-
Notifications
You must be signed in to change notification settings - Fork 1
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
DEV - MIG - UI Rollback option for CSV Migration Group #105
Closed
Closed
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
5241332
Try using drush command directly
dynac01 a898f4b
Merge branch 'main' into feature/add-option-to-rollback-full-migrations
dynac01 ffc7c99
Utilize built-in rollback feature
dynac01 a6b05e1
Merge branch 'feature/add-option-to-rollback-full-migrations' of http…
dynac01 8a08a7e
Remove unnessary method
dynac01 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
<?php | ||
|
||
namespace Drupal\islandora_spreadsheet_ingest\Util; | ||
|
||
use Drupal\Core\Messenger\MessengerInterface; | ||
use Drupal\migrate\MigrateMessage; | ||
use Drupal\migrate\Plugin\MigrationInterface; | ||
use Drupal\migrate\Plugin\MigrationPluginManagerInterface; | ||
use Drupal\Core\DependencyInjection\DependencySerializationTrait; | ||
use Drupal\migrate_tools\MigrateExecutable; | ||
|
||
/** | ||
* Class responsible for rolling back a migration in batches. | ||
*/ | ||
class MigrationRollbackBatch extends MigrateExecutable { | ||
|
||
use DependencySerializationTrait { | ||
__sleep as traitSleep; | ||
__wakeup as traitWakeup; | ||
} | ||
|
||
/** | ||
* Manages migration plugin instances. It's used to create instances of migrations by their group ID. | ||
* | ||
* @var MigrationPluginManagerInterface | ||
*/ | ||
protected MigrationPluginManagerInterface $migrationPluginManager; | ||
protected MessengerInterface $messenger; | ||
|
||
public function __construct( | ||
MigrationInterface $migration, | ||
MessengerInterface $messenger, | ||
array $options, | ||
) { | ||
parent::__construct($migration, new MigrateMessage(), $options); | ||
$this->messenger = $messenger; | ||
} | ||
|
||
/** | ||
* Prepare a batch array for execution for the given migration. | ||
* | ||
* @return array | ||
* A batch array with operations and the like. | ||
* | ||
* @throws \Exception | ||
* If the migration could not be enqueued successfully. | ||
*/ | ||
public function prepareBatch(): array { | ||
return [ | ||
'title' => $this->t('Rolling back migration: @migration', ['@migration' => $this->migration->id()]), | ||
'operations' => [ | ||
[[$this, 'processBatch'], []], | ||
], | ||
'finished' => [$this, 'finishBatch'], | ||
]; | ||
} | ||
|
||
/** | ||
* Process each batch to roll back all contained rows | ||
* | ||
* @param array $context | ||
* @return void | ||
*/ | ||
public function processBatch(array &$context): void { | ||
$context['message'] = $this->t('Processing of "@migration_id"', ['@migration_id' => $this->migration->id()]); | ||
|
||
$status = $this->rollback(); | ||
|
||
if ($status === MigrationInterface::RESULT_COMPLETED) { | ||
$message = $this->t('Rollback completed', ['@id' => $this->migration->id()]); | ||
$this->messenger->addStatus($message); | ||
} | ||
else { | ||
$message = $this->t('Rollback of @name migration failed.', ['@name' => $this->migration->id()]); | ||
$this->messenger->addError($message); | ||
} | ||
|
||
$context['message'] = $this->t('"@migration_id" has been processed', ['@migration_id' => $this->migration->id()]); | ||
} | ||
|
||
|
||
/** | ||
* Display success or error messages following the completion of processing | ||
* | ||
* @param $success | ||
* @param $results | ||
* @param $ops | ||
* @param $interval | ||
* @return void | ||
*/ | ||
public function finishBatch($success, $results, $ops, $interval): void { | ||
if (!$success || empty($results['errors'])) { | ||
$this->messenger->addError( | ||
$this->t( | ||
'Rollback encountered errors.' | ||
) | ||
); | ||
|
||
foreach ($results['errors'] as $e) { | ||
$this->messenger->addError( | ||
$this->t('Migration group rollback failed with exception: @e', ['@e' => $e])); | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changing this because both MigrateBatchExecutable and MigrationRollbackBatch extend MigrateExecutable