Currently the database credentials are only set on the creation and it's stored encrypted in migrate_group (source_database serialized key).
There should be some possibility to change that settings.
Any suggestions?

Notes:
- I could see the database creds in protected variables when run: drush eval "print_r( MigrationBase::getInstance('machine_name'));"
- encrypted arguments can be accessed by: drush sqlq "SELECT arguments FROM migrate_group"

CommentFileSizeAuthor
#8 example_migrate.drush_.inc_.txt2.94 KBkenorb

Comments

kenorb’s picture

Issue summary: View changes
kenorb’s picture

Issue summary: View changes
kenorb’s picture

As workaround, I did the following script:

$row = db_select('migrate_group', 'g')->fields('g', array('arguments'))->condition('name', 'machine_name')->execute()->fetchObject();
$arguments = MigrationBase::decryptArguments(unserialize($row->arguments));
unset($arguments['encrypted_arguments']);
print serialize($arguments);

and changed the arguments in the db to not include encrypted_arguments.
In this case, I could keep track of database credentials across the environments (easier to change).

kenorb’s picture

Project: Migrate » Drupal-to-Drupal data migration
Version: 7.x-2.x-dev » 7.x-2.1-beta1
kenorb’s picture

mikeryan’s picture

Category: Support request » Feature request

It's true, there's no simple way to update the credentials for a UI-based migration - you can go back through the wizard again filling in the new credentials and making all the same selections otherwise, and the credentials will be updated, but that's admittedly a pain.

The simplest short-term solution would be for migrate_d2d to not do an addConnectionInfo() if the connection is already defined - i.e., you could override the database in settings.php (as the referenced issue, misplaced in the Migrate issue queue, suggests). I'll address this.

kenorb’s picture

I did some workaround, where I've configured Drupal 6 credentials and put into settings file next to standard default:

$databases['migrate']['default'] = array(
  'driver' => 'mysql',
  'database' => 'drupal6',
  'username' => 'root',
  'password' => 'root',
  'host' => 'localhost',
  'prefix' => '',
);

See: https://drupal.org/node/1810122 for further example.

And then I've defined the following function which updates the db access based on above db credentials from settings file:

/**
 * Implements hook_install().
 */
function foo_migrate_install() {

  $connection6 = Database::getConnection('default', 'migrate');
  $connection7 = Database::getConnection('default', 'default');
  $info6       = $connection6->getConnectionOptions();


  // Updating migrate group source connection settings.
  $row = $connection7->select('migrate_group', 'mg')
    ->fields('mg')
    // ->condition('name', 'My_Group')
    ->execute()
    ->fetchObject();

  $arguments = unserialize($row->arguments);
  $arguments = MigrationBase::decryptArguments($arguments);

  $arguments['source_database']['driver']    = $info6['driver'];
  $arguments['source_database']['database']  = $info6['database'];
  $arguments['source_database']['username']  = $info6['username'];
  $arguments['source_database']['password']  = $info6['password'];
  $arguments['source_database']['db_prefix'] = $info6['prefix']['default'];
  $arguments['source_database']['port']      = $info6['port'];
  $arguments['source_database']['host']      = $info6['host'];

  $connection7->update('migrate_group')
    ->fields(array(
      'arguments' => serialize(MigrationBase::encryptArguments($arguments)),
    ))
    ->execute();
}

Also I've defined the following drush alias:

migrate-refresh   :  !drush eval "module_load_include('install', 'foo_migrate'); foo_migrate_install();" && drush migrate-register 

So I've to run:

drush migrate-refresh

each time when I've sql-sync db from other environment and I want to refresh and use my local migrate credentials (which could be different).

kenorb’s picture

StatusFileSize
new2.94 KB

Please check the following drush example file which implements drush command migrate-refresh-db similar as described in #7.

mscipioni’s picture

A workaround that worked for me is I backed up my database, created a new migration with the new credentials, used phpmyadmin to download the serialized blob from the arguments column in migrate_group, restored the old database, and finally replaced the original blob with the one I had downloaded. This had the effect of updating the connection configuration while retaining all of the previous settings I had saved in the migrate UI.