function pm_parse_project_version

6.x pm.drush.inc pm_parse_project_version($requests)
3.x pm.drush.inc pm_parse_project_version($requests)
4.x pm.drush.inc pm_parse_project_version($requests)
5.x pm.drush.inc pm_parse_project_version($requests)

Parse out the project name and version and return as a structured array.

Parameters

$requests an array of project names:

8 calls to pm_parse_project_version()
drush_pm_download in commands/pm/download.pm.inc
Command callback. Download Drupal core or any project.
drush_pm_find_project_from_extension in commands/pm/pm.drush.inc
Helper function for pm-enable.
drush_pm_releasenotes in commands/pm/pm.drush.inc
Command callback. Show release notes for given project(s).
drush_pm_releases in commands/pm/pm.drush.inc
Command callback. Show available releases for given project(s).
drush_pm_updatestatus in commands/pm/updatestatus.pm.inc
Command callback. Displays update status info of installed projects.

... See full list

File

commands/pm/pm.drush.inc, line 1379
The drush Project Manager

Code

function pm_parse_project_version($requests) {
  $requestdata = array();
  $drupal_version_default = drush_drupal_major_version();
  if (!$drupal_version_default) {
    $drupal_version_default = drush_get_option('default-major', 7);
  }
  $drupal_version_default .= '.x';
  $drupal_bootstrap = drush_get_context('DRUSH_BOOTSTRAP_PHASE') > 0;
  foreach ($requests as $request) {
    $drupal_version = $drupal_version_default;
    $project_version = NULL;
    $version = NULL;
    $project = $request;
    // project-HEAD or project-5.x-1.0-beta
    // '5.x-' is optional, as is '-beta'
    preg_match('/-+(HEAD|(?:(\d+\.x)-+)?(\d+\.[\dx]+.*))$/', $request, $matches);
    if (isset($matches[1])) {
      // The project is whatever we have prior to the version part of the request.
      $project = trim(substr($request, 0, strlen($request) - strlen($matches[0])), ' -');

      if ($matches[1] == 'HEAD' || $matches[2] == 'HEAD') {
        drush_log('DRUSH_PM_HEAD', 'Can\'t download HEAD releases because Drupal.org project information only provides for numbered release nodes.', 'warning');
        continue;
      }
      if (!empty($matches[2])) {
        // We have a specified Drupal core version.
        $drupal_version = trim($matches[2], '-.');
      }
      if (!empty($matches[3])) {
        if (!$drupal_bootstrap && empty($matches[2]) && $project != 'drupal') {
          // We are not working on a bootstrapped site, and the project is not Drupal itself,
          // so we assume this value is the Drupal core version and we want the stable project.
          $drupal_version = trim($matches[3], '-.');
        }
        else {
          // We are working on a bootstrapped site, or the user specified a Drupal version,
          // so this value must be a specified project version.
          $project_version = trim($matches[3], '-.');
          if (substr($project_version, -1, 1) == 'x') {
            // If a dev branch was requested, we add a -dev suffix.
            $project_version .= '-dev';
          }
        }
      }
    }
    // special checking for 'drupal-VERSION', == drupal latest stable release
    elseif ((substr($request, 0, 7) == 'drupal-') && (is_numeric(substr($request, 7)))) {
      $project = 'drupal';
      $drupal_version = substr($request, 7) . '.x';
      $project_version = $version;
    }
    if ($project_version) {
      if ($project == 'drupal') {
        // For project Drupal, ensure the major version branch is correct, so
        // we can locate the requested or stable release for that branch.
        $project_version_array = explode('.', $project_version);
        $drupal_version = $project_version_array[0] . '.x';
        // We use the project version only, since it is core.
        $version = $project_version;
      }
      else {
        // For regular projects the version string includes the Drupal core version.
        $version = $drupal_version . '-' . $project_version;
      }
    }
    $requestdata[$project] = array(
      'name' => $project,
      'version' => $version,
      'drupal_version' => $drupal_version,
      'project_version' => $project_version,
    );
  }
  return $requestdata;
}