function drush_pm_enable

8.0.x pm.drush.inc drush_pm_enable()
6.x pm.drush.inc drush_pm_enable()
7.x pm.drush.inc drush_pm_enable()
3.x pm.drush.inc drush_pm_enable()
4.x pm.drush.inc drush_pm_enable()
5.x pm.drush.inc drush_pm_enable()
master pm.drush.inc drush_pm_enable()

Command callback. Enable one or more projects.

File

commands/pm/pm.drush.inc, line 324
The drush Package Manager

Code

function drush_pm_enable() {
  $args = func_get_args();

  $project_info = drush_get_projects();

  // Classify $args in themes, modules or unknown.
  $modules = array();
  $themes = array();
  drush_pm_classify_projects($args, $modules, $themes, $project_info);
  $projects = array_merge($modules, $themes);
  $unknown = array_diff($args, $projects);

  // Discard and set an error for each unknown project.
  foreach ($unknown as $project) {
    drush_set_error('DRUSH_PM_ENABLE_PROJECT_NOT_FOUND', dt('!project was not found and will not be enabled.', array('!project' => $project)));
  }

  // Discard already enabled projects.
  foreach ($projects as $project) {
    if ($project_info[$project]->status) {
      if ($project_info[$project]->type == 'module') {
        unset($modules[$project]);
      }
      else {
        unset($themes[$project]);
      }
      drush_log(dt('!project is already enabled.', array('!project' => $project)), 'ok');
    }
  }

  if (!empty($modules)) {
    // Check module dependencies.
    $dependencies = drush_check_module_dependencies($modules, $project_info);
    $all_dependencies = array();
    foreach ($dependencies as $key => $info) {
      if (isset($info['error'])) {
        unset($modules[$key]);
        drush_set_error($info['error']['code'], $info['error']['message']);
      }
      elseif (!empty($info['dependencies'])) {
        // Make sure we have an assoc array.
        $assoc = drupal_map_assoc($info['dependencies']);
        $all_dependencies = array_merge($all_dependencies, $assoc);
      }
    }
    $all_dependencies = array_unique($all_dependencies);
    $enabled = array_keys(array_filter(drush_get_modules(), 'pm_is_enabled'));
    $needed = array_diff($all_dependencies, $enabled);
    $modules = $needed + $modules;

    // Discard modules which don't meet requirements.
    require_once drush_get_context('DRUSH_DRUPAL_ROOT') . '/includes/install.inc';
    foreach ($modules as $key => $module) {
      // Check to see if the module can be installed/enabled (hook_requirements).
      // See @system_modules_submit
      if (!drupal_check_module($module)) {
        unset($modules[$key]);
        drush_set_error('DRUSH_PM_ENABLE_MODULE_UNMEET_REQUIREMENTS', dt('Module !module don\'t meet the requirements to be enabled.', array('!module' => $module)));
      }
    }
  }

  // Inform the user which projects will finally be enabled.
  $projects = array_merge($modules, $themes);
  if (empty($projects)) {
    return drush_log(dt('There were no projects that could be enabled.'), 'ok');
  }
  else {
    drush_print(dt('The following projects will be enabled: !projects', array('!projects' => implode(', ', $projects))));
    if (!drush_confirm(dt('Do you really want to continue?'))) {
      return drush_log(dt('Aborting.'));
    }
  }

  // Enable themes.
  if (!empty($themes)) {
    drush_theme_enable($themes);
  }

  // Enable modules and pass dependency validation in form submit.
  if (!empty($modules)) {
    drush_module_enable($modules);
    $current = drupal_map_assoc($enabled, 'pm_true');
    $processed = drupal_map_assoc($modules, 'pm_true');
    $active_modules = array_merge($current, $processed);
    drush_system_modules_form_submit($active_modules);
  }

  // Inform the user of final status.
  $rsc = drush_db_select('system', array('name', 'status'), 'name IN (:projects)', array(':projects' => $projects));
  while ($project = drush_db_fetch_object($rsc)) {
    if ($project->status) {
      drush_log(dt('!project was enabled successfully.', array('!project' => $project->name)), 'ok');
    }
    else {
      drush_set_error('DRUSH_PM_ENABLE_PROJECT_ISSUE', dt('There was a problem enabling !project.', array('!project' => $project->name)));
    }
  }
}