function drush_pm_updatecode

8.0.x updatecode.pm.inc drush_pm_updatecode()
6.x updatecode.pm.inc drush_pm_updatecode()
7.x updatecode.pm.inc drush_pm_updatecode()
3.x updatecode.pm.inc drush_pm_updatecode()
4.x updatecode.pm.inc drush_pm_updatecode()
5.x updatecode.pm.inc drush_pm_updatecode()
master updatecode.pm.inc drush_pm_updatecode()

Command callback. Displays update status info and allows to update installed projects.

Pass specific projects as arguments, otherwise we update all that have candidate releases.

This command prompts for confirmation before updating, so it is safe to run just to check on. In this case, say at the confirmation prompt.

File

commands/pm/updatecode.pm.inc, line 19
pm-updatecode command implementation.

Code

function drush_pm_updatecode() {
  // In --pipe mode, just run pm-updatestatus and exit.
  if (drush_get_context('DRUSH_PIPE')) {
    drush_set_option('strict', 0);
    return drush_invoke('pm-updatestatus');
  }

  $update_status = drush_get_engine('update_status');

  // Get specific requests.
  $requests = pm_parse_arguments(func_get_args(), FALSE);

  // Print report of modules to update, and record
  // result of that function in $update_info.
  $updatestatus_options = array();
  foreach (array(
    'lock',
    'unlock',
    'lock-message',
    'update-backend',
    'check-disabled',
    'security-only',
  ) as $option) {
    $value = drush_get_option($option, FALSE);
    if ($value) {
      $updatestatus_options[$option] = $value;
    }
  }
  $backend_options = array(
    'integrate' => FALSE,
  );
  $values = drush_invoke_process("@self", 'pm-updatestatus', func_get_args(), $updatestatus_options, $backend_options);
  if (!is_array($values) || $values['error_status']) {
    return drush_set_error('pm-updatestatus failed.');
  }
  $last = $update_status->lastCheck();
  drush_print(dt('Update information last refreshed: ') . ($last ? format_date($last) : dt('Never')));
  drush_print($values['output']);

  $update_info = $values['object'];

  // Prevent update of core if --no-core was specified.
  if (isset($update_info['drupal']) && drush_get_option('no-core', FALSE)) {
    unset($update_info['drupal']);
    drush_print(dt('Skipping core update (--no-core specified).'));
  }

  // Remove locked and non-updateable projects.
  foreach ($update_info as $name => $project) {
    if ((isset($project['locked']) && !isset($requests[$name])) || (!isset($project['updateable']) || !$project['updateable'])) {
      unset($update_info[$name]);
    }
  }

  // Do no updates in simulated mode.
  if (drush_get_context('DRUSH_SIMULATE')) {
    return drush_log(dt('No action taken in simulated mode.'), LogLevel::OK);
    return TRUE;
  }

  $tmpfile = drush_tempnam('pm-updatecode.');

  $core_update_available = FALSE;
  if (isset($update_info['drupal'])) {
    $drupal_project = $update_info['drupal'];
    unset($update_info['drupal']);

    // At present we need to update drupal core after non-core projects
    // are updated.
    if (empty($update_info)) {
      return _pm_update_core($drupal_project, $tmpfile);
    }
    // If there are modules other than drupal core enabled, then update them
    // first.
    else {
      $core_update_available = TRUE;
      if ($drupal_project['status'] == DRUSH_UPDATESTATUS_NOT_SECURE) {
        drush_print(dt("NOTE: A security update for the Drupal core is available."));
      }
      else {
        drush_print(dt("NOTE: A code update for the Drupal core is available."));
      }
      drush_print(dt("Drupal core will be updated after all of the non-core projects are updated.\n"));
    }
  }

  // If there are no releases to update, then print a final
  // exit message.
  if (empty($update_info)) {
    if (drush_get_option('security-only')) {
      return drush_log(dt('No security updates available.'), LogLevel::OK);
    }
    else {
      return drush_log(dt('No code updates available.'), LogLevel::OK);
    }
  }

  // Offer to update to the identified releases.
  if (!pm_update_packages($update_info, $tmpfile)) {
    return FALSE;
  }

  // After projects are updated we can update core.
  if ($core_update_available) {
    drush_print();
    return _pm_update_core($drupal_project, $tmpfile);
  }
}