From de0170362071fc6874f049d33d6680ed7ac2f9e2 Mon Sep 17 00:00:00 2001 From: Fabian Franz Date: Thu, 1 Dec 2011 05:26:45 +0100 Subject: [PATCH] Issue #735900: Deleting module's blocks when module is uninstalled --- includes/install.inc | 6 +++++- modules/block/block.admin.inc | 1 + modules/block/block.install | 22 ++++++++++++++++++++++ 3 files changed, 28 insertions(+), 1 deletions(-) diff --git a/includes/install.inc b/includes/install.inc index 2ee29ba..dde25fb 100644 --- a/includes/install.inc +++ b/includes/install.inc @@ -34,7 +34,7 @@ function drupal_load_updates() { * @param $module * A module name. * @return - * If the module has updates, an array of available updates sorted by version. + * If the module has updates, an array of available updates sorted by version. * Otherwise, FALSE. */ function drupal_get_schema_versions($module) { @@ -381,6 +381,10 @@ function drupal_uninstall_module($module) { module_load_install($module); module_invoke($module, 'uninstall'); + // Remove all module's blocks. + db_query("DELETE FROM {blocks} WHERE module = '%s'", $module); + db_query("DELETE FROM {blocks_roles} WHERE module = '%s'", $module); + // Now remove the menu links for all paths declared by this module. if (!empty($paths)) { $paths = array_keys($paths); diff --git a/modules/block/block.admin.inc b/modules/block/block.admin.inc index 3fd8280..898b13e 100644 --- a/modules/block/block.admin.inc +++ b/modules/block/block.admin.inc @@ -339,6 +339,7 @@ function block_box_delete(&$form_state, $bid = 0) { function block_box_delete_submit($form, &$form_state) { db_query('DELETE FROM {boxes} WHERE bid = %d', $form_state['values']['bid']); db_query("DELETE FROM {blocks} WHERE module = 'block' AND delta = '%s'", $form_state['values']['bid']); + db_query("DELETE FROM {blocks_roles} WHERE module = 'block' AND delta = '%s'", $form_state['values']['bid']); drupal_set_message(t('The block %name has been removed.', array('%name' => $form_state['values']['info']))); cache_clear_all(); $form_state['redirect'] = 'admin/build/block'; diff --git a/modules/block/block.install b/modules/block/block.install index 45d6710..dd05b10 100644 --- a/modules/block/block.install +++ b/modules/block/block.install @@ -176,3 +176,25 @@ function block_schema() { return $schema; } +/** + * @defgroup updates-6.x-extra Extra block updates for 6.x + * @{ + */ + +/** + * Cleanup orphan block's data. + */ +function block_update_6000() { + $ret = array(); + // Cleanup for deleted custom blocks. + $ret[] = update_sql("DELETE FROM {blocks_roles} WHERE module = 'block' AND delta NOT IN (SELECT b.bid FROM {boxes} b)"); + // Cleanup for uninstalled modules' blocks. + $ret[] = update_sql("DELETE FROM {blocks} WHERE module IN (SELECT s.name FROM {system} s WHERE s.type = 'module' AND s.status = 0 AND s.schema_version = -1)"); + $ret[] = update_sql("DELETE FROM {blocks_roles} WHERE module IN (SELECT s.name FROM {system} s WHERE s.type = 'module' AND s.status = 0 AND s.schema_version = -1)"); + return $ret; +} + +/** + * @} End of "defgroup updates-6.x-extra" + * The next series of updates should start at 7000. + */ -- 1.7.4.1