module_enable

Versions
5 – 6
module_enable($module_list)
7
module_enable($module_list, $disable_modules_installed_hook = FALSE)

Enable a given list of modules.

Parameters

$module_list An array of module names.

$disable_modules_installed_hook Normally just testing wants to set this to TRUE.

▾ 4 functions call module_enable()

drupal_install_modules in includes/install.inc
Calls the install function for a given list of modules.
system_modules_submit in modules/system/system.admin.inc
Submit callback; handles modules form submission.
system_update_7020 in modules/system/system.install
Enable field module.
system_update_7027 in modules/system/system.install
Enable field type modules.

Code

includes/module.inc, line 212

<?php
function module_enable($module_list, $disable_modules_installed_hook = FALSE) {
  $invoke_modules = array();

  // Try to install the enabled modules and collect which were installed.
  // $module_list is not changed and already installed modules are ignored.
  $modules_installed = array_filter($module_list, '_drupal_install_module');
  foreach ($module_list as $module) {
    $existing = db_query("SELECT status FROM {system} WHERE type = :type AND name = :name", array(
      ':type' => 'module',
      ':name' => $module))
      ->fetchObject();
    if ($existing->status == 0) {
      module_load_install($module);
      db_update('system')
        ->fields(array('status' => 1))
        ->condition('type', 'module')
        ->condition('name', $module)
        ->execute();
      drupal_load('module', $module);
      $invoke_modules[] = $module;
      watchdog('system', '%module module enabled.', array('%module' => $module), WATCHDOG_INFO);
    }
  }

  if (!empty($invoke_modules)) {
    // Refresh the module list to exclude the disabled modules.
    module_list(TRUE);
    module_implements('', FALSE, TRUE);
    // Force to regenerate the stored list of hook implementations.
    registry_rebuild();
    // Refresh the schema to include the new enabled module.
    drupal_get_schema(NULL, TRUE);

    // If any modules were newly installed, execute the hook for them.
    if (!$disable_modules_installed_hook && !empty($modules_installed)) {
      module_invoke_all('modules_installed', $modules_installed);
    }
  }

  foreach ($invoke_modules as $module) {
    module_invoke($module, 'enable');
    // Check if node_access table needs rebuilding.
    // We check for the existence of node_access_needs_rebuild() since
    // at install time, module_enable() could be called while node.module
    // is not enabled yet.
    if (function_exists('node_access_needs_rebuild') && !node_access_needs_rebuild() && module_hook($module, 'node_grants')) {
      node_access_needs_rebuild(TRUE);
    }
  }

  if (!empty($invoke_modules)) {
    // Invoke hook_modules_enabled after all the modules have been
    // enabled.
    module_invoke_all('modules_enabled', $invoke_modules);
  }
}
?>
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.