function package_handler_download_project

8.0.x wget.inc package_handler_download_project(&$request, $release)
8.0.x git_drupalorg.inc package_handler_download_project(&$request, $release)
6.x wget.inc package_handler_download_project(&$request, $release)
6.x git_drupalorg.inc package_handler_download_project(&$request, $release)
7.x wget.inc package_handler_download_project(&$request, $release)
7.x git_drupalorg.inc package_handler_download_project(&$request, $release)
4.x wget.inc package_handler_download_project(&$request, $release)
4.x git_drupalorg.inc package_handler_download_project(&$request, $release)
4.x cvs.inc package_handler_download_project(&$project, $release)
5.x wget.inc package_handler_download_project(&$request, $release)
5.x git_drupalorg.inc package_handler_download_project(&$request, $release)
master wget.inc package_handler_download_project(&$request, $release)
master git_drupalorg.inc package_handler_download_project(&$request, $release)

Download a project.

Parameters

$request Array with information on the request to download.:

$release The release details array from drupal.org.:

2 calls to package_handler_download_project()
drush_pm_download in commands/pm/download.pm.inc
Command callback. Download Drupal core or any project.
package_handler_update_project in commands/pm/package_handler/wget.inc
This is an alias of the download function, since they are identical

File

commands/pm/package_handler/wget.inc, line 37
Drush PM Wget extension

Code

function package_handler_download_project(&$request, $release) {
  // Install profiles come in several variants. User may specify which one she wants.
  if ($request['project_type'] == 'profile') {
    if (!empty($release['files'])) {
      // @todo Use xpath to get the right file url.
      $files = $release['files'];
      foreach ($files as $key => $file) {
        if ((string) $file->variant == drush_get_option('variant', 'full') && (string) $file->archive_type == 'tar.gz') {
          $release['download_link'] = (string) $file->url;
          $release['mdhash'] = (string) $file->md5;
          $release['date'] = (string) $file->filedate;
          break;
        }
      }
    }
  }

  // Add <date> to URL so it is part of the cache key . Dev snapshots can then be cached forever.
  if (strpos($release['download_link'], '-dev') !== FALSE) {
    $release['download_link'] .= '?date=' . $release['date'];
  }
  $filename = basename($release['download_link']);
  // On Windows file name cannot contain '?'
  // See http://drupal.org/node/1782444
  if (drush_is_windows()) {
    $filename = str_replace('?', '_', $filename);
  }
  $cache_duration =  * ;
  $path = drush_download_file($release['download_link'], $request['base_project_path'] . DIRECTORY_SEPARATOR . $filename, $cache_duration);
  if ($path || drush_get_context('DRUSH_SIMULATE')) {
    drush_log("Downloading " . $filename . " was successful.");
  }
  else {
    return drush_set_error('DRUSH_PM_DOWNLOAD_FAILED', 'Unable to download ' . $filename . ' to ' . $request['base_project_path'] . ' from ' . $release['download_link']);
  }

  // Check Md5 hash.
  if (drush_op('md5_file', $path) != $release['mdhash'] && !drush_get_context('DRUSH_SIMULATE')) {
    drush_set_error('DRUSH_PM_FILE_CORRUPT', "File $filename is corrupt (wrong md5 checksum).");
    drush_delete_dir($path, TRUE);
    return FALSE;
  }
  else {
    drush_log("Md5 checksum of $filename verified.");
  }

  // Extract the tarball.
  $file_list = drush_tarball_extract($path, $request['base_project_path'], TRUE);

  // Move untarred directory to project_dir, if distinct.
  if (($request['project_type'] == 'core') || (($request['project_type'] == 'profile') && (drush_get_option('variant', 'full') == 'full'))) {
    // Obtain the dodgy project_dir for drupal core.
    $project_dir = drush_trim_path($file_list[]);
    if ($request['project_dir'] != $project_dir) {
      $path = $request['base_project_path'];
      drush_move_dir($path . '/' . $project_dir, $path . '/' . $request['project_dir']);
    }
  }

  return TRUE;
}