Issue #1587642 by TravisCarden: Rename drupal_uninstall_modules() to module_uninstall().
authorwebchick
Sat, 7 Jul 2012 18:50:30 +0000 (11:50 -0700)
committerwebchick
Sat, 7 Jul 2012 18:50:30 +0000 (11:50 -0700)
core/includes/install.inc
core/includes/module.inc
core/modules/locale/lib/Drupal/locale/Tests/LocaleUninstallTest.php
core/modules/system/lib/Drupal/system/Tests/Module/ModuleApiTest.php
core/modules/system/lib/Drupal/system/Tests/Module/UninstallTest.php
core/modules/system/system.admin.inc
core/modules/taxonomy/lib/Drupal/taxonomy/Tests/VocabularyUnitTest.php

index cd67257..d203db4 100644 (file)
@@ -329,79 +329,6 @@ function drupal_install_system() {
 }
 
 /**
- * Uninstalls a given list of modules.
- *
- * @param $module_list
- *   The modules to uninstall.
- * @param $uninstall_dependents
- *   If TRUE, the function will check that all modules which depend on the
- *   passed-in module list either are already uninstalled or contained in the
- *   list, and it will ensure that the modules are uninstalled in the correct
- *   order. This incurs a significant performance cost, so use FALSE if you
- *   know $module_list is already complete and in the correct order.
- *
- * @return
- *   FALSE if one or more dependent modules are missing from the list, TRUE
- *   otherwise.
- */
-function drupal_uninstall_modules($module_list = array(), $uninstall_dependents = TRUE) {
-  if ($uninstall_dependents) {
-    // Get all module data so we can find dependents and sort.
-    $module_data = system_rebuild_module_data();
-    // Create an associative array with weights as values.
-    $module_list = array_flip(array_values($module_list));
-
-    $profile = drupal_get_profile();
-    while (list($module) = each($module_list)) {
-      if (!isset($module_data[$module]) || drupal_get_installed_schema_version($module) == SCHEMA_UNINSTALLED) {
-        // This module doesn't exist or is already uninstalled, skip it.
-        unset($module_list[$module]);
-        continue;
-      }
-      $module_list[$module] = $module_data[$module]->sort;
-
-      // If the module has any dependents which are not already uninstalled and
-      // not included in the passed-in list, abort. It is not safe to uninstall
-      // them automatically because uninstalling a module is a destructive
-      // operation.
-      foreach (array_keys($module_data[$module]->required_by) as $dependent) {
-        if (!isset($module_list[$dependent]) && drupal_get_installed_schema_version($dependent) != SCHEMA_UNINSTALLED && $dependent != $profile) {
-          return FALSE;
-        }
-      }
-    }
-
-    // Sort the module list by pre-calculated weights.
-    asort($module_list);
-    $module_list = array_keys($module_list);
-  }
-
-  $storage = new DatabaseStorage();
-  foreach ($module_list as $module) {
-    // Uninstall the module.
-    module_load_install($module);
-    module_invoke($module, 'uninstall');
-    drupal_uninstall_schema($module);
-
-    // Remove all configuration belonging to the module.
-    $config_names = $storage->listAll($module . '.');
-    foreach ($config_names as $config_name) {
-      config($config_name)->delete();
-    }
-
-    watchdog('system', '%module module uninstalled.', array('%module' => $module), WATCHDOG_INFO);
-    drupal_set_installed_schema_version($module, SCHEMA_UNINSTALLED);
-  }
-
-  if (!empty($module_list)) {
-    // Call hook_module_uninstall to let other modules act
-    module_invoke_all('modules_uninstalled', $module_list);
-  }
-
-  return TRUE;
-}
-
-/**
  * Verify the state of the specified file.
  *
  * @param $file
index a3de431..f40161d 100644 (file)
@@ -6,6 +6,7 @@
  */
 
 use Drupal\Component\Graph\Graph;
