function block_module($op, $module) { if ($op == 'uninstall' && module_hook($module, 'block') { db_delete('blocks')->condition('module', $module)->execute(); db_delete('blocks_roles')->condition('module', $module)->execute(); } } function actions_module($op, $module) { if ($op == 'uninstall') { $module_actions = module_invoke($module, 'action_info'); foreach(array_keys($module_actions) as $aid) { actions_delete($aid); } } } function filter_module($op, $module) { if ($op == 'uninstall' && module_hook($module, 'filter')) { db_delete('filters')->condition('module', $module)->execute(); } } function node_module($op, $module) { // TODO Suppress messages and watchdog? if ($op == 'uninstall') { $node_types = module_invoke($module, 'node_info'); foreach(array_keys($node_types) as $type) { $nodes = db_query("SELECT nid FROM {node} WHERE type = :type", $type); foreach(db_result($nodes) as $nid) { node_delete($nid); } node_delete_type($type); } } } function user_module($op, $module) { if ($op == 'uninstall') { $perms = module_invoke($module, 'perm'); if (!empty($perms)) { db_delete('role_permission')->condition('permission', array_keys($perms), 'IN')->execute(); } } } function menu_module($op, $module) { if ($op == 'uninstall') { $module_paths = module_invoke($module, 'menu'); // Now remove the menu links for all paths declared by this module. if (!empty($module_paths)) { $module_paths = array_keys($module_paths); // Clean out the names of load functions. foreach ($module_paths as $index => $path) { $parts = explode('/', $path, MENU_MAX_PARTS); foreach ($parts as $k => $part) { if (preg_match('/^%[a-z_]*$/', $part)) { $parts[$k] = '%'; } } $module_paths[$index] = implode('/', $parts); } $placeholders = implode(', ', array_fill(0, count($module_paths), "'%s'")); $result = db_query('SELECT * FROM {menu_links} WHERE router_path IN (' . $placeholders . ') AND external = 0 ORDER BY depth DESC', $module_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); } } } } function drupal_uninstall_module($module) { // Allow other modules to act on uninstalling the module(s) drupal_load('module', $module); module_invoke_all('module', 'uninstall', $module); // Uninstall the module(s). module_load_install($module); module_invoke($module, 'uninstall'); cache_clear_all(); drupal_set_installed_schema_version($module, SCHEMA_UNINSTALLED); }