function module_uninstall

Uninstalls a given list of modules.

Parameters

$module_list: The modules to uninstall.

$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 value

FALSE if one or more dependent modules are missing from the list, TRUE otherwise.

6 calls to module_uninstall()
BreakpointThemeTest::testThemeBreakpointGroupModule in drupal/core/modules/breakpoint/lib/Drupal/breakpoint/Tests/BreakpointThemeTest.php
Test the breakpoints defined by the custom group in the module.
LocaleUninstallTest::testUninstallProcess in drupal/core/modules/locale/lib/Drupal/locale/Tests/LocaleUninstallTest.php
Check if the values of the Locale variables are correct after uninstall.
ModuleApiTest::testDependencyResolution in drupal/core/modules/system/lib/Drupal/system/Tests/Module/ModuleApiTest.php
Test dependency resolution.
system_modules_uninstall_submit in drupal/core/modules/system/system.admin.inc
Processes the submitted uninstall form.
UninstallTest::testUserPermsUninstalled in drupal/core/modules/system/lib/Drupal/system/Tests/Module/UninstallTest.php
Tests the hook_modules_uninstalled() of the user module.

... See full list

File

drupal/core/includes/module.inc, line 679
API for loading and interacting with Drupal modules.

Code

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 = drupal_container()
    ->get('config.storage');
  $schema_store = drupal_container()
    ->get('keyvalue')
    ->get('system.schema');
  $disabled_config = config('system.module.disabled');
  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_uninstall_default_config('module', $module);
    watchdog('system', '%module module uninstalled.', array(
      '%module' => $module,
    ), WATCHDOG_INFO);
    $schema_store
      ->delete($module);
    $disabled_config
      ->clear($module);
  }
  $disabled_config
    ->save();
  drupal_get_installed_schema_version(NULL, TRUE);
  if (!empty($module_list)) {

    // Call hook_module_uninstall to let other modules act
    module_invoke_all('modules_uninstalled', $module_list);
  }
  return TRUE;
}