From f2f41c6b9f74826f22a0ba42838359bad3966a6b Mon Sep 17 00:00:00 2001 From: Dieter Holvoet Date: Fri, 21 Oct 2022 13:34:08 +0200 Subject: [PATCH 1/2] Allow resetting the status of multiple migrations --- .../Commands/core/MigrateRunnerCommands.php | 47 ++++++++++++++----- 1 file changed, 35 insertions(+), 12 deletions(-) diff --git a/src/Drupal/Commands/core/MigrateRunnerCommands.php b/src/Drupal/Commands/core/MigrateRunnerCommands.php index 6a96849ab6..614efb93c7 100644 --- a/src/Drupal/Commands/core/MigrateRunnerCommands.php +++ b/src/Drupal/Commands/core/MigrateRunnerCommands.php @@ -570,29 +570,52 @@ public function stop(string $migrationId): void * * @command migrate:reset-status * - * @param string $migrationId - * The ID of migration to reset. + * @param string|null $migrationIds + * Comma-separated list of migration IDs. * * @aliases mrs,migrate-reset-status * * @topics docs:migrate * + * @option all Process all migrations. + * @option tag A comma-separated list of migration tags to rollback + * + * @usage migrate:reset-status --all + * Reset the status of all migrations + * @usage migrate:reset-status --tag=user,main_content + * Reset the status of all migrations tagged with user and main_content tags + * @usage migrate:reset-status classification,article + * Reset the status of the classification and article migrations + * * @validate-module-enabled migrate - * @validate-migration-id * @version 10.4 * * @throws PluginException */ - public function resetStatus(string $migrationId): void + public function resetStatus(?string $migrationIds = null, array $options = ['all' => false, 'tag' => self::REQ]): void { - /** @var MigrationInterface $migration */ - $migration = $this->migrationPluginManager->createInstance($migrationId); - $status = $migration->getStatus(); - if ($status == MigrationInterface::STATUS_IDLE) { - $this->logger()->warning(dt('Migration @id is already Idle', ['@id' => $migrationId])); - } else { - $migration->setStatus(MigrationInterface::STATUS_IDLE); - $this->logger()->success(dt('Migration @id reset to Idle', ['@id' => $migrationId])); + $tags = $options['tag']; + $all = $options['all']; + + if (!$all && !$migrationIds && !$tags) { + throw new \Exception(dt('You must specify --all, --tag, or one or more migration names separated by commas')); + } + + if (!$list = $this->getMigrationList($migrationIds, $options['tag'])) { + $this->logger()->error(dt('No migrations found.')); + } + + foreach ($list as $migrations) { + foreach ($migrations as $migrationId => $migration) { + /** @var MigrationInterface $migration */ + $status = $migration->getStatus(); + if ($status == MigrationInterface::STATUS_IDLE) { + $this->logger()->warning(dt('Migration @id is already Idle', ['@id' => $migrationId])); + } else { + $migration->setStatus(MigrationInterface::STATUS_IDLE); + $this->logger()->success(dt('Migration @id reset to Idle', ['@id' => $migrationId])); + } + } } } From 6e3be62be15633a55cc66b0231edc542a27ee449 Mon Sep 17 00:00:00 2001 From: Dieter Holvoet Date: Wed, 14 Dec 2022 19:38:41 +0100 Subject: [PATCH 2/2] Stop logging 'Migration @id is already Idle' --- src/Drupal/Commands/core/MigrateRunnerCommands.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/Drupal/Commands/core/MigrateRunnerCommands.php b/src/Drupal/Commands/core/MigrateRunnerCommands.php index 614efb93c7..762a887524 100644 --- a/src/Drupal/Commands/core/MigrateRunnerCommands.php +++ b/src/Drupal/Commands/core/MigrateRunnerCommands.php @@ -609,9 +609,7 @@ public function resetStatus(?string $migrationIds = null, array $options = ['all foreach ($migrations as $migrationId => $migration) { /** @var MigrationInterface $migration */ $status = $migration->getStatus(); - if ($status == MigrationInterface::STATUS_IDLE) { - $this->logger()->warning(dt('Migration @id is already Idle', ['@id' => $migrationId])); - } else { + if ($status !== MigrationInterface::STATUS_IDLE) { $migration->setStatus(MigrationInterface::STATUS_IDLE); $this->logger()->success(dt('Migration @id reset to Idle', ['@id' => $migrationId])); }