You are here

public function MigrateUpgradeDrushRunner::rollback in Migrate Upgrade 8.3

Same name and namespace in other branches
  1. 8 src/MigrateUpgradeDrushRunner.php \Drupal\migrate_upgrade\MigrateUpgradeDrushRunner::rollback()
  2. 8.2 src/MigrateUpgradeDrushRunner.php \Drupal\migrate_upgrade\MigrateUpgradeDrushRunner::rollback()

Rolls back the configured migrations.

File

src/MigrateUpgradeDrushRunner.php, line 431

Class

MigrateUpgradeDrushRunner
Class MigrateUpgradeDrushRunner.

Namespace

Drupal\migrate_upgrade

Code

public function rollback() {
  static::$messages = new DrushLogMigrateMessage($this->logger);
  $database_state_key = \Drupal::state()
    ->get('migrate.fallback_state_key');
  $database_state = \Drupal::state()
    ->get($database_state_key);
  $db_spec = $database_state['database'];
  $connection = $this
    ->getConnection($db_spec);
  $version = $this
    ->getLegacyDrupalVersion($connection);
  $migrations = $this
    ->getMigrations('migrate_drupal_' . $version, $version);

  // Roll back in reverse order.
  $this->migrationList = array_reverse($migrations);
  foreach ($migrations as $migration) {
    $this->logger
      ->log('ok', dt('Rolling back @migration', [
      '@migration' => $migration
        ->id(),
    ]));
    $executable = new MigrateExecutable($migration, static::$messages);

    // drush_op() provides --simulate support.
    drush_op([
      $executable,
      'rollback',
    ]);
  }
}