Forums / Developer / Check attributes before custom php object creation

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+

eZ debug

Timing: Jan 29 2025 13:31:27
Script start
Timing: Jan 29 2025 13:31:27
Module start 'content'
Timing: Jan 29 2025 13:31:27
Module end 'content'
Timing: Jan 29 2025 13:31:28
Script end

Main resources:

Total runtime0.2405 sec
Peak memory usage2,048.0000 KB
Database Queries141

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0079 588.0781180.8203
Module start 'content' 0.00790.0069 768.8984102.1484
Module end 'content' 0.01480.2257 871.0469530.1094
Script end 0.2405  1,401.1563 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00351.4455200.0002
Check MTime0.00140.5875200.0001
Mysql Total
Database connection0.00080.317210.0008
Mysqli_queries0.195881.39791410.0014
Looping result0.00100.39641390.0000
Template Total0.225293.610.2252
Template load0.00100.400010.0010
Template processing0.224393.244210.2243
Override
Cache load0.00070.280210.0007
Sytem overhead
Fetch class attribute can translate value0.00060.232310.0006
XML
Image XML parsing0.00020.081110.0002
General
dbfile0.00943.9026200.0005
String conversion0.00000.002130.0000
Note: percentages do not add up to 100% because some accumulators overlap

CSS/JS files loaded with "ezjscPacker" during request:

CacheTypePacklevelSourceFiles
CSS0extension/community/design/community/stylesheets/ext/jquery.autocomplete.css
extension/community_design/design/suncana/stylesheets/scrollbars.css
extension/community_design/design/suncana/stylesheets/tabs.css
extension/community_design/design/suncana/stylesheets/roadmap.css
extension/community_design/design/suncana/stylesheets/content.css
extension/community_design/design/suncana/stylesheets/star-rating.css
extension/community_design/design/suncana/stylesheets/syntax_and_custom_tags.css
extension/community_design/design/suncana/stylesheets/buttons.css
extension/community_design/design/suncana/stylesheets/tweetbox.css
extension/community_design/design/suncana/stylesheets/jquery.fancybox-1.3.4.css
extension/bcsmoothgallery/design/standard/stylesheets/magnific-popup.css
extension/sevenx/design/simple/stylesheets/star_rating.css
extension/sevenx/design/simple/stylesheets/libs/fontawesome/css/all.min.css
extension/sevenx/design/simple/stylesheets/main.v02.css
extension/sevenx/design/simple/stylesheets/main.v02.res.css
JS0extension/ezjscore/design/standard/lib/yui/3.17.2/build/yui/yui-min.js
extension/ezjscore/design/standard/javascript/jquery-3.7.0.min.js
extension/community_design/design/suncana/javascript/jquery.ui.core.min.js
extension/community_design/design/suncana/javascript/jquery.ui.widget.min.js
extension/community_design/design/suncana/javascript/jquery.easing.1.3.js
extension/community_design/design/suncana/javascript/jquery.ui.tabs.js
extension/community_design/design/suncana/javascript/jquery.hoverIntent.min.js
extension/community_design/design/suncana/javascript/jquery.popmenu.js
extension/community_design/design/suncana/javascript/jScrollPane.js
extension/community_design/design/suncana/javascript/jquery.mousewheel.js
extension/community_design/design/suncana/javascript/jquery.cycle.all.js
extension/sevenx/design/simple/javascript/jquery.scrollTo.js
extension/community_design/design/suncana/javascript/jquery.cookie.js
extension/community_design/design/suncana/javascript/ezstarrating_jquery.js
extension/community_design/design/suncana/javascript/jquery.initboxes.js
extension/community_design/design/suncana/javascript/app.js
extension/community_design/design/suncana/javascript/twitterwidget.js
extension/community_design/design/suncana/javascript/community.js
extension/community_design/design/suncana/javascript/roadmap.js
extension/community_design/design/suncana/javascript/ez.js
extension/community_design/design/suncana/javascript/ezshareevents.js
extension/sevenx/design/simple/javascript/main.js

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1pagelayout.tpl<No override>extension/sevenx/design/simple/templates/pagelayout.tplEdit templateOverride template
 Number of times templates used: 1
 Number of unique templates used: 1

Time used to render debug report: 0.0002 secs