? test.php
? includes/table.inc
Index: commands/core/upgrade.drush.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/drush/commands/core/upgrade.drush.inc,v
retrieving revision 1.29
diff -u -p -r1.29 upgrade.drush.inc
--- commands/core/upgrade.drush.inc	8 Feb 2011 01:21:30 -0000	1.29
+++ commands/core/upgrade.drush.inc	23 Feb 2011 14:16:19 -0000
@@ -32,6 +32,8 @@ function upgrade_drush_command() {
       'no-cache' => 'Transfer a fresh database from source site. Otherwise, DB dump is re-used for 24 hours.',
       'core-only' => 'Stop after upgrading Drupal core; do not download and enable new versions of the site\'s modules.',
       'force-sites-default' => 'Forces settings.php to be written in sites/default folder, even if source settings.php is not.',
+      'replace' => 'Replace target if it already exists.  Default is to prompt.',
+      'reuse' => 'Reuse target if it already exists.  Default is to prompt.',
     ),
     'aliases' => array('sup'),
     'topics' => array('docs-aliases'),
@@ -103,30 +105,37 @@ function drush_upgrade_site_upgrade($tar
   // CONFIRM:  Ask the user before overwriting an exsiting site
 
   // Check to see what we should do if the target Drupal folder already exists
-  $selection = 'replace';
-  if (file_exists($destination_core)) {
-    $options = array(
-      'replace' => dt("Delete the existing site and start over"),
-      'reuse' => dt("Re-use the existing site, skipping the Drupal download and updatedb steps"),
-    );
-    $selection = drush_choice($options, dt("Drupal site already exists at !root.  Would you like to:", array('!root' => $destination_core)));
-    if (!$selection) {
-      return drush_user_abort();
+  $options = array(
+    'replace' => dt("Delete the existing site and start over"),
+    'reuse' => dt("Re-use the existing site, skipping the Drupal download and updatedb steps"),
+  );
+  foreach ($options as $option) {
+    if (drush_get_option($option, FALSE)) {
+      $selection = $option;
     }
   }
-
+  if (!isset($selection)) {
+    if (file_exists($destination_core)) {
+      $selection = drush_choice($options, dt("Drupal site already exists at !root.  Would you like to:", array('!root' => $destination_core)));
+      if (!$selection) {
+        return drush_user_abort();
+      }
+    }
+  }
+  
   // STEP 1:  Download the next major version of Drupal
 
   if ($selection == 'replace') {
     // Fetch target core and place as per target alias root.
     drush_set_option('destination', dirname($destination_core));
     drush_set_option('drupal-project-rename', basename($destination_core));
+    drush_set_option('drupal-version-major', $target_version);
 
     // No need for version control in this command.
     drush_set_option('version-control', 'backup');
 
     // TODO: get releases other than dev snapshot.
-    drush_pm_download('drupal-'. $target_version . '.x');
+    drush_pm_download('drupal-'. $target_version);
     if (drush_get_error()) return FALSE; // Early exit if we see an error.
 
     // Check and see if there is a Drupal site at the target
@@ -156,7 +165,17 @@ function drush_upgrade_site_upgrade($tar
 
     // Append new $db_url with new DB name in target's settings.php.
     drush_upgrade_fix_db_url($target_alias, $settings_destination);
+  }
+  else {
+    // Move sites/all/modules and $conf_path()/modules out of the way
+    // so that updatedb can be run on core only
+    if (_drush_upgrade_preserve_modules($destination_core) === FALSE) {
+      return FALSE;
+    }
+  }
 
+  // 'if (TRUE)' to be removed prior to commit; this is here only to reduce the size of the diff.
+  if (TRUE) {
     // Copy source database to target database. The source DB is not changed.
     // Always set 'common' at minimum. Sites that want other can create other key in drushrc.php.
     if (!drush_get_option('structure-tables-key')) {
@@ -213,6 +232,9 @@ function drush_upgrade_site_upgrade($tar
     drush_log(dt('updatedb complete for Drupal core'), 'ok');
   }
 
+  // If we moved our modules out of the way, bring them back now.
+  _drush_upgrade_restore_preserved_modules();
+
   // STEP 3: Download and re-enable the non-core modules
 
   if (!empty($non_core_extensions) && !drush_get_option('core-only')) {
@@ -220,6 +242,8 @@ function drush_upgrade_site_upgrade($tar
     // bootstrapped to the target site.
     $result = drush_invoke_sitealias_args($target_alias, 'site-upgrade-modules', $non_core_extensions, array('#interactive' => TRUE));
   }
+  
+  return $result;
 }
 
 /**
@@ -232,12 +256,26 @@ function drush_upgrade_site_upgrade($tar
 function drush_upgrade_site_upgrade_modules() {
   $non_core_extensions = func_get_args();
 
+  // Make a list of all of the extensions to download.  We will
+  // download everything in the non-core extension list, but we
+  // will skip projects that already exist.
+  $project_download_list = array();
+  $extensions = drush_pm_get_extensions();
+  foreach ($non_core_extensions as $extension_name) {
+    if (array_key_exists($extension_name, $extensions)) {
+      $project = $extensions[$extension_name]->info['project'];
+      if (!is_dir(DRUPAL_ROOT . '/sites/all/modules/' . $project) && is_dir(DRUPAL_ROOT . conf_path() . '/modules/' . $project)) {
+        $project_download_list[$project][] = $extension_name;
+      }
+    }
+  }
+  
   // Download our non-core extensions.  We do not force --yes here so that
   // pm-download can prompt for the version to download if there is no
   // recommended release available for the upgrade.
-  drush_log(dt('Download modules: !modules', array('!modules' => implode(' ', $non_core_extensions))), 'ok');
+  drush_log(dt('Download projects: !projects', array('!projects' => implode(' ', array_keys($project_download_list)))), 'ok');
   drush_set_option('destination', NULL);
-  call_user_func_array('drush_pm_download', $non_core_extensions);
+  call_user_func_array('drush_pm_download', array_keys($project_download_list));
 
   // Run updatedb to update all of the non-core extensions
   drush_log(dt('About to perform updatedb for extensions'), 'ok');
@@ -290,3 +328,55 @@ function drush_upgrade_fix_db_url(&$targ
   // Also append the new configuration options to the end of settings.php
   drush_op('file_put_contents', $settings_destination, $append, FILE_APPEND);
 }
+
+/**
+ * Rollback function: restore our modules if updatedb fails
+ */
+function drush_upgrade_site_upgrade_rollback($target_key) {
+  _drush_upgrade_restore_preserved_modules();
+}
+
+/**
+ * Preserve existing modules.  Move them out of the way prior
+ * to updatedb of Drupal core.  We will move them back afterwards.
+ */
+function _drush_upgrade_preserve_modules($destination_core) {
+  $modules_preserve['root'] = $destination_core;
+  $modules_preserve['list'] = array();
+  
+  $moduledir_list = array(
+    'sites_all_modules' => $destination_core . '/sites/all/modules',
+    'sites_conf_path_modules' => $destination_core . conf_path() . '/modules',
+  );
+  
+  foreach ($moduledir_list as $moduledir_name => $moduledir) {
+    if (is_dir($moduledir)) {
+      $preserved_moduledir = drush_tempnam($moduledir_name, dirname($moduledir));
+      $result = drush_move_dir($moduledir, $preserved_moduledir, TRUE);
+      if ($result) {
+        $modules_preserve['list'][$moduledir] = $preserved_moduledir;
+        drush_log(dt('Move !src to !dest prior to updatedb on Drupal core.', array('!src' => $moduledir, '!dest' => $preserved_moduledir)), 'ok');
+      }
+      else {
+        return drush_set_error('DRUSH_MODULE_PRESERVE_FAILED', dt('Failed to move !src to !dest.', array('!src' => $moduledir, '!dest' => $preserved_moduledir)));
+      }
+    }
+  }
+  
+  drush_set_context('DRUSH_MODULES_PRESERVE', $modules_preserve);
+  return TRUE;
+}
+
+/**
+ * Restore modules that were preserved by _drush_upgrade_preserve_modules
+ */
+function _drush_upgrade_restore_preserved_modules() {
+  $modules_preserve = drush_get_context('DRUSH_MODULES_PRESERVE', array());
+  
+  if (!empty($modules_preserve) && array_key_exists('list', $modules_preserve)) {
+    foreach ($modules_preserve['list'] as $moduledir => $preserved_moduledir) {
+      drush_move_dir($preserved_moduledir, $moduledir, TRUE);
+    }
+  }
+  drush_set_context('DRUSH_MODULES_PRESERVE', array());
+}
Index: commands/pm/pm.drush.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/drush/commands/pm/pm.drush.inc,v
retrieving revision 1.218
diff -u -p -r1.218 pm.drush.inc
--- commands/pm/pm.drush.inc	21 Feb 2011 18:38:07 -0000	1.218
+++ commands/pm/pm.drush.inc	23 Feb 2011 14:16:21 -0000
@@ -222,6 +222,7 @@ function pm_drush_command() {
       'drush dl' => 'Download latest recommended release of Drupal core.',
       'drush dl drupal' => 'Same as `drush dl`.',
       'drush dl drupal-7.x' => 'Download latest 7.x development version of Drupal core.',
+      'drush dl drupal --drupal-version-major=6' => 'Download latest recommended release of Drupal 6.x.',
       'drush dl cck zen' => 'Download latest versions of CCK and Zen projects.',
       'drush dl og-1.3' => 'Download a specfic version of Organic groups module for my version of Drupal.',
       'drush dl diff-6.x-2.x' => 'Download a specific development branch of diff module for a specific Drupal version.',
@@ -241,6 +242,8 @@ function pm_drush_command() {
       'select' => "Select the version to download interactively from a list of available releases.",
       'all' => "Useful only with --select; shows all available releases instead of a short list of recent releases.",
       'drupal-project-rename' => 'Alternate name for "drupal-x.y" directory when downloading Drupal project. Defaults to "drupal".',
+      'drupal-version-major' => 'Specify the major version of Drupal to download.  Defaults to "7".',
+      'default-major' => 'Specify the default major version of modules to download when there is no bootstrapped Drupal site.  Defaults to "7".',
       'pipe' => 'Returns a list of the names of the extensions (modules and themes) contained in the downloaded projects.',
     ),
     'bootstrap' => DRUSH_BOOTSTRAP_MAX,
@@ -1790,13 +1793,19 @@ function pm_parse_arguments($args, $dash
  */
 function pm_parse_project_version($requests) {
   $requestdata = array();
-  $drupal_version_default = drush_get_context('DRUSH_DRUPAL_MAJOR_VERSION', 7) . '.x';
+  $drupal_version_default = drush_get_context('DRUSH_DRUPAL_MAJOR_VERSION', drush_get_option('default-major',7)) . '.x';
   // bootstrap_bootstrap is a temporary hack. You can't currently download a 7.x
   // module after bootstrapping a 6.x site. This is needed by site-upgrade.
   // Related to http://drupal.org/node/463110.
   $drupal_bootstrap = drush_get_option('bootstrap_cancel') ? !drush_get_option('bootstrap_cancel') : drush_get_context('DRUSH_BOOTSTRAP_PHASE') > 0;
   foreach($requests as $request) {
-    $drupal_version = $drupal_version_default;
+    $drupal_version = drush_get_option($request . '-version-major');
+    if (!isset($drupal_version)) {
+      $drupal_version = $drupal_version_default;
+    }
+    else {
+      $drupal_version .= '.x';
+    }
     $project_version = NULL;
     $version = NULL;
     $project = $request;
