Changing custom rules actions and names

I’ve got a custom module on a D6 client site that contains a few rules actions and conditions that another dev created. There are about 10 detailed rules set up on the system relying on these actions & conditions. We needed to rename the module (its actually a feature module) for consistency and better organization.

I did a simple find/replace on the module files, changed the file name, and reenabled… no problem! But - the rules were still looking for the old action names and throwing an error. I tried resaving both the rule and each condition/action… but that didn’t seem to do it. So, I figured I’d use the devel php tool to update the db.

It took me a few tries to get it just right (note the “%b” for storing blob info), but it worked nicely and kept me going down the road. So - if you need to change the hook_rules_condition_info() or hook_rules_action_info() in a live module, something like this may help. In my case, the changes were uniform, but depending on your config, it may take a bit more effort.

<?php
$query
= "SELECT * FROM {rules_rules}";
$results = db_query($query);
while (
$rule = db_fetch_object($results)) {
 
$rule->data = str_replace('old_module_name', 'new_module_name', $rule->data);
 
// dpm($rule->data);
 
db_query("UPDATE {rules_rules} SET data=%b WHERE name='%s'", $rule->data, $rule->name);
}
?>