drupal_uninstall_modules

Versions
7
drupal_uninstall_modules($module_list = array())

Calls the uninstall function and updates the system table for a given module.

Parameters

$module_list The modules to uninstall.

Code

includes/install.inc, line 665

<?php
function drupal_uninstall_modules($module_list = array()) {
  foreach ($module_list as $module) {
    // First, retrieve all the module's menu paths from db.
    drupal_load('module', $module);
    $paths = module_invoke($module, 'menu');

    // Uninstall the module.
    module_load_install($module);
    module_invoke($module, 'uninstall');
    drupal_uninstall_schema($module);

    watchdog('system', '%module module uninstalled.', array('%module' => $module), WATCHDOG_INFO);

    // Now remove the menu links for all paths declared by this module.
    if (!empty($paths)) {
      $paths = array_keys($paths);
      // Clean out the names of load functions.
      foreach ($paths as $index => $path) {
        $parts = explode('/', $path, MENU_MAX_PARTS);
        foreach ($parts as $k => $part) {
          if (preg_match('/^%[a-z_]*$/', $part)) {
            $parts[$k] = '%';
          }
        }
        $paths[$index] = implode('/', $parts);
      }

      $result = db_select('menu_links')
        ->fields('menu_links')
        ->condition('router_path', $paths, 'IN')
        ->condition('external', 0)
        ->orderBy('depth')
        ->execute();
      // Remove all such items. Starting from those with the greatest depth will
      // minimize the amount of re-parenting done by menu_link_delete().
      foreach ($result as $item) {
        _menu_delete_item($item, TRUE);
      }
    }

    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);
  }
}
?>
Login or register to post comments
 
 

All source code and documentation on this site is released under the terms of the GNU General Public License, version 2 and later. Drupal is a registered trademark of Dries Buytaert.