diff -u b/core/modules/migrate/src/MigrateEvents.php b/core/modules/migrate/src/MigrateEvents.php --- b/core/modules/migrate/src/MigrateEvents.php +++ b/core/modules/migrate/src/MigrateEvents.php @@ -12,6 +12,8 @@ * * @see \Drupal\migrate\MigrateMapSaveEvent * @see \Drupal\migrate\MigrateMapDeleteEvent + * @see \Drupal\migrate\MigratePreImportEvent + * @see \Drupal\migrate\MigratePostImportEvent */ final class MigrateEvents { @@ -47,2 +49,32 @@ + /** + * Name of the event fired when beginning a migration import operation. + * + * This event allows modules to perform an action whenever a migration import + * operation is about to begin. The event listener method receives a + * \Drupal\migrate\MigratePreImportEvent instance. + * + * @Event + * + * @see \Drupal\migrate\MigratePreImportEvent + * + * @var string + */ + const PRE_IMPORT = 'migrate.pre_import'; + + /** + * Name of the event fired when finishing a migration import operation. + * + * This event allows modules to perform an action whenever a migration import + * operation is completing. The event listener method receives a + * \Drupal\migrate\MigratePostImportEvent instance. + * + * @Event + * + * @see \Drupal\migrate\MigratePreImportEvent + * + * @var string + */ + const POST_IMPORT = 'migrate.post_import'; + } diff -u b/core/modules/migrate/src/MigrateExecutable.php b/core/modules/migrate/src/MigrateExecutable.php --- b/core/modules/migrate/src/MigrateExecutable.php +++ b/core/modules/migrate/src/MigrateExecutable.php @@ -207,6 +207,9 @@ * {@inheritdoc} */ public function import() { + $this->migration->getEventDispatcher()->dispatch(MigrateEvents::PRE_IMPORT, + new MigratePreImportEvent($this->migration)); + // Knock off migration if the requirements haven't been met. try { $this->migration->checkRequirements(); @@ -305,12 +308,9 @@ } } - /** - * @TODO uncomment this - */ - #$this->progressMessage($return); - $this->migration->setMigrationResult($return); + $this->migration->getEventDispatcher()->dispatch(MigrateEvents::POST_IMPORT, + new MigratePostImportEvent($this->migration)); return $return; } diff -u b/core/modules/migrate/tests/src/Unit/MigrateSqlIdMapEnsureTablesTest.php b/core/modules/migrate/tests/src/Unit/MigrateSqlIdMapEnsureTablesTest.php --- b/core/modules/migrate/tests/src/Unit/MigrateSqlIdMapEnsureTablesTest.php +++ b/core/modules/migrate/tests/src/Unit/MigrateSqlIdMapEnsureTablesTest.php @@ -181,34 +181,34 @@ ->getMock(); $database->expects($this->any()) ->method('schema') - ->will($this->returnValue($schema)); + ->willReturn($schema); $migration = $this->getMigration(); $plugin = $this->getMock('Drupal\migrate\Plugin\MigrateSourceInterface'); $plugin->expects($this->any()) ->method('getIds') - ->will($this->returnValue(array( + ->willReturn(array( 'source_id_property' => array( 'type' => 'integer', ), - ))); + )); $migration->expects($this->any()) ->method('getSourcePlugin') - ->will($this->returnValue($plugin)); + ->willReturn($plugin); $event_dispatcher = $this->getMock('Symfony\Component\EventDispatcher\EventDispatcherInterface'); $migration->expects($this->any()) ->method('getEventDispatcher') - ->will($this->returnValue($event_dispatcher)); + ->willReturn($event_dispatcher); $plugin = $this->getMock('Drupal\migrate\Plugin\MigrateSourceInterface'); $plugin->expects($this->any()) ->method('getIds') - ->will($this->returnValue(array( + ->willReturn(array( 'destination_id_property' => array( 'type' => 'string', ), - ))); + )); $migration->expects($this->any()) ->method('getDestinationPlugin') - ->will($this->returnValue($plugin)); + ->willReturn($plugin); $map = new TestSqlIdMap($database, array(), 'sql', array(), $migration); $map->getDatabase(); } only in patch2: unchanged: --- /dev/null +++ b/core/modules/migrate/src/MigratePostImportEvent.php @@ -0,0 +1,45 @@ +migration = $migration; + } + + /** + * Gets migration object. + * + * @return \Drupal\migrate\Entity\MigrationInterface + * The migration object just finishing an import operation. + */ + public function getMigration() { + return $this->migration; + } + +} only in patch2: unchanged: --- /dev/null +++ b/core/modules/migrate/src/MigratePreImportEvent.php @@ -0,0 +1,45 @@ +migration = $migration; + } + + /** + * Gets migration object. + * + * @return \Drupal\migrate\Entity\MigrationInterface + * The migration object about to begin an import operation. + */ + public function getMigration() { + return $this->migration; + } + +}