function drush_upgrade_fix_db_url

3.x upgrade.drush.inc drush_upgrade_fix_db_url($target_alias, $settings_destination)
4.x upgrade.drush.inc drush_upgrade_fix_db_url(&$target_alias, $settings_destination)

Replace db_url with DB name from target. updatedb will later append a DBTNG compatible version.

1 call to drush_upgrade_fix_db_url()
drush_upgrade_copy_settings in commands/core/upgrade.drush.inc
Copy the settings.php file from the source site to the target site, and fix it up so that it will have its own database settings.

File

commands/core/upgrade.drush.inc, line 616
Refine your Drupal major version upgrade.

Code

function drush_upgrade_fix_db_url(&$target_alias, $settings_destination) {
  $old_url = $GLOBALS['db_url'];
  if (is_array($old_url)) {
    $old_url = $old_url['default'];
  }
  $old_databases = $GLOBALS['databases'];
  if (empty($old_databases)) {
    $old_databases = drush_sitealias_convert_db_from_db_url($old_url);
  }

  $target_alias_databases = sitealias_get_databases_from_record($target_alias);
  $database_name = $target_alias_databases['default']['default']['database'];
  if (empty($database_name)) {
    $database_name = str_replace("@", "", $target_alias['name']) . "db";
    drush_log(dt("No database name specified; defaulting to !dbname", array("!dbname" => $database_name)), 'notice');
  }

  $append = "\n# Added by drush site-upgrade.";
  if (drush_drupal_major_version() <= 6) {
    $new_url = substr($old_url, 0, strrpos(trim($old_url), '/')) . '/' . $database_name;
    $append .= "\n" . '$db_url = \'' . $new_url . '\';';
    $databases = drush_sitealias_convert_db_from_db_url($new_url);
  }
  else {
    $databases = $GLOBALS['databases'];
    $databases['default']['default']['database'] = $target_alias_databases['default']['default']['database'];
    $append .= "\n" . '$databases = ' . var_export($databases, TRUE) . ';';
  }
  // Caching the database record in the alias record allows sql-sync to work
  // before updatedb is called. updatedb is what converts from a db_url to a
  // DBTNG array; this conversion is required by sql-sync.
  drush_sitealias_cache_db_settings($target_alias, $databases);

  // Also append the new configuration options to the end of settings.php.
  drush_op('file_put_contents', $settings_destination, $append, FILE_APPEND);
}