function updatexml_get_releases_from_xml

6.x updatexml.inc updatexml_get_releases_from_xml($xml, $project)
5.x updatexml.inc updatexml_get_releases_from_xml($xml, $project)

Obtain releases for a project's xml as returned by the update service.

2 calls to updatexml_get_releases_from_xml()
release_info_fetch in commands/pm/release_info/updatexml.inc
Obtain the most appropiate release for the requested project.
release_info_get_releases in commands/pm/release_info/updatexml.inc
Obtain releases info for given requests and fill in status information.

File

commands/pm/release_info/updatexml.inc, line 497
Drush release info engine for update.drupal.org and compatible services.

Code

function updatexml_get_releases_from_xml($xml, $project) {
  // If bootstraped, we can obtain which is the installed release of a project.
  static $installed_projects = FALSE;
  if (!$installed_projects) {
    if (drush_get_context('DRUSH_BOOTSTRAP_PHASE') >= DRUSH_BOOTSTRAP_DRUPAL_FULL) {
      $installed_projects = drush_get_projects();
    }
    else {
      $installed_projects = array();
    }
  }

  foreach (array(
    'title',
    'short_name',
    'dc:creator',
    'api_version',
    'recommended_major',
    'supported_majors',
    'default_major',
    'project_status',
    'link',
  ) as $item) {
    if (array_key_exists($item, $xml)) {
      $value = $xml->xpath($item);
      $project_info[$item] = (string) $value[0];
    }
  }

  $recommended_major = @$xml->xpath("/project/recommended_major");
  $recommended_major = empty($recommended_major) ? "" : (string) $recommended_major[0];
  $supported_majors = @$xml->xpath("/project/supported_majors");
  $supported_majors = empty($supported_majors) ? array() : array_flip(explode(',', (string) $supported_majors[0]));
  $releases_xml = @$xml->xpath("/project/releases/release[status='published']");
  $recommended_version = NULL;
  $latest_version = NULL;
  $releases = array();
  foreach ($releases_xml as $release) {
    $release_info = array();
    foreach (array(
      'name',
      'version',
      'tag',
      'version_major',
      'version_extra',
      'status',
      'release_link',
      'download_link',
      'date',
      'mdhash',
      'filesize',
    ) as $item) {
      if (array_key_exists($item, $release)) {
        $value = $release->xpath($item);
        $release_info[$item] = (string) $value[0];
      }
    }
    $statuses = array();
    if (array_key_exists($release_info['version_major'], $supported_majors)) {
      $statuses[] = "Supported";
      unset($supported_majors[$release_info['version_major']]);
    }
    if ($release_info['version_major'] == $recommended_major) {
      if (!isset($latest_version)) {
        $latest_version = $release_info['version'];
      }
      // The first stable version (no 'version extra') in the recommended major
      // is the recommended release
      if (empty($release_info['version_extra']) && (!isset($recommended_version))) {
        $statuses[] = "Recommended";
        $recommended_version = $release_info['version'];
      }
    }
    if (!empty($release_info['version_extra']) && ($release_info['version_extra'] == "dev")) {
      $statuses[] = "Development";
    }
    foreach ($release->xpath('terms/term/value') as $release_type) {
      // There are three kinds of release types that we recognize:
      // "Bug fixes", "New features" and "Security update".
      // We will add "Security" for security updates, and nothing
      // for the other kinds.
      if (strpos($release_type, "Security") !== FALSE) {
        $statuses[] = "Security";
      }
    }
    // Add to status whether the project is installed.
    if (isset($installed_projects[$project])) {
      if ($installed_projects[$project]['version'] == $release_info['version']) {
        $statuses[] = dt('Installed');
        $project_info['installed'] = $release_info['version'];
      }
    }
    $release_info['release_status'] = $statuses;
    $releases[$release_info['version']] = $release_info;
  }
  // If there is no -stable- release in the recommended major,
  // then take the latest verion in the recommended major to be
  // the recommended release.
  if (!isset($recommended_version) && isset($latest_version)) {
    $recommended_version = $latest_version;
    $releases[$recommended_version]['release_status'][] = "Recommended";
  }

  $project_info['releases'] = $releases;
  $project_info['recommended'] = $recommended_version;

  return $project_info;
}