}
/**
- * 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
*/
use Drupal\Component\Graph\Graph;
+use Drupal\Core\Config\DatabaseStorage;
/**
* Load all the modules that have been enabled in the system table.
}
/**
+ * 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.
// Uninstall Locale.
module_disable($locale_module);
- drupal_uninstall_modules($locale_module);
+ module_uninstall($locale_module);
// Visit the front page.
$this->drupalGet('');
// 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)));
}
// 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.'));
// 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();
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';
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