function drush_check_self_update

4.x drush.inc drush_check_self_update()
5.x drush.inc drush_check_self_update()

Check to see if a newer version of drush is available

Return value

TRUE - A new version is available. FALSE - Error. NULL - No release available.

2 calls to drush_check_self_update()
drush_core_version in commands/core/core.drush.inc
Called for `drush version` or `drush --version`
drush_pm_updatecode in commands/pm/updatecode.pm.inc
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.

File

includes/drush.inc, line 181
The drush API implementation and helpers.

Code

function drush_check_self_update() {
  $error = "";

  // Don't check unless we have a datestamp in drush.info
  $drush_info = drush_read_drush_info();
  if (($drush_info === FALSE) || (!array_key_exists('datestamp', $drush_info))) {
    drush_log(dt('Cannot determine release date for drush'), 'notice');
    return FALSE;
  }

  // Allow updates to the latest HEAD release if --self-update=head is specified.
  // If we are called from `drush self-update`, then --dev will set --self-update=head.
  $dev_ok = (drush_get_option('self-update') == 'head');
  $is_dev = FALSE;

  // Get release info for drush
  $info = _drush_pm_get_releases(array('drush'));
  // Check for newer releases based on the datestamp.
  // We add 60 seconds to the drush.info date because of a drupal.org WTF. See http://drupal.org/node/1019356.
  $version_date = $drush_info['datestamp'] + 60;
  $newer_version = FALSE;
  foreach ($info['drush']['releases'] as $version => $release_info) {
    // We deliberately skip any dev releases unless the current release is a dev release.
    if ($dev_ok || ((!array_key_exists('version_extra', $release_info) || ($release_info['version_extra'] != 'dev')))) {
      if ($release_info['date'] > $version_date) {
        $newer_version = $release_info['version'];
        $version_date = $release_info['date'];
        $is_dev = isset($release_info['version_extra']) && $release_info['version_extra'] == 'dev';
        if ($is_dev) {
          $newer_version .= " (" . date('Y-M-d', $version_date) . ")";
        }
      }
    }
  }

  if ($newer_version) {
    drush_print(dt('A newer version of drush, !version, is available.  You are currently running drush version !currentversion; to update, run `drush self-update`.  To disable this check, put "$options[\'self-update\'] = FALSE;" in your drushrc.php configuration file.' . "\n", array('!version' => $newer_version, '!currentversion' => DRUSH_VERSION)));
    return TRUE;
  }
  else {
    drush_log(dt("drush self-update check: drush !version is up-to-date.", array('!version' => DRUSH_VERSION)), 'notice');
  }

  return NULL;
}