function pm_drush_pm_download_destination_alter

8.0.x download.pm.inc pm_drush_pm_download_destination_alter(&$request, $release)
6.x download.pm.inc pm_drush_pm_download_destination_alter(&$project, $release)
7.x download.pm.inc pm_drush_pm_download_destination_alter(&$request, $release)
4.x pm.drush.inc pm_drush_pm_download_destination_alter(&$project, $release)
5.x download.pm.inc pm_drush_pm_download_destination_alter(&$project, $release)
master download.pm.inc pm_drush_pm_download_destination_alter(&$request, $release)

Implementation of hook_drush_pm_download_destination_alter().

Built-in download-destination-alter hook. This particular version of the hook will move modules that contain only drush commands to /usr/share/drush/commands if it exists, or $HOME/.drush if the site-wide location does not exist.

File

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

Code

function pm_drush_pm_download_destination_alter(&$project, $release) {
  // A module is a pure drush command if it has no .module and contain
  // .drush.inc files.
  if ($project['project_type'] == 'module') {
    $module_files = drush_scan_directory($project['full_project_path'], '/.*\.module/');
    if (empty($module_files)) {
      if ($project['name'] == 'drush') {
        // $project['version'] is empty here, so compose the version from the $release structure.
        $drush_release_version = $release['version_major'] . "." . $release['version_patch'] . (empty($release['version_extra']) ? '' : ('-' . $release['version_extra']));
        if (($project['project_install_location'] != DRUSH_BASE_PATH) && ($release['version_major'] >= '4')) {
          $backup_dir = drush_preflight_backup_dir();
          if (drush_confirm(dt('Would you like to back up your current drush version !currentversion to !backup and replace it with drush !version?', array('!version' => $drush_release_version, '!backup' => $backup_dir, '!currentversion' => DRUSH_VERSION)))) {
            $project['project_install_location'] = DRUSH_BASE_PATH;
          }
          else {
            // If we are called via 'drush self-update', then "no" means "do nothing".
            // If we are called via 'drush dl drush', then "no" means "download to cwd".
            if (drush_get_option('self-update', FALSE)) {
              return drush_user_cancel();
            }
          }
        }
      }
      else {
        $drush_command_files = drush_scan_directory($project['full_project_path'], '/.*\.drush.inc/');
        if (!empty($drush_command_files)) {
          $install_dir = drush_get_context('SHARE_PREFIX', '/usr') . '/share/drush/commands';
          if (!is_dir($install_dir) || !is_writable($install_dir)) {
            $install_dir = drush_server_home() . '/.drush';
          }
          // Make the .drush dir if it does not already exist.
          if (!is_dir($install_dir)) {
            drush_mkdir($install_dir);
          }
          // Change the location if the mkdir worked.
          if (is_dir($install_dir)) {
            $project['project_install_location'] = $install_dir;
          }
        }
      }
    }
  }
}