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.