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 12

Code

function drush_pm_updatecode() {
  // We don't provide for other options here, so we supply an explicit path.
  drush_include_engine('update_info', 'drupal', NULL, DRUSH_BASE_PATH . '/commands/pm/update_info');

  // Find only security updates?
  $security_only = drush_get_option('security-only');

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

  // Get installed extensions and projects.
  $extensions = drush_get_extensions();
  $projects = drush_get_projects($extensions);

  // Parse out project name and version.
  $requests = pm_parse_project_version($requests, $projects);

  // Get update status information.
  $update_info = _pm_get_update_info($projects);

  // Process locks specified on the command line.
  $locked_list = drush_pm_update_lock($update_info, drush_get_option_list('lock'), drush_get_option_list('unlock'), drush_get_option('lock-message'));

  foreach ($extensions as $name => $extension) {
    // Add an item to $update_info for each enabled extension which was obtained
    // from cvs or git and its project is unknown (because of cvs_deploy or
    // git_deploy is not enabled).
    if (!isset($extension->info['project'])) {
      if ((isset($extension->vcs)) && ($extension->status)) {
        $update_info[$name] = array(
          'label' => $extension->label,
          'existing_version' => 'Unknown',
          'status' => DRUSH_PM_REQUESTED_PROJECT_NOT_PACKAGED,
          'status_msg' => dt('Project was not packaged by drupal.org but obtained from !vcs. You need to enable !vcs_deploy module', array('!vcs' => $extension->vcs)),
        );
        // The user may have requested to update a project matching this
        // extension. If it was by coincidence or error we don't mind as we've
        // already added an item to $update_info. Just clean up $requests.
        if (isset($requests[$name])) {
          unset($requests[$name]);
        }
      }
    }
    // Aditionally if the extension name is distinct to the project name and
    // the user asked to update the extension, fix the request.
    elseif ((isset($requests[$name])) && ($extension->name != $extension->info['project'])) {
      $requests[$extension->info['project']] = $requests[$name];
      unset($requests[$name]);
    }
  }

  // Add an item to $update_info for each request not present in $update_info.
  foreach ($requests as $name => $request) {
    if (!isset($update_info[$name])) {
      // Disabled projects.
      if ((isset($projects[$name])) && ($projects[$name]['status'] == 0)) {
        $update_info[$name] = array(
          'label' => $projects[$name]['label'],
          'existing_version' => $projects[$name]['version'],
          'status' => DRUSH_PM_REQUESTED_PROJECT_NOT_UPDATEABLE,
        );
        unset($requests[$name]);
      }
      // At this point we are unable to find matching installed project.
      // It does not exist at all or it is mispelled,...
      else {
        $update_info[$name] = array(
          'label' => $name,
          'existing_version' => 'Unknown',
          'status' => DRUSH_PM_REQUESTED_PROJECT_NOT_FOUND,
        );
      }
    }
  }

  // If specific versions were requested, match the requested release.
  foreach ($requests as $name => $request) {
    if (!empty($request['version'])) {
      $release = pm_get_release($request, $update_info[$name]);
      if (!$release) {
        $update_info[$name]['status'] = DRUSH_PM_REQUESTED_VERSION_NOT_FOUND;
      }
      else if ($release['version'] == $update_info[$name]['existing_version']) {
        $update_info[$name]['status'] = DRUSH_PM_REQUESTED_CURRENT;
      }
      else {
        $update_info[$name]['status'] = DRUSH_PM_REQUESTED_UPDATE;
      }
      // Set the candidate version to the requested release.
      $update_info[$name]['candidate_version'] = $release['version'];
    }
  }

  // Table headers.
  $rows[] = array(dt('Name'), dt('Installed version'), dt('Proposed version'), dt('Status'));

  // Process releases, notifying user of status and
  // building a list of proposed updates.
  $updateable = pm_project_filter($update_info, $rows, $security_only);

  // Pipe preparation.
  if (drush_get_context('DRUSH_PIPE')) {
    $pipe = "";
    foreach ($updateable as $project) {
      $pipe .= $project['name'] . " ";
      $pipe .= $project['existing_version'] . " ";
      $pipe .= $project['candidate_version'] . " ";
      $pipe .= str_replace(' ', '-', pm_update_filter($project)) . "\n";
    }
    drush_print_pipe($pipe);
    // Automatically curtail update process if in pipe mode.
    $updateable = array();
  }

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

  $last = pm_update_last_check();
  drush_print(dt('Update information last refreshed: ') . ($last ? format_date($last) : dt('Never')));
  drush_print();
  drush_print(dt("Update status information on all installed and enabled Drupal projects:"));
  // Cache the output of drush_print_table in $tmpfile so that we can
  // include it in the paginated output later.
  $tmphandle = fopen($tmpfile, 'a');
  drush_print_table($rows, TRUE, array(3 => 50), $tmphandle);
  fclose($tmphandle);
  $contents = file_get_contents($tmpfile);
  drush_print($contents);
  drush_print();

  // If specific project updates were requested then remove releases for all
  // others.
  $requested = func_get_args();
  if (!empty($requested)) {
    foreach ($updateable as $name => $project) {
      if (!isset($requests[$name])) {
        unset($updateable[$name]);
      }
    }
  }

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

  // If there are any locked projects that were not requested, then remove them.
  if (!empty($locked_list)) {
    foreach ($updateable as $name => $project) {
      if ((isset($locked_list[$name])) && (!isset($requests[$name]))) {
        unset($updateable[$name]);
      }
    }
  }

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

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

    // At present we need to update drupal core after non-core projects
    // are updated.
    if (empty($updateable)) {
      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'] == UPDATE_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 modules are updated.\n"));
    }
  }

  // If there are no releases to update, then print a final
  // exit message.
  if (empty($updateable)) {
    if ($security_only) {
      return drush_log(dt('No security updates available.'), 'ok');
    }
    else {
      return drush_log(dt('No code updates available.'), 'ok');
    }
  }

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

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