Check attributes before custom php object creation

Author Message

Paul Etienney

Monday 29 November 2010 10:05:54 pm

Hello eZ riders !

I use the great eZContentFunctions::createAndPublishObject method to create new objects. It works fine but there is a major problem. It does not check content attributes according to attributes and datatype configuration.

I want to perform the same verification that when editing object. Do you know where i can find the tools ?

Thank you very much.

Bye

-- Good websites creation --
My site : http://www.pauletienney.com
Twitter : http://www.twitter.com/p_etienney

Jérôme Vieilledent

Tuesday 30 November 2010 12:53:55 am

Hi Paul

Unfortunately it does not seem to be possible at that time, because validation is only made by the content/edit module.

However, every datatype has a validateObjectAttributeHTTPInput() method, but as its name indicates it, it is based on HTTP. I guess you could fake it by using eZHTTPTool and provide fake POST variables, while this is not the cleanest thing I could advise...

Anyway, instead of using eZContentFunctions::createAndPublishObject(), you might want to use SQLIImport extension which contains a simplified content API. It does not allow (yet) to validate data, but this is an interesting idea :)

Paul Etienney

Tuesday 30 November 2010 1:17:02 am

Hello Jérôme.

Thanks for your reply. I guess you have a gazillion kilometers long todo list but it would great to be able to easily check attributes.

Meanwhile, i'll do it "manually".

Bye.

-- Good websites creation --
My site : http://www.pauletienney.com
Twitter : http://www.twitter.com/p_etienney

Gaetano Giunta

Tuesday 30 November 2010 1:51:55 am

Having attribute validation decoupled from HTTP is imho one one of the most important advancements we need at this point in time in the eZP content model:

- it prevents creation of webservices / cli scripts / other APIS that create content without going through the monster that content/edit is

- it makes creation and validation of import scripts a chore. Almost every website I have audited where import scripts had been developed had some inconsistent data in the db

So I'd rather push to fix this in the kernel than add it to an extension...

Principal Consultant International Business
Member of the Community Project Board

Gaetano Giunta

Tuesday 30 November 2010 1:53:52 am

ps: this is also true for content imported via packages. Just test this: set an object-relation attribute as required in a class, create an obj, export it in a package (but omit its related obj), import it. You end up with an object that does not comply with your class spec...

Principal Consultant International Business
Member of the Community Project Board

Paul Etienney

Tuesday 30 November 2010 1:58:38 am

Hello Gaeano,

Good to hear that. I guess many people would love to check attributes easily.

Do you think it is a lot of work to fix this in the kernel ?

-- Good websites creation --
My site : http://www.pauletienney.com
Twitter : http://www.twitter.com/p_etienney

Jérôme Vieilledent

Tuesday 30 November 2010 2:25:13 am

"

So I'd rather push to fix this in the kernel than add it to an extension...

"

Sure, this is also the case for the simplified content API btw ;).

The main advantage to add this into an extension is that you can have it now :). Besides, SQLIImport is compatible 4.1+

Powered by eZ Publish™ CMS Open Source Web Content Management. Copyright © 1999-2014 eZ Systems AS (except where otherwise noted). All rights reserved.

eZ debug

Timing: Jan 18 2025 02:05:00
Script start
Timing: Jan 18 2025 02:05:00
Module start 'layout'
Timing: Jan 18 2025 02:05:01
Module start 'content'
Timing: Jan 18 2025 02:05:01
Module end 'content'
Timing: Jan 18 2025 02:05:01
Script end

Main resources:

Total runtime0.6748 sec
Peak memory usage4,096.0000 KB
Database Queries72

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0056 589.1797152.6406
Module start 'layout' 0.00560.0040 741.820339.5000
Module start 'content' 0.00950.6636 781.3203639.6094
Module end 'content' 0.67320.0016 1,420.929720.1250
Script end 0.6748  1,441.0547 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00330.4942160.0002
Check MTime0.00140.2094160.0001
Mysql Total
Database connection0.00080.116510.0008
Mysqli_queries0.593487.9369720.0082
Looping result0.00070.1102700.0000
Template Total0.637294.420.3186
Template load0.00200.292420.0010
Template processing0.635294.126520.3176
Template load and register function0.00010.017910.0001
states
state_id_array0.00150.215410.0015
state_identifier_array0.00080.121520.0004
Override
Cache load0.00180.2686440.0000
Sytem overhead
Fetch class attribute can translate value0.00410.605130.0014
Fetch class attribute name0.00180.2740100.0002
XML
Image XML parsing0.00150.224230.0005
class_abstraction
Instantiating content class attribute0.00000.0059140.0000
General
dbfile0.00200.2902290.0001
String conversion0.00000.001540.0000
Note: percentages do not add up to 100% because some accumulators overlap

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1node/view/full.tplfull/forum_topic.tplextension/sevenx/design/simple/override/templates/full/forum_topic.tplEdit templateOverride template
7content/datatype/view/ezimage.tpl<No override>extension/sevenx/design/simple/templates/content/datatype/view/ezimage.tplEdit templateOverride template
7content/datatype/view/ezxmltext.tpl<No override>extension/community_design/design/suncana/templates/content/datatype/view/ezxmltext.tplEdit templateOverride template
11content/datatype/view/ezxmltags/paragraph.tpl<No override>extension/ezwebin/design/ezwebin/templates/content/datatype/view/ezxmltags/paragraph.tplEdit templateOverride template
2content/datatype/view/ezxmltags/strong.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/strong.tplEdit templateOverride template
1content/datatype/view/ezxmltags/link.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/link.tplEdit templateOverride template
1content/datatype/view/ezxmltags/quote.tpldatatype/ezxmltext/quote.tplextension/ezwebin/design/ezwebin/override/templates/datatype/ezxmltext/quote.tplEdit templateOverride template
1print_pagelayout.tpl<No override>extension/community/design/community/templates/print_pagelayout.tplEdit templateOverride template
 Number of times templates used: 31
 Number of unique templates used: 8

Time used to render debug report: 0.0002 secs