Skip to content

Commit

Permalink
More worky?
Browse files Browse the repository at this point in the history
  • Loading branch information
adam-vessey committed Jun 6, 2024
1 parent 35f2e87 commit bf52db7
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 16 deletions.
16 changes: 12 additions & 4 deletions src/Form/Ingest/Review.php
Original file line number Diff line number Diff line change
Expand Up @@ -261,15 +261,20 @@ protected function submitProcessImmediate(array &$form, FormStateInterface $form
/**
* Callback for the "full_rollback_migration_group" method.
*/
protected function submitProcessRollbackMigrationGroup(array &$form, FormStateInterface $form_state, array $params): void {
protected function submitProcessRollbackMigrationGroup(array &$form, FormStateInterface $form_state): void {
try {
$migrations = $this->migrationPluginManager->createInstancesByTag($this->migrationGroupDeriver->deriveTag($this->entity));

$migrations = array_reverse($migrations);

$batch = [
'operations' => [],
];

$messenger = new MigrateMessage();

foreach ($migrations as $migration) {
$executable = new MigrationRollbackBatch($migration, $this->messenger, [
$executable = new MigrationRollbackBatch($migration, $messenger, [
'limit' => 0,
'update' => 0,
'force' => 0,
Expand All @@ -295,15 +300,18 @@ protected function submitProcessRollbackMigrationGroup(array &$form, FormStateIn
/**
* Callback for the "failed_rollback_migration_group" method.
*/
protected function submitProcessRollbackFailedMigrationGroup(array &$form, FormStateInterface $form_state, array $params): void {
protected function submitProcessRollbackFailedMigrationGroup(array &$form, FormStateInterface $form_state): void {
try {
$migrations = $this->migrationPluginManager->createInstancesByTag($this->migrationGroupDeriver->deriveTag($this->entity));
$migrations = array_reverse($migrations);
$batch = [
'operations' => [],
];

$messenger = new MigrateMessage();

foreach ($migrations as $migration) {
$executable = new MigrationRollbackBatch($migration, $this->messenger, [
$executable = new MigrationRollbackBatch($migration, $messenger, [
'limit' => 0,
'update' => 0,
'force' => 0,
Expand Down
19 changes: 7 additions & 12 deletions src/Util/MigrationRollbackBatch.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
use Drupal\dgi_migrate\MigrateBatchException;
use Drupal\dgi_migrate\StatusFilter;
use Drupal\migrate\Event\MigrateEvents;
use Drupal\migrate\Event\MigrateImportEvent;
use Drupal\migrate\Event\MigrateRollbackEvent;
use Drupal\migrate\Event\MigrateRowDeleteEvent;
use Drupal\migrate\MigrateMessageInterface;
Expand All @@ -24,18 +23,15 @@ class MigrationRollbackBatch extends MigrateExecutable {
__wakeup as traitWakeup;
}

/**
* Options.
*/
protected array $options;

/**
* Stores the migration rows.
*
* @var \Drupal\Core\Queue\QueueInterface
*/
protected QueueInterface $queue;

protected bool $checkStatus;

/**
* Constructs a new MigrationRollbackBatch instance.
*
Expand All @@ -52,8 +48,7 @@ public function __construct(
array $options,
) {
parent::__construct($migration, $messenger, $options);
$this->options = $options;
$this->messenger = $messenger;
$this->checkStatus = $options['checkStatus'] ?? FALSE;
}

/**
Expand Down Expand Up @@ -103,18 +98,18 @@ private function enqueue(): int {
]), 'error');
return MigrationInterface::RESULT_FAILED;
}
$this->getEventDispatcher()->dispatch(new MigrateImportEvent($this->migration, $this->message), MigrateEvents::PRE_ROLLBACK);
$this->getEventDispatcher()->dispatch(new MigrateRollbackEvent($this->migration, $this->message), MigrateEvents::PRE_ROLLBACK);
$this->migration->setStatus(MigrationInterface::STATUS_ROLLING_BACK);
$queue = $this->getQueue();
$queue->deleteQueue();

$id_map = $this->getIdMap();
$iterator = $this->options['checkStatus'] ?
$iterator = $this->checkStatus ?
new StatusFilter($id_map, StatusFilter::mapStatuses('failed,ignored')) :
$id_map;
foreach ($iterator as $row) {
foreach ($iterator as $_) {
$this->queue->createItem([
'destination' => $row,
'destination' => $id_map->currentDestination(),
'source' => $id_map->currentSource(),
]);
}
Expand Down

0 comments on commit bf52db7

Please sign in to comment.