Triggers And Uninstalling Modules

Note, Actions and Triggers are core in Drupal 6.x so this only applies to Drupal 5.x if you are using the Actions module as a 5.x contributed module:
http://drupal.org/project/actions

If you are using Triggers in Drupal 5.x then you have probably installed something like the Node Triggers module, which allows Actions to be triggered on node-related events (using hook_nodeapi()):
http://drupal.org/project/nodetriggers

Triggers and actions in Drupal are extremely useful. They allow you to perform automated tasks when a variety of different events occur in the system. Good examples are a node is created, a comment is edited, a module is installed, etc. etc. Using the Actions API in Drupal 6.x you can provide your own actions in your module which can then be fired by Triggers provided by the system.

By way of an example, I created a simple action which placed the node ID of a node in a CCK field. I then assigned this to a node insert trigger meaning whenever a new node is inserted in the database, immediately after my action is executed.

Cool stuff!

Here's the warning: if you write your own actions and assign them as triggers, whatever you do make sure you *unassign* your actions from any triggers before you uninstall your module. This is not handled automatically, so if you fail to do so you will end up with an orphan trigger trying to call a function that no longer exists... and the white screen of death! =(

In fact, I strongly advise that any module providing an action copies some portion of the code for unassigning actions from triggers in to the hook_uninstall() implementation, so you know for sure no triggers can be left set. At the moment it seems the only function for handling this in the core Trigger module is the admin form submit function, which is not ideal:
http://api.drupal.org/api/function/trigger_unassign_submit

For Drupal 5.x you'll need to examine the code of the trigger module you're using to understand if there is a function you can call for this or not.

There's probably scope in Drupal 7.x for a function to unassign all triggers belonging to a given module that can be called from hook_uninstall(), so contributed modules can easily and safely clear up after themselves... but that's for another day. For now, remember triggers and actions are great, but make sure you don't leave orphaned triggers behind when you uninstall modules. That goes for *all* modules - don't assume they uninstall actions gracefully by checking for triggers.

Tools

What a clear and understandable great post you have above. You wrote so many good point which assisted me so much. I have found many informative point here.

Best wishes!

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <blockquote>
  • Lines and paragraphs break automatically.
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
Image CAPTCHA
Copy the characters (respecting upper/lower case) from the image.