summaryrefslogtreecommitdiff
path: root/modules/system/system.admin.inc
diff options
context:
space:
mode:
authorAngie Byron <webchick@24967.no-reply.drupal.org>2010-11-20 03:34:30 +0000
committerAngie Byron <webchick@24967.no-reply.drupal.org>2010-11-20 03:34:30 +0000
commitaa10522336e69d462176e7505f3cdc00c3cf85d7 (patch)
treec9e413cfd4e16605957ef12ae8b218e4e47b0de9 /modules/system/system.admin.inc
parent2f7600c1c512adcc36bc088d98de392dac102f1e (diff)
downloadbrdo-aa10522336e69d462176e7505f3cdc00c3cf85d7.tar.gz
brdo-aa10522336e69d462176e7505f3cdc00c3cf85d7.tar.bz2
#151452 by David_Rothstein, Dave Reid, tstoeckler: Fixed uninstalling modules does not follow dependencies.
Diffstat (limited to 'modules/system/system.admin.inc')
-rw-r--r--modules/system/system.admin.inc70
1 files changed, 46 insertions, 24 deletions
diff --git a/modules/system/system.admin.inc b/modules/system/system.admin.inc
index 0b6e45683..647ffc5c7 100644
--- a/modules/system/system.admin.inc
+++ b/modules/system/system.admin.inc
@@ -1213,30 +1213,42 @@ function system_modules_uninstall($form, $form_state = NULL) {
return $confirm_form;
}
- // Pull all disabled modules from the system table.
- $disabled_modules = db_query("SELECT name, filename, info FROM {system} WHERE type = 'module' AND status = 0 AND schema_version > :schema ORDER BY name", array(':schema' => SCHEMA_UNINSTALLED));
- foreach ($disabled_modules as $module) {
- // Grab the module info
- $info = unserialize($module->info);
-
- // Load the .install file, and check for an uninstall or schema hook.
- // If the hook exists, the module can be uninstalled.
- module_load_install($module->name);
- if (module_hook($module->name, 'uninstall') || module_hook($module->name, 'schema')) {
- $form['modules'][$module->name]['name'] = array('#markup' => $info['name'] ? $info['name'] : $module->name);
- $form['modules'][$module->name]['description'] = array('#markup' => t($info['description']));
- $options[$module->name] = '';
+ // Get a list of disabled, installed modules.
+ $all_modules = system_rebuild_module_data();
+ $disabled_modules = array();
+ foreach ($all_modules as $name => $module) {
+ if (empty($module->status) && $module->schema_version > SCHEMA_UNINSTALLED) {
+ $disabled_modules[$name] = $module;
+ }
+ }
+
+ // Only build the rest of the form if there are any modules available to
+ // uninstall.
+ if (!empty($disabled_modules)) {
+ $profile = drupal_get_profile();
+ uasort($disabled_modules, 'system_sort_modules_by_info_name');
+ $form['uninstall'] = array('#tree' => TRUE);
+ foreach ($disabled_modules as $module) {
+ $module_name = $module->info['name'] ? $module->info['name'] : $module->name;
+ $form['modules'][$module->name]['#module_name'] = $module_name;
+ $form['modules'][$module->name]['name']['#markup'] = $module_name;
+ $form['modules'][$module->name]['description']['#markup'] = t($module->info['description']);
+ $form['uninstall'][$module->name] = array(
+ '#type' => 'checkbox',
+ '#title' => t('Uninstall @module module', array('@module' => $module_name)),
+ '#title_display' => 'invisible',
+ );
+ // All modules which depend on this one must be uninstalled first, before
+ // we can allow this module to be uninstalled. (The install profile is
+ // excluded from this list.)
+ foreach (array_keys($module->required_by) as $dependent) {
+ if ($dependent != $profile && drupal_get_installed_schema_version($dependent) != SCHEMA_UNINSTALLED) {
+ $dependent_name = isset($all_modules[$dependent]->info['name']) ? $all_modules[$dependent]->info['name'] : $dependent;
+ $form['modules'][$module->name]['#required_by'][] = $dependent_name;
+ $form['uninstall'][$module->name]['#disabled'] = TRUE;
+ }
+ }
}
- }
-
- // Only build the rest of the form if there are any modules available to uninstall.
- if (!empty($options)) {
- $form['uninstall'] = array(
- '#type' => 'checkboxes',
- '#title' => t('Modules'),
- '#title_display' => 'invisible',
- '#options' => $options,
- );
$form['actions'] = array('#type' => 'actions');
$form['actions']['submit'] = array(
'#type' => 'submit',
@@ -2586,10 +2598,20 @@ function theme_system_modules_uninstall($variables) {
// Display table.
$rows = array();
foreach (element_children($form['modules']) as $module) {
+ if (!empty($form['modules'][$module]['#required_by'])) {
+ $disabled_message = format_plural(count($form['modules'][$module]['#required_by']),
+ 'To uninstall @module, the following module must be uninstalled first: @required_modules',
+ 'To uninstall @module, the following modules must be uninstalled first: @required_modules',
+ array('@module' => $form['modules'][$module]['#module_name'], '@required_modules' => implode(', ', $form['modules'][$module]['#required_by'])));
+ $disabled_message = '<div class="admin-requirements">' . $disabled_message . '</div>';
+ }
+ else {
+ $disabled_message = '';
+ }
$rows[] = array(
array('data' => drupal_render($form['uninstall'][$module]), 'align' => 'center'),
'<strong><label for="' . $form['uninstall'][$module]['#id'] . '">' . drupal_render($form['modules'][$module]['name']) . '</label></strong>',
- array('data' => drupal_render($form['modules'][$module]['description']), 'class' => array('description')),
+ array('data' => drupal_render($form['modules'][$module]['description']) . $disabled_message, 'class' => array('description')),
);
}