function drush_pm_disable

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

Command callback. Disable one or more projects.

File

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

Code

function drush_pm_disable() {
  $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 disabled.', array('!project' => $project)));
  }

  // Discard already disabled 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 disabled.', array('!project' => $project)), 'ok');
    }
  }

  // Discard default theme.
  if (!empty($themes)) {
    $default_theme = drush_theme_get_default();
    if (in_array($default_theme, $themes)) {
      unset($themes[$default_theme]);
      drush_log(dt('!theme is the default theme and can\'t be disabled.', array('!theme' => $default_theme)), 'ok');
    }
  }

  // Add enabled dependents to list of modules to disable.
  if (!empty($modules)) {
    $enabled = array_keys(array_filter(drush_get_modules(), 'pm_is_enabled'));
    $dependents = drush_module_dependents($modules, $project_info);
    $dependents = array_unique($dependents);
    $dependents = array_intersect($dependents, $enabled);
    $modules = array_merge($modules, $dependents);
  }

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

  // Disable themes.
  if (!empty($themes)) {
    drush_theme_disable($themes);
  }

  // Disable modules and pass dependency validation in form submit.
  if (!empty($modules)) {
    drush_module_disable($modules);
    $active_modules = array_diff($enabled, $modules);
    $active_modules = drupal_map_assoc($active_modules, 'pm_true');
    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 disabled successfully.', array('!project' => $project->name)), 'ok');
    }
    else {
      drush_set_error('DRUSH_PM_DISABLE_PROJECT_ISSUE', dt('There was a problem disabling !project.', array('!project' => $project->name)));
    }
  }
}