drush_pm_download
Drupal 7 drush_pm_download()
Command callback. Download Drupal core or any project.
File
- sites/
all/ modules/ drush/ commands/ pm/ download.pm.inc, line 77
Code
function drush_pm_download() {
if (!$requests = pm_parse_arguments(func_get_args(), FALSE)) {
$requests = array('drupal');
}
// Parse out project name and version.
$requests = pm_parse_project_version($requests);
// Get release history for each request and download the project.
$source = drush_get_option('source', RELEASE_INFO_DEFAULT_URL);
$restrict_to = drush_get_option('dev', FALSE) ? 'dev' : '';
$select = drush_get_option('select', 'auto');
$all = drush_get_option('all', FALSE);
foreach ($requests as $name => $request) {
$request['status url'] = $source;
$release = release_info_fetch($request, $restrict_to, $select, $all);
if ($release == FALSE) {
continue;
}
// Determine the name of the directory that will contain the project.
// We face here all the asymetries to make it smooth for package handlers.
// For Drupal core: --drupal-project-rename or drupal-x.y
if (($request['project_type'] == 'core') ||
(($request['project_type'] == 'profile') && (drush_get_option('variant', 'full') == 'full'))) {
// Avoid downloading core into existing core.
if (drush_get_context('DRUSH_BOOTSTRAP_PHASE') >= DRUSH_BOOTSTRAP_DRUPAL_ROOT) {
if (strpos(realpath(drush_get_option('destination')), DRUPAL_ROOT) !== FALSE) {
return drush_set_error('DRUSH_PM_DOWNLOAD_TRANSLATIONS_FORBIDDEN', dt('It\'s forbidden to download !project core into an existing core.', array('!project' => $request['name'])));
}
}
if ($rename = drush_get_option('drupal-project-rename', FALSE)) {
if ($rename === TRUE) {
$request['project_dir'] = $request['name'];
}
else {
$request['project_dir'] = $rename;
}
}
else {
// Set to drupal-x.y, the expected name for .tar.gz contents.
// Explicitly needed for cvs package handler.
$request['project_dir'] = strtolower(strtr($release['name'], ' ', '-'));
}
}
// For the other project types we want the project name. Including core
// variant for profiles. Note those come with drupal-x.y in the .tar.gz.
else {
$request['project_dir'] = $request['name'];
}
// Download the project to a temporary location.
$request['base_project_path'] = drush_tempdir();
$request['full_project_path'] = $request['base_project_path'] . '/' . $request['project_dir'];
drush_log(dt('Downloading project !name to !dir ...', array('!name' => $request['name'], '!dir' => $request['base_project_path'])));
if (!package_handler_download_project($request, $release)) {
drush_log(dt('Error downloading !name', array('!name' => $request['name']), 'error'));
continue;
}
// Determine the install location for the project. User provided
// --destination has preference.
$destination = drush_get_option('destination');
if (!empty($destination)) {
$request['project_install_location'] = realpath($destination);
}
else {
$request['project_install_location'] = _pm_download_destination($request['project_type']);
}
// If user did not provide --destination, then call the
// download-destination-alter hook to give the chance to any commandfiles
// to adjust the install location or abort it.
if (empty($destination)) {
$result = drush_command_invoke_all_ref('drush_pm_download_destination_alter', $request, $release);
if (array_search(FALSE, $result, TRUE) !== FALSE) {
return FALSE;
}
}
// Load version control engine and detect if (the parent directory of) the
// project install location is under a vcs.
if (!$version_control = drush_pm_include_version_control($request['project_install_location'])) {
continue;
}
$request['project_install_location'] .= '/' . $request['project_dir'];
if ($version_control->engine == 'backup') {
// Check if install location already exists.
if (is_dir($request['project_install_location'])) {
if (drush_confirm(dt('Install location !location already exists. Do you want to overwrite it?', array('!location' => $request['project_install_location'])))) {
drush_delete_dir($request['project_install_location'], TRUE);
}
else {
drush_log(dt("Skip installation of !project to !dest.", array('!project' => $request['name'], '!dest' => $request['project_install_location'])), 'warning');
continue;
}
}
}
else {
// Find and unlink all files but the ones in the vcs control directories.
$skip_list = array('.', '..');
$skip_list = array_merge($skip_list, drush_version_control_reserved_files());
drush_scan_directory($request['project_install_location'], '/.*/', $skip_list, 'unlink', TRUE, 'filename', 0, TRUE);
}
// Copy the project to the install location.
if (drush_op('_drush_recursive_copy', $request['full_project_path'], $request['project_install_location'])) {
drush_log(dt("Project !project (!version) downloaded to !dest.", array('!project' => $request['name'], '!version' => $release['version'], '!dest' => $request['project_install_location'])), 'success');
$request['base_project_path'] = basename($request['project_install_location']);
$request['full_project_path'] = $request['project_install_location'];
if ($request['project_install_location'] == DRUSH_BASE_PATH) {
drush_log(dt("Drush successfully updated to version !version.", array('!version' => $release['version'])), 'success');
}
// If the version control engine is a proper vcs we also need to remove
// orphan directories.
if ($version_control->engine != 'backup') {
$empty_dirs = drush_find_empty_directories($request['full_project_path'], $version_control->reserved_files());
foreach ($empty_dirs as $empty_dir) {
// Some VCS files are read-only on Windows (e.g., .svn/entries).
drush_delete_dir($empty_dir, TRUE);
}
}
// Post download actions.
package_handler_post_download($request, $release);
drush_command_invoke_all('drush_pm_post_download', $request, $release);
$version_control->post_download($request);
// Print release notes if --notes option is set.
if (drush_get_option('notes') && !drush_get_context('DRUSH_PIPE')) {
release_info_print_releasenotes(array($name . '-' . $release['version']), FALSE);
}
// Inform the user about available modules a/o themes in the downloaded project.
drush_pm_extensions_in_project($request);
}
else {
// We don't `return` here in order to proceed with downloading additional projects.
drush_set_error('DRUSH_PM_DOWNLOAD_FAILED', dt("Project !project (!version) could not be downloaded to !dest.", array('!project' => $request['name'], '!version' => $release['version'], '!dest' => $request['project_install_location'])));
}
}
}

