You are here

public function MigrateToolsCommands::stop in Migrate Tools 8.5

Same name and namespace in other branches
  1. 8.4 src/Commands/MigrateToolsCommands.php \Drupal\migrate_tools\Commands\MigrateToolsCommands::stop()

Stop an active migration operation.

@command migrate:stop

@validate-module-enabled migrate_tools @aliases mst, migrate-stop

Parameters

string $migration_id: ID of migration to stop.

File

src/Commands/MigrateToolsCommands.php, line 541

Class

MigrateToolsCommands
Migrate Tools drush commands.

Namespace

Drupal\migrate_tools\Commands

Code

public function stop($migration_id = '') {

  /** @var \Drupal\migrate\Plugin\MigrationInterface $migration */
  $migration = $this->migrationPluginManager
    ->createInstance($migration_id);
  if ($migration) {
    $status = $migration
      ->getStatus();
    switch ($status) {
      case MigrationInterface::STATUS_IDLE:
        $this
          ->logger()
          ->warning(dt('Migration @id is idle', [
          '@id' => $migration_id,
        ]));
        break;
      case MigrationInterface::STATUS_DISABLED:
        $this
          ->logger()
          ->warning(dt('Migration @id is disabled', [
          '@id' => $migration_id,
        ]));
        break;
      case MigrationInterface::STATUS_STOPPING:
        $this
          ->logger()
          ->warning(dt('Migration @id is already stopping', [
          '@id' => $migration_id,
        ]));
        break;
      default:
        $migration
          ->interruptMigration(MigrationInterface::RESULT_STOPPED);
        $this
          ->logger()
          ->notice(dt('Migration @id requested to stop', [
          '@id' => $migration_id,
        ]));
        break;
    }
  }
  else {
    $error = dt('Migration @id does not exist', [
      '@id' => $migration_id,
    ]);
    $this
      ->logger()
      ->error($error);
    throw new \Exception($error);
  }
}