示例#1
0
 /**
  * Calculates update status for given projects.
  */
 private function calculateUpdateStatus($available, $projects)
 {
     $update_info = array();
     foreach ($available as $project_name => $project_release_info) {
         // Obtain project 'global' status. NULL status is ok (project published),
         // otherwise it signals something is bad with the project (revoked, etc).
         $project_status = $this->calculateProjectStatus($project_release_info);
         // Discard custom projects.
         if ($project_status == DRUSH_UPDATESTATUS_UNKNOWN) {
             continue;
         }
         // Prepare update info.
         $project = $projects[$project_name];
         $is_core = $project['type'] == 'core';
         $version = pm_parse_version($project['version'], $is_core);
         // If project version ends with 'dev', this is a dev snapshot.
         $install_type = substr($project['version'], -3, 3) == 'dev' ? 'dev' : 'official';
         $project_update_info = array('name' => $project_name, 'label' => $project['label'], 'path' => isset($project['path']) ? $project['path'] : '', 'install_type' => $install_type, 'existing_version' => $project['version'], 'existing_major' => $version['version_major'], 'status' => $project_status, 'datestamp' => empty($project['datestamp']) ? NULL : $project['datestamp']);
         // If we don't have a project status yet, it means this is
         // a published project and we need to obtain its update status
         // and recommended release.
         if (is_null($project_status)) {
             $this->calculateProjectUpdateStatus($project_release_info, $project_update_info);
         }
         // We want to ship all release info data including all releases,
         // not just the ones selected by calculateProjectUpdateStatus().
         // We use it to allow the user to update to a specific version.
         unset($project_update_info['releases']);
         $update_info[$project_name] = $project_update_info + $project_release_info->getInfo();
     }
     return $update_info;
 }
示例#2
0
文件: Project.php 项目: hanoii/drush
 /**
  * Filter project releases by a criteria and returns a list.
  *
  * If no filter is provided, the first Recommended, Supported, Security
  * or Development release on each major version will be shown.
  *
  * @param string $filter
  *   Valid values:
  *     - 'all': Select all releases.
  *     - 'dev': Select all development releases.
  * @param string $installed_version
  *   Version string. If provided, Select all releases in the same
  *   version_major branch until the provided one is found.
  *   On any other branch, the default behaviour will be applied.
  *
  * @return array
  *   List of releases matching the filter criteria.
  */
 function filterReleases($filter = '', $installed_version = NULL)
 {
     $releases = $this->parsed['releases'];
     usort($releases, array($this, 'compareDates'));
     $installed_version = pm_parse_version($installed_version);
     // Iterate through and filter out the releases we're interested in.
     $options = array();
     $limits_list = array();
     foreach ($releases as $release) {
         $eligible = FALSE;
         // Mark as eligible if the filter criteria matches.
         if ($filter == 'all') {
             $eligible = TRUE;
         } elseif ($filter == 'dev') {
             if (!empty($release['version_extra']) && $release['version_extra'] == 'dev') {
                 $eligible = TRUE;
             }
         } elseif ($this->getType() != 'core' && $installed_version['version_major'] == $release['version_major']) {
             // In case there's no filter, select all releases until the installed one.
             // Always show the dev release.
             if (isset($release['version_extra']) && $release['version_extra'] == 'dev') {
                 $eligible = TRUE;
             } else {
                 if (self::compareVersions($release, $installed_version) < 1) {
                     $eligible = TRUE;
                 }
             }
         } else {
             foreach ($release['release_status'] as $one_status) {
                 $test_key = $release['version_major'] . $one_status;
                 if (empty($limits_list[$test_key])) {
                     $limits_list[$test_key] = TRUE;
                     $eligible = TRUE;
                 }
             }
         }
         if ($eligible) {
             $options[$release['version']] = $release;
         }
     }
     // Add Installed status.
     if (!is_null($installed_version) && isset($options[$installed_version['version']])) {
         $options[$installed_version['version']]['release_status'][] = 'Installed';
     }
     return $options;
 }
