Actions and trigger

in

A couple problems I encountered creating a module that does action and trigger:

  1. when the module is disabled, the actions it defines should be disabled to prevent undefined function call in case you try to re-configure the actions. When the module is disabled, any actions that it has defines are still displayed with the "Configure" link available. If you click configure, of course you will get undefined function because the code is gone.
  2. when the module is uninstalled, I have a problem with deleting configurable action definition.

First problem: when a module is disabled, any actions it defines stay in the actions database table. And if there is any trigger assign to those actions, the assignment remain in trigger_assignments table as well. Even though it's a Drupal convention to leave the database untouched when a module is disabled so things get restored once the module is re-enabled, there is a problem in case of actions and trigger assignment. The problem is when the module is disabled, the php code in it is no longer active. If we try to edit the actions configuration, we get undefined function call. There needs to be a way to disable a module's actions when it's disabled and re-enable them when the moudle is re-enabled. I don't see anyway to do this. It appears that actions and trigger assignments were not designed to accommodate module disable/enable.

Second problem: when the module is uninstalled, its actions should be deleted. The function actions_delete($aid) does this. It deletes action definition from actions table and call module_invoke_all('actions_delete', $aid). This invokes the hook_actions_delete in the trigger module, which deletes the corresponding trigger_assignment record. Good. But there is a problem: the $aid for a configurable action is some numeric sequence number not known to the module that defines the action. There appears to have no ready made way to find all action id from a module. So the solution is to execute db_query() to fetch all of the module's aids. Then call actions_delete($aid) to delete the action definition.

Update: the function actions_synchronize() has the option to delete orphans. So a call

action_synchronize(NULL, TRUE);

should do the trick.

Post new comment

The content of this field is kept private and will not be shown publicly.

Navigation

User login