function drush_pm_download

8.0.x download.pm.inc drush_pm_download()
6.x download.pm.inc drush_pm_download()
7.x download.pm.inc drush_pm_download()
3.x pm.drush.inc drush_pm_download()
4.x pm.drush.inc drush_pm_download()
5.x download.pm.inc drush_pm_download()
master download.pm.inc drush_pm_download()

Command callback. Download Drupal core or any project.

1 call to drush_pm_download()
drush_upgrade_site_upgrade in commands/core/upgrade.drush.inc
A drush command callback.

File

commands/pm/pm.drush.inc, line 1292
The drush Package Manager

Code

function drush_pm_download() {
  // Bootstrap to the highest level possible.
  drush_bootstrap_max();

  drush_include_engine('package_handler', drush_get_option('package-handler', 'wget'));

  if (!$requests = func_get_args()) {
    $requests = array('drupal');
  }

  // Parse out project name and version
  $requests = pm_parse_project_version($requests);

  $project_types = pm_project_types();
  $project_types_xpath = '(value="' . implode('" or value="', $project_types) . '")';
  foreach ($requests as $name => $request) {
    // Don't rely on UPDATE_DEFAULT_URL since we are not fully bootstrapped.
    $url = drush_get_option('source', 'http://updates.drupal.org/release-history') . '/' . $request['name'] . '/' . $request['drupal_version'];
    drush_log('Downloading release history from ' . $url);
    // A simple download, which is never available via CVS.
    // Some hosts have allow_url_fopen disabled.
    if (!$xml = @simplexml_load_file($url)) {
      if (!drush_shell_exec("wget $url")) {
        drush_shell_exec("curl -O $url");
      }
      // Get the filename...
      $filename = explode('/', $url);
      $filename = array_pop($filename);
      $xml = simplexml_load_file($filename);
      drush_op('unlink', $filename);
    }

    if ($xml) {
      if ($error = $xml->xpath('/error')) {
        drush_set_error('DRUSH_PM_COULD_NOT_LOAD_UPDATE_FILE', $error[0]);
      }
      else {
        // Try to get the specified release.
        if (!empty($request['version'])) {
          $releases = $xml->xpath("/project/releases/release[status='published'][version='" . $request['version'] . "']");
          if (empty($releases)) {
            drush_log(dt("Could not locate specified project version, downloading latest stable version"), 'notice');
          }
        }
        // If that did not work, get the first published release for the recommended major version.
        if (empty($releases)) {
          if ($recommended_major = $xml->xpath("/project/recommended_major")) {
            $xpath_releases = "/project/releases/release[status='published'][version_major=" . (string) $recommended_major[0] . "]";
            $releases = @$xml->xpath($xpath_releases);
          }
        }

        // If there are recommended releases (no 'version_extra' elements),
        // then use only recommended releases.  Otherwise, use all; in
        // this case, the recommended release defaults to the latest published
        // release with the right recommended major version number.
        $recommended_releases = array();
        if (!empty($releases)) {
          foreach ($releases as $one_release) {
            if (!array_key_exists('version_extra', $one_release)) {
              $recommended_releases[] = $one_release;
            }
          }
        }

        if (!empty($recommended_releases)) {
          $releases = $recommended_releases;
        }

        if (empty($releases)) {
          drush_log(dt('There is no *recommended* release for project !project on Drupal !drupal_version. Ask the maintainer to review http://drupal.org/node/197584 and create/recommend a release in order to be compatible with drush and the drupal.org security broadcast system. A recommended development snapshot release is sufficient. Alternatively, run pm-releases command and explicity pm-download any non-recommended release that might be available.', array('!drupal_version' => $request['drupal_version'], '!project' => $request['name'])), 'ok');
          continue;
        }

        // Profiles have 3 variants for a given real relase. Admin can specify using option.
        // Depends on a fixed order of variations in releases list.
        // Usually,  the first release is chosen.
        $variations = array('core', 'no-core', 'make');
        $variant = drush_get_option('variant', 'core');
        $release = (array) $releases[array_search($variant, $variations)];

        // Determine what type of project we have, so we know where to put it.
        $release['type'] = 'module';

        if ($types = $xml->xpath('/project/terms/term[name="Projects" and ' . $project_types_xpath . ']')) {
          $release['type'] = array_search($types[0]->value, $project_types);
        }

        // Create basic project array.
        $project = $request;
        if ($project['base_project_path'] = pm_dl_destination($release['type'])) {
          $project['full_project_path'] = $project['base_project_path'] . $request['name'];
          $project['project_type'] = $release['type'];
          if (!$version_control = drush_pm_include_version_control($project['base_project_path'])) {
            return FALSE;
          }
          if (package_handler_install_project($project, $release)) {
            // If the --destination option was not specified, then
            // allow commandfiles that implement the adjust-download-destination
            // hook to pick a new default location for the project.
            if (drush_get_option('destination', FALSE) === FALSE) {
              drush_pm_relocate_project($project, $release);
            }
            drush_log(dt("Project !project (!version) downloaded to !dest.", array('!project' => $request['name'], '!version' => $release['version'], '!dest' => $project['full_project_path'])), 'success');
            drush_command_invoke_all('drush_pm_post_download', $project, $release);
            $version_control->post_download($project);
          }
        }
      }
    }
    else {
      // We are not getting here since drupal.org always serves an XML response.
      drush_set_error('DRUSH_PM_DOWNLOAD_FAILED', dt('Could not download project status information from !url', array('!url' => $url)));
    }

    unset($error, $release, $releases, $types);
  }
}