detect new object creation..

Author Message

Ivan Švogor

Monday 10 January 2011 6:58:15 am

Hello!

Can anyone tell me how can I detect new object creation? I need to execute my code after someone creates a new event (for calendar). What is the best way to do this?

Edi Modrić

Monday 10 January 2011 7:10:21 am

Hi Ivan,

You can create your own workflow event and attach it to the after publish trigger. From the workflow event, you can execute any code you wish.

There's a nice article here, on share.ez.no, to get you started on workflow events:

http://share.ez.no/learn/ez-publish/creating-a-simple-custom-workflow-event

eZ Publish certified developer

http://ez.no/certification/verify/350658

Carlos Revillo

Monday 10 January 2011 7:11:50 am

i'd say workflows is your best option. you can add your own and so you can execute code after publishing something.

http://doc.ez.no/eZ-Publish/Technical-manual/4.4/Concepts-and-basics/Workflows

Carlos Revillo

Monday 10 January 2011 7:12:43 am

"

i'd say workflows is your best option. you can add your own and so you can execute code after publishing something.

http://doc.ez.no/eZ-Publish/Technical-manual/4.4/Concepts-and-basics/Workflows

"

ops, sorry Edi. Didn't see your post...

Damien Pobel

Monday 10 January 2011 7:15:08 am

Hi Ivan,

You should take a look at this article : http://share.ez.no/learn/ez-publish/creating-a-simple-custom-workflow-event

it explains how to create a workflow event type that can be triggered by the publication of an object...

Cheers

Damien
Planet eZ Publish.fr : http://www.planet-ezpublish.fr
Certification : http://auth.ez.no/certification/verify/372448
Publications about eZ Publish : http://pwet.fr/tags/keywords/weblog/ez_publish

Damien Pobel

Monday 10 January 2011 7:19:45 am

Carlos I'm even slower than you ;-)

Damien
Planet eZ Publish.fr : http://www.planet-ezpublish.fr
Certification : http://auth.ez.no/certification/verify/372448
Publications about eZ Publish : http://pwet.fr/tags/keywords/weblog/ez_publish

Marko Žmak

Monday 10 January 2011 9:46:38 am

Ivan, you can also use content edit handlers. The edit handler is executed every time you publish an object, and you can also detect if the published object is a newly created one.

Also take a look at my extension:

http://projects.ez.no/saedithandlers

it gives you an easy way to execute multiple edit handlers.

(it's not well documented yet, so fell free to bug me if you need some help)

--
Nothing is impossible. Not if you can imagine it!

Hubert Farnsworth

Bertrand Dunogier

Tuesday 11 January 2011 12:37:46 am

I'd rather suggest a workflow event than a content edit handler. It makes much more sense from a conceptual point of vue, at least based on the info you've provided us with.

More details on what you need to achieve exactly would help clear that out.

Bertrand Dunogier
eZ Systems Engineering, Lyon
http://twitter.com/bdunogier
http://gplus.to/BertrandDunogier

Marko Žmak

Tuesday 11 January 2011 12:54:05 pm

Bertrand, I wouldn't completely agree with you. If you just want to execute a simple piece of code upon object publishing, the content edit handlers is a better solution.

Main arguments:

  • custom edit handlers are easier to implement and maintain
  • edit handler are faster (I'm not 100% sure about this, but I've got a hunch)

Only if you need to setup a more complex system of functionality, then you should use workflows.

This is my opinion, but I'm also open to hearing a counter-opinion.

--
Nothing is impossible. Not if you can imagine it!

Hubert Farnsworth

Bertrand Dunogier

Wednesday 12 January 2011 4:38:37 am

Marko,

There are imho two main counter arguments.

Execution order

content edit handlers are executed at step #9 of the content/publish operation (out of 19 currently). Several further steps haven't been executed yet at that step. Post publish trigger is step #19. The object is therefore in an incomplete state (onPublish hasn't been called on attributes, untranslated attributes haven't been updated, cache hasn't been cleared, search indexing hasn't been done...). This might not be an issue in every case, but it can't be neglected.

Common sense ;-)

It isn't a technical argument, but imho, a workflow makes more sense (yet, that isn't very concrete) than a content edit handler here, in terms of extension type.

Regarding complexity, workflow events require a bit more than content edit handlers, that is true, but once you're used to the API, they're not that complex. Execution of content edit handlers is probably a bit faster, though. I haven't tested, but based on what I know of the operation, they most likely are.

Bertrand Dunogier
eZ Systems Engineering, Lyon
http://twitter.com/bdunogier
http://gplus.to/BertrandDunogier

Gaetano Giunta

Wednesday 12 January 2011 5:05:13 am

I agree with BD.

Please oh master of the eZ Sources, make a simpler API for us mere mortals who want to code new workflow events and new datatypes!

;-)

Principal Consultant International Business
Member of the Community Project Board

Marko Žmak

Wednesday 12 January 2011 6:40:56 am

Bertrand, thanks for the info and arguments. Here are some of my points...

"

Execution order

