Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow resetting the status of multiple migrations #5287

Open
wants to merge 2 commits into
base: 11.x
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
45 changes: 33 additions & 12 deletions src/Drupal/Commands/core/MigrateRunnerCommands.php
Original file line number Diff line number Diff line change
Expand Up @@ -570,29 +570,50 @@ 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 <info>user</info> and <info>main_content</info> tags
* @usage migrate:reset-status classification,article
* Reset the status of the <info>classification</info> and <info>article</info> 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'];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens if some are using:

  • --all with --tag and some migration names?
  • but --all with --tag?
  • or --all with a list of migrations?

Maybe we should remove --all and NO MIGRATIONS == ALL? Then:

  • no arguments, no options: All migrations
  • only --tag: All migrations filtered by provided tags
  • migration IDs + --tag: should return error (or filter the list on tags?)


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'])) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We've already assign $options['tag'] to $tags. Why not use that var?

$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) {
$migration->setStatus(MigrationInterface::STATUS_IDLE);
$this->logger()->success(dt('Migration @id reset to Idle', ['@id' => $migrationId]));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe Migration @id status reset to idle (added the "status" word)

}
}
}
}

Expand Down