+use Drupal\Core\Config\DatabaseStorage;
 
 /**
  * Load all the modules that have been enabled in the system table.
@@ -580,6 +581,79 @@ function module_disable($module_list, $disable_dependents = TRUE) {
 }
 
 /**
+ * Uninstalls a given list of modules.
+ *
+ * @param $module_list
+ *   The modules to uninstall.
+ * @param $uninstall_dependents
+ *   If TRUE, the function will check that all modules which depend on the
+ *   passed-in module list either are already uninstalled or contained in the
+ *   list, and it will ensure that the modules are uninstalled in the correct
+ *   order. This incurs a significant performance cost, so use FALSE if you
+ *   know $module_list is already complete and in the correct order.
+ *
+ * @return
+ *   FALSE if one or more dependent modules are missing from the list, TRUE
+ *   otherwise.
+ */
+function module_uninstall($module_list = array(), $uninstall_dependents = TRUE) {
+  if ($uninstall_dependents) {
+    // Get all module data so we can find dependents and sort.
+    $module_data = system_rebuild_module_data();
+    // Create an associative array with weights as values.
+    $module_list = array_flip(array_values($module_list));
+
+    $profile = drupal_get_profile();
+    while (list($module) = each($module_list)) {
+      if (!isset($module_data[$module]) || drupal_get_installed_schema_version($module) == SCHEMA_UNINSTALLED) {
+        // This module doesn't exist or is already uninstalled, skip it.
+        unset($module_list[$module]);
+        continue;
+      }
+      $module_list[$module] = $module_data[$module]->sort;
+
+      // If the module has any dependents which are not already uninstalled and
+      // not included in the passed-in list, abort. It is not safe to uninstall
+      // them automatically because uninstalling a module is a destructive
+      // operation.
+      foreach (array_keys($module_data[$module]->required_by) as $dependent) {
+        if (!isset($module_list[$dependent]) && drupal_get_installed_schema_version($dependent) != SCHEMA_UNINSTALLED && $dependent != $profile) {
+          return FALSE;
+        }
+      }
+    }
+
+    // Sort the module list by pre-calculated weights.
+    asort($module_list);
+    $module_list = array_keys($module_list);
+  }
+
+  $storage = new DatabaseStorage();
+  foreach ($module_list as $module) {
+    // Uninstall the module.
+    module_load_install($module);
+    module_invoke($module, 'uninstall');
+    drupal_uninstall_schema($module);
+
+    // Remove all configuration belonging to the module.
+    $config_names = $storage->listAll($module . '.');
+    foreach ($config_names as $config_name) {
+      config($config_name)->delete();
+    }
+
+    watchdog('system', '%module module uninstalled.', array('%module' => $module), WATCHDOG_INFO);
+    drupal_set_installed_schema_version($module, SCHEMA_UNINSTALLED);
+  }
+
+  if (!empty($module_list)) {
+    // Call hook_module_uninstall to let other modules act
+    module_invoke_all('modules_uninstalled', $module_list);
+  }
+
+  return TRUE;
+}
+
+/**
  * @defgroup hooks Hooks
  * @{
  * Allow modules to interact with the Drupal core.
index 30595dd..b63e8cd 100644 (file)
@@ -87,7 +87,7 @@ class LocaleUninstallTest extends WebTestBase {
 
     // Uninstall Locale.
     module_disable($locale_module);
-    drupal_uninstall_modules($locale_module);
+    module_uninstall($locale_module);
 
     // Visit the front page.
     $this->drupalGet('');
index c63a7b2..8468185 100644 (file)
@@ -205,8 +205,8 @@ class ModuleApiTest extends WebTestBase {
     // Try to uninstall the PHP module by itself. This should be rejected,
     // since the modules which it depends on need to be uninstalled first, and
     // that is too destructive to perform automatically.
-    $result = drupal_uninstall_modules(array('php'));
-    $this->assertFalse($result, t('Calling drupal_uninstall_modules() on a module whose dependents are not uninstalled fails.'));
+    $result = module_uninstall(array('php'));
+    $this->assertFalse($result, t('Calling module_uninstall() on a module whose dependents are not uninstalled fails.'));
     foreach (array('forum', 'poll', 'php') as $module) {
       $this->assertNotEqual(drupal_get_installed_schema_version($module), SCHEMA_UNINSTALLED, t('The @module module was not uninstalled.', array('@module' => $module)));
     }
@@ -214,17 +214,17 @@ class ModuleApiTest extends WebTestBase {
     // Now uninstall all three modules explicitly, but in the incorrect order,
     // and make sure that drupal_uninstal_modules() uninstalled them in the
     // correct sequence.
-    $result = drupal_uninstall_modules(array('poll', 'php', 'forum'));
-    $this->assertTrue($result, t('drupal_uninstall_modules() returns the correct value.'));
+    $result = module_uninstall(array('poll', 'php', 'forum'));
+    $this->assertTrue($result, t('module_uninstall() returns the correct value.'));
     foreach (array('forum', 'poll', 'php') as $module) {
       $this->assertEqual(drupal_get_installed_schema_version($module), SCHEMA_UNINSTALLED, t('The @module module was uninstalled.', array('@module' => $module)));
     }
-    $this->assertEqual(variable_get('test_module_uninstall_order', array()), array('forum', 'poll', 'php'), t('Modules were uninstalled in the correct order by drupal_uninstall_modules().'));
+    $this->assertEqual(variable_get('test_module_uninstall_order', array()), array('forum', 'poll', 'php'), t('Modules were uninstalled in the correct order by module_uninstall().'));
 
     // Uninstall the profile module from above, and make sure that the profile
     // itself is not on the list of dependent modules to be uninstalled.
-    $result = drupal_uninstall_modules(array('comment'));
-    $this->assertTrue($result, t('drupal_uninstall_modules() returns the correct value.'));
+    $result = module_uninstall(array('comment'));
+    $this->assertTrue($result, t('module_uninstall() returns the correct value.'));
     $this->assertEqual(drupal_get_installed_schema_version('comment'), SCHEMA_UNINSTALLED, t('Comment module was uninstalled.'));
     $uninstalled_modules = variable_get('test_module_uninstall_order', array());
     $this->assertTrue(in_array('comment', $uninstalled_modules), t('Comment module is in the list of uninstalled modules.'));
index bc9556f..98bed37 100644 (file)
@@ -32,7 +32,7 @@ class UninstallTest extends WebTestBase {
     // Uninstalls the module_test module, so hook_modules_uninstalled()
     // is executed.
     module_disable(array('module_test'));
-    drupal_uninstall_modules(array('module_test'));
+    module_uninstall(array('module_test'));
 
     // Are the perms defined by module_test removed from {role_permission}.
     $count = db_query("SELECT COUNT(rid) FROM {role_permission} WHERE permission = :perm", array(':perm' => 'module_test perm'))->fetchField();
index a60c3fb..f11f15b 100644 (file)
@@ -1343,7 +1343,7 @@ function system_modules_uninstall_submit($form, &$form_state) {
   if (!empty($form['#confirmed'])) {
     // Call the uninstall routine for each selected module.
     $modules = array_keys($form_state['values']['uninstall']);
-    drupal_uninstall_modules($modules);
+    module_uninstall($modules);
     drupal_set_message(t('The selected modules have been uninstalled.'));
 
     $form_state['redirect'] = 'admin/modules/uninstall';
index 8d94383..883ab6e 100644 (file)
@@ -206,7 +206,7 @@ class VocabularyUnitTest extends TaxonomyTestBase {
 
     module_disable(array('taxonomy'));
     require_once DRUPAL_ROOT . '/core/includes/install.inc';
-    drupal_uninstall_modules(array('taxonomy'));
+    module_uninstall(array('taxonomy'));
     module_enable(array('taxonomy'));
 
     // Now create a vocabulary with the same name. All field instances