function updatexml_parse_release

6.x updatexml.inc updatexml_parse_release($request, $xml, $restrict_to = '')
5.x updatexml.inc updatexml_parse_release($request, $xml, $restrict_to = '')

Pick most appropriate release from XML list or ask the user if no one fits.

Parameters

array $request: An array with project and version strings as returned by pm_parse_project_version().

resource $xml: A handle to the XML document.

String $restrict_to: One of: 'dev': Forces a -dev release. 'version': Forces a point release. '': No restriction (auto-selects latest recommended or supported release if requested release is not found). Default is ''.

2 calls to updatexml_parse_release()
releaseInfoCase::testReleaseXML in tests/releaseInfoTest.php
release_info_fetch in commands/pm/release_info/updatexml.inc
Obtain the most appropiate release for the requested project.

File

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

Code

function updatexml_parse_release($request, $xml, $restrict_to = '') {
  if (!empty($request['version'])) {
    $matches = array();
    // See if we only have a branch version.
    if (preg_match('/^\d+\.x-(\d+)$/', $request['version'], $matches)) {
      $xpath_releases = "/project/releases/release[status='published'][version_major=" . (string) $matches[] . "]";
      $releases = @$xml->xpath($xpath_releases);
    }
    else {
      // In some cases, the request only says something like '7.x-3.x' but the
      // version strings include '-dev' on the end, so we need to append that
      // here for the xpath to match below.
      if (substr($request['version'], -) == '.x') {
        $request['version'] .= '-dev';
      }
      $releases = $xml->xpath("/project/releases/release[status='published'][version='" . $request['version'] . "']");
      if (empty($releases)) {
        if (empty($restrict_to)) {
          drush_log(dt("Could not locate !project version !version, will try to download latest recommended or supported release.", array('!project' => $request['name'], '!version' => $request['version'])), 'warning');
        }
        else {
          drush_log(dt("Could not locate !project version !version.", array('!project' => $request['name'], '!version' => $request['version'])), 'warning');
          return FALSE;
        }
      }
    }
  }

  if ($restrict_to == 'dev') {
    $releases = @$xml->xpath("/project/releases/release[status='published'][version_extra='dev']");
    if (empty($releases)) {
      drush_print(dt('There is no development release for project !project.', array('!type' => $release_type, '!project' => $request['name'])));
      return FALSE;
    }
  }

  // If that did not work, we will get the first published release for the
  // recommended major version or fallback to other supported major versions.
  if (empty($releases)) {
    foreach (array('recommended_major', 'supported_majors') as $release_type) {
      if ($versions = $xml->xpath("/project/$release_type")) {
        $xpath = "/project/releases/release[status='published'][version_major=" . (string) $versions[] . "]";
        $releases = @$xml->xpath($xpath);
        if (!empty($releases)) {
          break;
        }
      }
    }
  }

  // If there are releases found, let's try first to fetch one with no
  // 'version_extra'. Otherwise, use all.
  if (!empty($releases)) {
    $stable_releases = array();
    foreach ($releases as $one_release) {
      if (!array_key_exists('version_extra', $one_release)) {
        $stable_releases[] = $one_release;
      }
    }
    if (!empty($stable_releases)) {
      $releases = $stable_releases;
    }
  }

  if (empty($releases)) {
    drush_print(dt('There are no releases for project !project.', array('!project' => $request['name'])));
    return FALSE;
  }

  // First published release is just the first value in $releases.
  return (array) $releases[];
}