Migration in Drupal - Part 2

Part 1 looked at how to put the source database credentials in settings.php.  Part 2 looks at how to specify the source website root so that files are properly transferred.  After the fix for the database settings in part 1 the command for configuring the migration is

drush migrate-upgrade --legacy-root=http://mydrupal7site.com --configure-only

The import of the files is done by running

drush migrate-import upgrade-d7-files

This is supposed to retrieve the files and put them in the new website. However, all the files show an error message that has the path but is missing the http://mydrupal7.site.com prefix. Since the legacy root flag is documented in many places it seems strange that it does not work properly. Perhaps introducing the configure only flag and splitting the upgrade into two commands is why this is no longer working.

Migration of files without the legacy root

Tracking down the problem shows that the constant source_base_path is missing when running the import. Trying to specify the legacy root in the migrate-import does not work. It is possible to copy all of the files manually before running the import but this can result in copying over files that are no longer needed. Fortunately the code to fix the problem is just a few line although not obvious. We again use the custom_migration module.

/**
 * Implements hook_migrate_MIGRATION_ID_prepare_row().
 */
function custom_migration_migrate_upgrade_d7_file_prepare_row($row, $source, $migration) {
  $constants = array('source_base_path' => 'http://mydrupal7site.com/');
  $row->setSourceProperty('constants', $constants);
}

Now the command for configuring the migration is

drush migrate-upgrade --configure-only
Categories