5 * Command-line tools to aid performing and developing upgrade migrations.
8 use Drupal\migrate_upgrade\MigrateUpgradeDrushRunner;
11 * Implements hook_drush_command().
13 function migrate_upgrade_drush_command() {
14 $items['migrate-upgrade'] = [
15 'description' => 'Perform one or more upgrade processes.',
17 'legacy-db-url' => 'A Drupal 6 style database URL. Required if you do not set legacy-db-key.',
18 'legacy-db-key' => 'A database connection key from settings.php. Use as an alternative to legacy-db-url',
19 'legacy-db-prefix' => 'Prefix of the legacy Drupal installation.',
20 'legacy-root' => 'Site address or root of the legacy Drupal installation',
21 'configure-only' => 'Set up the appropriate upgrade processes but do not perform them',
22 'migration-prefix' => 'With configure-only, a prefix to apply to generated migration ids. Defaults to \'upgrade_\'',
25 'migrate-upgrade --legacy-db-url=\'mysql://root:pass@127.0.0.1/d6\'' => 'Upgrade a Drupal 6 database to Drupal 8',
26 'migrate-upgrade --legacy-db-key=\'drupal_7\'' => 'Upgrade Drupal 7 database where the connection to Drupal 7 has already been created in settings.php ($databases[\'drupal_7\'])',
27 'migrate-upgrade --legacy-db-url=\'mysql://root:pass@127.0.0.1/d7\' --configure-only --migration-prefix=d7_custom_' => 'Generate migrations for a custom migration from Drupal 7 to Drupal 8',
29 'drupal dependencies' => ['migrate_upgrade'],
31 $items['migrate-upgrade-rollback'] = [
32 'description' => 'Rolls back and removes upgrade migrations.',
34 'migrate-upgrade-rollback' => 'Rolls back a previously-run upgrade',
36 'drupal dependencies' => ['migrate_upgrade'],
43 * Execute the upgrade command, configuring the necessary migrations and
44 * optionally perform the imports.
46 function drush_migrate_upgrade() {
47 $runner = new MigrateUpgradeDrushRunner();
51 if (drush_get_option('configure-only')) {
56 \Drupal::state()->set('migrate_drupal_ui.performed', \Drupal::time()->getRequestTime());
58 // Remove the global database state.
59 \Drupal::state()->delete('migrate.fallback_state_key');
61 catch (\Exception $e) {
62 drush_log($e->getMessage(), 'error');
67 * Rolls back any upgrade migrations that are present, and deletes the migrations
70 function drush_migrate_upgrade_rollback() {
71 if ($date_performed = \Drupal::state()->get('migrate_drupal_ui.performed')) {
72 if (drush_confirm(dt('All migrations tagged as \'Drupal\' will be rolled back. Are you sure?'))) {
73 $runner = new MigrateUpgradeDrushRunner();
76 drush_log(dt('Rolling back the upgrades performed @date',
77 ['@date' => \Drupal::service('date.formatter')->format($date_performed)]));
79 \Drupal::state()->delete('migrate_drupal_ui.performed');
80 drush_log(dt('Rolled back upgrades'));
82 catch (\Exception $e) {
83 drush_log($e->getMessage(), 'error');
91 drush_log(dt('No upgrade operation has been performed.'), 'warning');