Forums / Developer / Which is the method to create new triggers?

Which is the method to create new triggers?

Author Message

Vanessa Merle

Monday 21 March 2005 12:05:30 am

Hello

Which is the method to create new triggers?

In fact, I want to apply a workflow when the contents (user object) are removed.

I found documentation to create a new workflow, but I didn't find many explanations for Triggers.
Can you give me some details, or an example of trigger extension?
Where can I find documentation?

Thanks for your help.

Vanessa

Paul Forsyth

Monday 21 March 2005 2:33:58 am

Heres a small example of a adding a trigger

The key is to add your trigger to the operation_definition.php file within a module.

For example to add a trigger to the user module (which has no triggers) add:

kernel/user/operation_definition.php


$OperationList = array();
$OperationList['activate'] = array( 'name' => 'activate',
                                        'default_call_method' => array( 'include_file' => 'kernel/user/ezuseroperationcollection.php',
                                                                        'class' => 'eZUserOperationCollection' ),
                                        'parameter_type' => 'standard',
                                        'parameters' => array( array( 'name' => 'user_id',
                                                                      'type' => 'integer',
                                                                      'required' => true ),
                                                               ),
                                        'keys' => array( 'user_id' ),
                                        'body' => array( array( 'type' => 'trigger',
                                                                'name' => 'post_activate',
                                                                'keys' => array( 'user_id' ) )));
?>

This adds a trigger to the activate function which will run when the user confirms their intention to register.

To make the activate.php file respect the trigger you need to add the following code:

kernel/user/activate.php

    //Run workflow
    include_once( 'lib/ezutils/classes/ezoperationhandler.php' );

    $operationResult = eZOperationHandler::execute( 'user','activate', array( 'user_id' => $userID ) );

And note in this example the presence of another class, which isnt used but might need to be present. Its ok for it to be empty.

kernel/user/ezuseroperationcollection.php

<?php

?>

The last part is to active your trigger. In workflow.ini add the trigger to the operation settings:

[OperationSettings]
AvailableOperations=content_publish;shop_confirmorder;shop_checkout;user_activate

Once cache is cleared the trigger should show up in the trigger area.

In general these triggers and handlers will have been set up for you in the main modules.

Have a look at other 'operation' files to get the general idea.

Hope this helps

Paul

Lex 007

Monday 21 March 2005 2:47:31 am

I was also looking for some documentation about this. Thanks Paul.

Paul Forsyth

Monday 21 March 2005 2:53:22 am

Np. Let me know if there are any mistakes in the code. It was a quick cut/paste/hack ;)

paul

Lex 007

Tuesday 10 May 2005 1:49:06 am

Hi,

Just another message to thank you because it worked great for me (just changed user_id with object_id to fit my needs).

:)

Do you think it would be possible to program an extension for this trigger, instead of patching the kernel files ? (which is not very safe and portable)

Lex

Paul Forsyth

Tuesday 10 May 2005 2:37:39 am

Thats a long standing wish: overriding base files with extensions. But it isnt possible yet.

On the other hand you could copy the whole module into an extension and use it there. Not as useful but it gives you separation.

Do you maintain a patch file? Much easier than keeping the whole file around.

paul

Lex 007

Tuesday 10 May 2005 2:46:04 am

Thanks for your answer, unfortunatly that's what I thought ... I do maintain documentation on everything I patch, but the main issue is that we don't know how future version of eZP will behave !

Anyway thanks.

Fabricio Guerrero

Thursday 15 September 2005 9:56:22 am

OK, this is probably an easy question... but I'm having no luck with this :(

I'm using Lex007 personal folder extension found here:
http://ez.no/community/contribs/workflow/personal_folder

which seems to be using Paul's code:
$OperationList = array();
$OperationList['activate'] = array( 'name' => 'activate',...

Up to here everything works perfect but the site I'm working on is a private site whom only the admin creates users. Being this way the user never has to activate his account and furthermore this trigger will never go off.

I've tried changing the trigger function from After Activation to Before Activation but no luck..

I've also tried changing some of Pauls coding specially this line:

'body' => array( array( 'type' => 'trigger',
'name' => 'post_activate',
'keys' => array( 'user_id' ) )));

TO

'name' => 'pre_activate',

but no luck at all :(

Which would be the correct way to make the trigger go off once user is created either in the public or admin site? Would there be a difference in coding or does the user creation in the public and Admin section use the same code?
Would something like User/Publish/After work?

Thanks,
Fabricio

http://www.solobromasychistes.com <<Joomla Site :P
http://www.recipesforhealthyfood.com/ <<Drupal Site :P
http://www.ezforge.com/ <<future ezCommunity, Articles, forums and more...

Lex 007

Friday 16 September 2005 2:55:14 am

Hi,

You are right, this was Paul's code :D

I answered to your question in the Contribs section for the "post_register" trigger.

Lex

christian bencivenni

Thursday 12 January 2006 8:46:13 am

Hi.
I have the same problem of vanessa.
I must modify a DB table when an object is deleted.
I have the workflow ready and the event which will modify the table operative.
What I'm not understand is what I must write in the BODY section of the trigger.
The functions that EZ use to delete an object?
My functions to delete an object?
Nothing?

How can make understandable for my new trigger that it must activate when an object is deleted?

Thanks