Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Phases in SDL Tridion Event Handler 2011

Have difficulties in understanding Event phases.

1) Consider the Component Save action. When the content is to be overridden based on the content rule, it can be done so in 'Initiated' phase. In case of content disobeying the content rule, errors can be thrown in 'Initiated' or 'Processed' event phases .

When 'Initiated' phase itself is sufficient both for content overriding and content rule validation, When will 'Processed' phase be useful? Pls. explain with an example.

2) While saving and closing the component, 'Save' and 'CheckIn' events are triggered. After the 'Processed' phase of Save action, CheckIn action will take place. In case of any errors during 'Initiated'/'Processed' phase of CheckIn action, 'TransactionAborted' phase of Save action will occur.

Above is the only example that I could think of for 'TrasactionAborted'. Can you provide any other example which will help in understanding 'TrasactionAborted' phase?

like image 435
user1528297 Avatar asked Jul 16 '12 08:07

user1528297


2 Answers

Ad1: On the initiated phase the item is not saved yet to the database, and there is no transaction to be rolled back. If you want to validate data you should do this before anything in the database is changed. Of course, transactions are supported and when you raise an exception all will be fine, but you perform unnecessary actions, which all adds up to the performance picture.

Processed will be useful for situations in which you dont work with the item content itself, but should be able to roll back the change. E.g.: ability to write to an archive or highly business critical event log.

Another case would be to set a translation required flag on localized children. If that fails you might want to cancel the change on the parent item as well (for some reason).

Ad2: In general Transaction Aborted would be triggered when any exception occurs. Maybe you can elaborate a bit more on point 2?

like image 164
Arjen Stobbe Avatar answered Nov 07 '22 06:11

Arjen Stobbe


I've tried to give a complete explanation of the SDL Tridion 2011 Event Phases, Event Types and Subject Types in the following article on SDL Tridion World: SDL Tridion 2011 .NET events.

In short, the phases are fired in a specific order so you can hook into the action at specific times, the order is as follows:

  1. Initiated phase
  2. CMS action takes place (not a phase)
  3. Processed phase
  4. One of the transaction phases (TransactionCommitted if the transaction was successful, TransactionAborted in case of a transaction abort and TransactionInDoubt when the state of the transaction cannot be determined, it is neither commited nor aborted and never will be)

So if you want to do something before the item is saved (like doing a validity check on the item in which case you might want to prevent it from being saved, you can best use the Initiated phase, but if you want to do something after the item has been saved (like placing it on a Page), you should use the Transaction Committed phase (in this case probably the one of the Check-in, rather than the Save event even).

So when does the Processed phase come in useful, well I can never think of a simple use case for it, but I'm sure that in some situation it will come in handy at some point. The fact that it is there, does not mean you need to use it right away.

like image 6
Bart Koopman Avatar answered Nov 07 '22 07:11

Bart Koopman