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

eZ debug

Timing: Jan 18 2025 19:23:33
Script start
Timing: Jan 18 2025 19:23:33
Module start 'content'
Timing: Jan 18 2025 19:23:34
Module end 'content'
Timing: Jan 18 2025 19:23:34
Script end

Main resources:

Total runtime1.1879 sec
Peak memory usage4,096.0000 KB
Database Queries221

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0084 589.1172180.8125
Module start 'content' 0.00841.0160 769.9297742.9063
Module end 'content' 1.02440.1634 1,512.8359344.4297
Script end 1.1878  1,857.2656 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00440.3671210.0002
Check MTime0.00170.1457210.0001
Mysql Total
Database connection0.00100.080110.0010
Mysqli_queries1.076690.63372210.0049
Looping result0.00380.31932190.0000
Template Total1.142696.220.5713
Template load0.00280.232920.0014
Template processing1.139895.954320.5699
Template load and register function0.00020.018110.0002
states
state_id_array0.00220.181510.0022
state_identifier_array0.00240.202920.0012
Override
Cache load0.00240.1980920.0000
Sytem overhead
Fetch class attribute can translate value0.00140.121760.0002
Fetch class attribute name0.00190.1633120.0002
XML
Image XML parsing0.00170.146160.0003
class_abstraction
Instantiating content class attribute0.00000.0038150.0000
General
dbfile0.00210.1775330.0001
String conversion0.00000.000530.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
1node/view/full.tplfull/forum_topic.tplextension/sevenx/design/simple/override/templates/full/forum_topic.tplEdit templateOverride template
10content/datatype/view/ezxmltext.tpl<No override>extension/community_design/design/suncana/templates/content/datatype/view/ezxmltext.tplEdit templateOverride template
20content/datatype/view/ezxmltags/paragraph.tpl<No override>extension/ezwebin/design/ezwebin/templates/content/datatype/view/ezxmltags/paragraph.tplEdit templateOverride template
7content/datatype/view/ezxmltags/line.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/line.tplEdit templateOverride template
4content/datatype/view/ezxmltags/literal.tpl<No override>extension/community/design/standard/templates/content/datatype/view/ezxmltags/literal.tplEdit templateOverride template
5content/datatype/view/ezimage.tpl<No override>extension/sevenx/design/simple/templates/content/datatype/view/ezimage.tplEdit templateOverride template
1pagelayout.tpl<No override>extension/sevenx/design/simple/templates/pagelayout.tplEdit templateOverride template
 Number of times templates used: 48
 Number of unique templates used: 7

Time used to render debug report: 0.0002 secs