示例#3
0
 /**
  * Tests for pm_parse_version() with project versions.
  */
 public function testVersionParserContrib()
 {
     _drush_add_commandfiles(array(DRUSH_BASE_PATH . '/commands/pm'));
     drush_set_option('default-major', UNISH_DRUPAL_MAJOR_VERSION);
     $version = '';
     $version_parts = pm_parse_version($version);
     $this->assertEquals('', $version_parts['version']);
     $this->assertEquals(UNISH_DRUPAL_MAJOR_VERSION . '.x', $version_parts['drupal_version']);
     $this->assertEquals('', $version_parts['version_major']);
     $this->assertEquals('', $version_parts['version_minor']);
     $this->assertEquals('', $version_parts['version_patch']);
     $this->assertEquals('', $version_parts['version_extra']);
     $this->assertEquals('', $version_parts['project_version']);
     $version = '7';
     $version_parts = pm_parse_version($version);
     $this->assertEquals('', $version_parts['version']);
     $this->assertEquals('7.x', $version_parts['drupal_version']);
     $this->assertEquals('', $version_parts['version_major']);
     $this->assertEquals('', $version_parts['version_minor']);
     $this->assertEquals('', $version_parts['version_patch']);
     $this->assertEquals('', $version_parts['version_extra']);
     $this->assertEquals('', $version_parts['project_version']);
     $version = '7.x';
     $version_parts = pm_parse_version($version);
     $this->assertEquals('', $version_parts['version']);
     $this->assertEquals('7.x', $version_parts['drupal_version']);
     $this->assertEquals('', $version_parts['version_major']);
     $this->assertEquals('', $version_parts['version_minor']);
     $this->assertEquals('', $version_parts['version_patch']);
     $this->assertEquals('', $version_parts['version_extra']);
     $this->assertEquals('', $version_parts['project_version']);
     $version = '7.x-1.0-beta1';
     $version_parts = pm_parse_version($version);
     $this->assertEquals('7.x', $version_parts['drupal_version']);
     $this->assertEquals('1', $version_parts['version_major']);
     $this->assertEquals('', $version_parts['version_minor']);
     $this->assertEquals('0', $version_parts['version_patch']);
     $this->assertEquals('beta1', $version_parts['version_extra']);
     $this->assertEquals('1.0-beta1', $version_parts['project_version']);
     $version = '7.x-1.0-beta1+30-dev';
     $version_parts = pm_parse_version($version);
     $this->assertEquals('7.x', $version_parts['drupal_version']);
     $this->assertEquals('1', $version_parts['version_major']);
     $this->assertEquals('', $version_parts['version_minor']);
     $this->assertEquals('0', $version_parts['version_patch']);
     $this->assertEquals('beta1', $version_parts['version_extra']);
     $this->assertEquals('30', $version_parts['version_offset']);
     $this->assertEquals('1.0-beta1+30-dev', $version_parts['project_version']);
     $version = '7.x-1.0';
     $version_parts = pm_parse_version($version);
     $this->assertEquals('7.x', $version_parts['drupal_version']);
     $this->assertEquals('1', $version_parts['version_major']);
     $this->assertEquals('', $version_parts['version_minor']);
     $this->assertEquals('0', $version_parts['version_patch']);
     $this->assertEquals('', $version_parts['version_extra']);
     $this->assertEquals('1.0', $version_parts['project_version']);
     $version = '7.x-1.0+30-dev';
     $version_parts = pm_parse_version($version);
     $this->assertEquals('7.x', $version_parts['drupal_version']);
     $this->assertEquals('1', $version_parts['version_major']);
     $this->assertEquals('', $version_parts['version_minor']);
     $this->assertEquals('0', $version_parts['version_patch']);
     $this->assertEquals('', $version_parts['version_extra']);
     $this->assertEquals('30', $version_parts['version_offset']);
     $this->assertEquals('1.0+30-dev', $version_parts['project_version']);
     // Since we're not on a bootstrapped site, the version string
     // for the following cases is interpreted as a core version.
     // Tests on a bootstrapped site are in \pmRequestCase::testVersionParser()
     $version = '6.x';
     $version_parts = pm_parse_version($version);
     $this->assertEquals('6.x', $version_parts['drupal_version']);
     $this->assertEquals('', $version_parts['version_major']);
     $this->assertEquals('', $version_parts['version_minor']);
     $this->assertEquals('', $version_parts['version_patch']);
     $this->assertEquals('', $version_parts['version_extra']);
     $this->assertEquals('', $version_parts['project_version']);
     $version = '6.22';
     $version_parts = pm_parse_version($version);
     $this->assertEquals('6.x', $version_parts['drupal_version']);
     $this->assertEquals('', $version_parts['version_major']);
     $this->assertEquals('', $version_parts['version_minor']);
     $this->assertEquals('', $version_parts['version_patch']);
     $this->assertEquals('', $version_parts['version_extra']);
     $this->assertEquals('', $version_parts['project_version']);
 }