You are here

function drupal_uninstall_module in Drupal 6

Same name and namespace in other branches
  1. 5 includes/install.inc \drupal_uninstall_module()

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

Parameters

$module: The module to uninstall.

1 call to drupal_uninstall_module()
system_modules_uninstall_submit in modules/system/system.admin.inc
Processes the submitted uninstall form.

File

includes/install.inc, line 375

Code

function drupal_uninstall_module($module) {

  // First, retrieve all the module's menu paths from db.
  drupal_load('module', $module);
  $paths = module_invoke($module, 'menu');

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

  // 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);
    }
    $placeholders = implode(', ', array_fill(0, count($paths), "'%s'"));
    $result = db_query('SELECT * FROM {menu_links} WHERE router_path IN (' . $placeholders . ') AND external = 0 ORDER BY depth DESC', $paths);

    // Remove all such items. Starting from those with the greatest depth will
    // minimize the amount of re-parenting done by menu_link_delete().
    while ($item = db_fetch_array($result)) {
      _menu_delete_item($item, TRUE);
    }
  }
  drupal_set_installed_schema_version($module, SCHEMA_UNINSTALLED);
}