I have written a contrib module which provides a rules action using hook_rules_action_info() and which also creates a locked rule using hook_default_rules_configuration().

Now, I want to write a hook_uninstall() to cleanup the system in case my module gets uninstalled.

My understanding is that the action will automatically disappear as soon as the module is uninstalled. But I wonder about the rule itself. What is the best way to delete that rule? I wasn't able to find an easy API call for that functionality and hope for help here.

Comments

TR’s picture

Status: Active » Fixed

You do not have to delete default components programmatically in hook_uninstall(). Rules takes care of that for you when you disable your module.

However if you have used the Rules UI and modified the component (the status will be shown as "Overridden" in the UI), then when you disable your module you will see a system message that says:

1 Rules configuration requires some of the disabled modules to function and cannot be executed any more.

Rules will not remove the modified configuration from the database because it it now a customized part of the site.
You can then delete it through the UI, or in your hook_uninstall() like this:

  db_delete('rules_config')
    ->condition('name', $machine_name)
    ->execute();

where $machine_name is the machine name of your component.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.