function Project::filterReleases

8.0.x Project.php Project::filterReleases($filter = '', $installed_version = NULL)
7.x Project.php Project::filterReleases($filter = '', $installed_version = NULL)
master Project.php Project::filterReleases($filter = '', $installed_version = NULL)

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.

Parameters

string $filter: Valid values:

  • 'all': Select all releases.
  • 'dev': Select all development releases.

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 value

array List of releases matching the filter criteria.

File

lib/Drush/UpdateService/Project.php, line 479

Namespace

Drush\UpdateService

Class

Project
Representation of a project's release info from the update service.

Code

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;
      }
    }
    // The Drupal core version scheme (ex: 7.31) is different to
    // other projects (ex 7.x-3.2). We need to manage this special case.
    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;
        }
      }
    }
    // Otherwise, pick only the first release in each status.
    // For example after we pick out the first security release,
    // we won't pick any other. We do this on a per-major-version basis,
    // though, so if a project has three major versions, then we will
    // pick out the first security release from each.
    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;
}