reverted: --- b/src/Event/MigrateEvents.php +++ /dev/null @@ -1,25 +0,0 @@ -stopPropagation() to prevent the rollback. - */ - const MISSING_SOURCE_ITEM = 'migrate_tools.missing_source_item'; - -} diff -u b/src/MigrateExecutable.php b/src/MigrateExecutable.php --- b/src/MigrateExecutable.php +++ b/src/MigrateExecutable.php @@ -16,7 +16,6 @@ use Drupal\migrate\Plugin\MigrationInterface; use Drupal\migrate_plus\Event\MigrateEvents as MigratePlusEvents; use Drupal\migrate_plus\Event\MigratePrepareRowEvent; -use Drupal\migrate_tools\Event\MigrateEvents as MigrateToolsEvents; /** * Defines a migrate executable class for drush. @@ -334,7 +333,7 @@ public function rollbackMissingItems() { // Only begin the rollback operation if the migration is currently idle. if ($this->migration->getStatus() !== MigrationInterface::STATUS_IDLE) { - $status = $this->migration->getStatusLabel; + $status = $this->migration->getStatusLabel(); $this->message->display($this->t('Migration @id is busy with another operation: @status', [ '@id' => $this->migration->id(), @@ -379,7 +378,7 @@ } $event = $this->getEventDispatcher() - ->dispatch(MigrateToolsEvents::MISSING_SOURCE_ITEM, new MigrateRowDeleteEvent($this->migration, $destination_key)); + ->dispatch(MigratePlusEvents::MISSING_SOURCE_ITEM, new MigrateRowDeleteEvent($this->migration, $destination_key)); if (!$event->isPropagationStopped()) { $this->rollbackCurrentRow(); } only in patch2: unchanged: --- /dev/null +++ b/tests/src/Kernel/RollbackMissingMessageTest.php @@ -0,0 +1,124 @@ + ['id' => '1', 'name' => 'categories', 'weight' => '2'], + ]; + + $this->migration = $this->createMigration('import', $vocabulary_data_rows); + } + + /** + * Tests rolling back configuration and content entities. + */ + public function testNonSyncableSource() { + $this->startCollectingMessages(); + // Rollback. + $rollback_executable = new MigrateExecutable($this->migration, $this); + $rollback_executable->rollbackMissingItems(); + + $messages = $this->migration->getIdMap()->getMessageIterator(); + $count = 0; + foreach ($messages as $message) { + $count++; + $this->assertContains("Migration 'import' does not support rolling back items missing from the source", $message->message); + $this->assertEqual($message->level, MigrationInterface::MESSAGE_ERROR); + } + // There should be only the one message. + $this->assertEqual($count, 1); + } + + /** + * Tests rolling back configuration and content entities. + */ + public function testNotIdle() { + $this->migration->setStatus(MigrationInterface::STATUS_STOPPING); + $this->startCollectingMessages(); + // Rollback. + $rollback_executable = new MigrateExecutable($this->migration, $this); + $rollback_executable->rollbackMissingItems(); + + $messages = $this->migration->getIdMap()->getMessageIterator(); + $count = 0; + foreach ($messages as $message) { + $count++; + $this->assertContains("Migration 'import' is busy with another operation: 4", $message->message); + $this->assertEqual($message->level, MigrationInterface::MESSAGE_ERROR); + } + // There should be only the one message. + $this->assertEqual($count, 1); + } + + /** + * Helper to create a vocabulary migration with given data. + * + * @param string $id + * An migration id. + * @param array $data + * Data for the embedded data source plugin for a vocabulary migration. + * + * @return \Drupal\migrate\Plugin\MigrationInterface + * A vocabulary migration stub. + */ + protected function createMigration($id, array $data) { + $ids = ['id' => ['type' => 'integer']]; + $definition = [ + 'id' => $id, + 'migration_tags' => ['Import and rollback test'], + 'source' => [ + 'plugin' => 'embedded_data', + 'data_rows' => $data, + 'ids' => $ids, + ], + 'process' => [ + 'vid' => 'id', + 'name' => 'name', + 'weight' => 'weight', + ], + 'destination' => ['plugin' => 'entity:taxonomy_vocabulary'], + ]; + + $this->migration = \Drupal::service('plugin.manager.migration') + ->createStubMigration($definition); + return $this->migration; + } + +}