content edit handlers are executed at step #9 of the content/publish operation (out of 19 currently). Several further steps haven't been executed yet at that step. Post publish trigger is step #19. The object is therefore in an incomplete state (onPublish hasn't been called on attributes, untranslated attributes haven't been updated, cache hasn't been cleared, search indexing hasn't been done...). This might not be an issue in every case, but it can't be neglected.

"

There are some cases when you DO want to execute some code before all this operations. Here's an example from my real life experience... If you need this functionality:

  1. change the published date based on a value of a date attribute
  2. autofill an XML attribute if it's left blank by the user

Then you want to do the 1) before the cache is cleared and search indexing is done, and you want to do 2) before onPublish is called.

"

It isn't a technical argument, but imho, a workflow makes more sense (yet, that isn't very concrete) than a content edit handler here, in terms of extension type.

"

So what would in your opinion be the scenario when a content edit handler is a better choice? I'd love to hear some examples.

To sum it up, it actually comes up to what Bertrand suggested:

You really have to know precisely what you want to do before you can decide between content edit handler and workflow.

--
Nothing is impossible. Not if you can imagine it!

Hubert Farnsworth

Carlos Revillo

Wednesday 12 January 2011 7:05:54 am

"

Then you want to do the 1) before the cache is cleared and search indexing is done, and you want to do 2) before onPublish is called.

"

Correct me if i'm wrong, but can't you setup a content -> before -> publish trigger for that?

Bertrand Dunogier

Thursday 13 January 2011 7:25:36 am

"
"

Then you want to do the 1) before the cache is cleared and search indexing is done, and you want to do 2) before onPublish is called.

"

Correct me if i'm wrong, but can't you setup a content -> before -> publish trigger for that?

"

Thanks for stepping up ;-)

I don't have much time available now, but I'd say that globally, content edit handlers are for code RELATED TO the object being published, while triggers are for when you need to do something BASED on the object being published. But that's my personal view !

Bertrand Dunogier
eZ Systems Engineering, Lyon
http://twitter.com/bdunogier
http://gplus.to/BertrandDunogier

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:59:57
Script start
Timing: Jan 18 2025 02:59:57
Module start 'layout'
Timing: Jan 18 2025 02:59:57
Module start 'content'
Timing: Jan 18 2025 02:59:58
Module end 'content'
Timing: Jan 18 2025 02:59:58
Script end

Main resources:

Total runtime0.6913 sec
Peak memory usage4,096.0000 KB
Database Queries101

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0046 587.9141152.6250
Module start 'layout' 0.00460.0022 740.539139.4531
Module start 'content' 0.00680.6831 779.9922905.7656
Module end 'content' 0.68990.0014 1,685.757832.1641
Script end 0.6913  1,717.9219 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00300.4281160.0002
Check MTime0.00110.1649160.0001
Mysql Total
Database connection0.00080.111410.0008
Mysqli_queries0.591585.56621010.0059
Looping result0.00090.1297990.0000
Template Total0.666396.420.3332
Template load0.00190.270220.0009
Template processing0.664496.107920.3322
Template load and register function0.00020.022710.0002
states
state_id_array0.00080.114710.0008
state_identifier_array0.00090.131120.0005
Override
Cache load0.00180.2668990.0000
Sytem overhead
Fetch class attribute can translate value0.00110.156570.0002
Fetch class attribute name0.00160.2372190.0001
XML
Image XML parsing0.00280.399570.0004
class_abstraction
Instantiating content class attribute0.00000.0060240.0000
General
dbfile0.00140.1973420.0000
String conversion0.00000.000740.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
14content/datatype/view/ezxmltext.tpl<No override>extension/community_design/design/suncana/templates/content/datatype/view/ezxmltext.tplEdit templateOverride template
30content/datatype/view/ezxmltags/paragraph.tpl<No override>extension/ezwebin/design/ezwebin/templates/content/datatype/view/ezxmltags/paragraph.tplEdit templateOverride template
10content/datatype/view/ezimage.tpl<No override>extension/sevenx/design/simple/templates/content/datatype/view/ezimage.tplEdit templateOverride template
6content/datatype/view/ezxmltags/quote.tpldatatype/ezxmltext/quote.tplextension/ezwebin/design/ezwebin/override/templates/datatype/ezxmltext/quote.tplEdit templateOverride template
1content/datatype/view/ezxmltags/link.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/link.tplEdit templateOverride template
2content/datatype/view/ezxmltags/li.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/li.tplEdit templateOverride template
1content/datatype/view/ezxmltags/ul.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/ul.tplEdit templateOverride template
4content/datatype/view/ezxmltags/strong.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/strong.tplEdit templateOverride template
4content/datatype/view/ezxmltags/emphasize.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/emphasize.tplEdit templateOverride template
1content/datatype/view/ezxmltags/ol.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/ol.tplEdit templateOverride template
1print_pagelayout.tpl<No override>extension/community/design/community/templates/print_pagelayout.tplEdit templateOverride template
 Number of times templates used: 75
 Number of unique templates used: 12

Time used to render debug report: 0.0001 secs