Conditionally enable the new Ban module.
function system_update_8020() {
$blocked_ips_exists = db_query_range('SELECT 1 FROM {blocked_ips}', 0, 1)
->fetchField();
if ($blocked_ips_exists) {
// Rename the permission name.
db_update('role_permission')
->fields(array(
'permission' => 'ban IP addresses',
'module' => 'ban',
))
->condition('permission', 'block IP addresses')
->execute();
// Rename {blocked_ips} table into {ban_ip}.
db_rename_table('blocked_ips', 'ban_ip');
// Remove all references to the removed action callback.
db_delete('actions')
->condition('callback', 'system_block_ip_action')
->execute();
db_delete('actions')
->condition('aid', 'system_block_ip_action')
->execute();
// Enable the new Ban module.
module_enable(array(
'ban',
));
}
else {
// Drop old table.
db_drop_table('blocked_ips');
}
}