reverted: --- b/core/modules/migrate/src/Entity/Migration.php +++ a/core/modules/migrate/src/Entity/Migration.php @@ -15,7 +15,6 @@ use Drupal\migrate\Plugin\MigrateIdMapInterface; use Drupal\migrate\Plugin\RequirementsInterface; use Drupal\Component\Utility\NestedArray; -use Symfony\Component\EventDispatcher\EventDispatcherInterface; /** * Defines the Migration entity. @@ -242,13 +241,6 @@ protected $entityManager; /** - * The event dispatcher. - * - * @var \Symfony\Component\EventDispatcher\EventDispatcherInterface - */ - protected $eventDispatcher; - - /** * {@inheritdoc} */ public function getSourcePlugin() { @@ -409,16 +401,6 @@ /** * {@inheritdoc} */ - public function getEventDispatcher() { - if (!isset($this->eventDispatcher)) { - $this->eventDispatcher = \Drupal::service('event_dispatcher'); - } - return $this->eventDispatcher; - } - - /** - * {@inheritdoc} - */ public function setMigrationResult($result) { $migrate_result_store = \Drupal::keyValue('migrate_result'); $migrate_result_store->set($this->id(), $result); reverted: --- b/core/modules/migrate/src/Entity/MigrationInterface.php +++ a/core/modules/migrate/src/Entity/MigrationInterface.php @@ -283,12 +283,4 @@ */ public function getMigrationDependencies(); - /** - * Get the event dispatcher. - * - * @return \Symfony\Component\EventDispatcher\EventDispatcherInterface - * The event dispatcher. - */ - public function getEventDispatcher(); - } reverted: --- b/core/modules/migrate/src/MigrateEvents.php +++ /dev/null @@ -1,110 +0,0 @@ -migration = $migration; $this->message = $message; $this->migration->getIdMap()->setMessage($message); + if (!$event_dispatcher) { + $event_dispatcher = \Drupal::service('event_dispatcher'); + } + $this->eventDispatcher = $event_dispatcher; } /** @@ -137,8 +155,7 @@ * {@inheritdoc} */ public function import() { - $this->migration->getEventDispatcher()->dispatch(MigrateEvents::PRE_IMPORT, - new MigratePreImportEvent($this->migration)); + $this->eventDispatcher->dispatch(MigrateEvents::PRE_IMPORT, new MigrateImportEvent($this->migration)); // Knock off migration if the requirements haven't been met. try { @@ -187,11 +204,9 @@ if ($save) { try { - $this->migration->getEventDispatcher()->dispatch(MigrateEvents::PRE_SAVE, - new MigratePreSaveEvent($this->migration, $row)); + $this->eventDispatcher->dispatch(MigrateEvents::PRE_SAVE, new MigratePreRowSaveEvent($this->migration, $row)); $destination_id_values = $destination->import($row, $id_map->lookupDestinationId($this->sourceIdValues)); - $this->migration->getEventDispatcher()->dispatch(MigrateEvents::POST_SAVE, - new MigratePostSaveEvent($this->migration, $row, $destination_id_values)); + $this->eventDispatcher->dispatch(MigrateEvents::POST_SAVE, new MigratePostRowSaveEvent($this->migration, $row, $destination_id_values)); if ($destination_id_values) { // We do not save an idMap entry for config. if ($destination_id_values !== TRUE) { @@ -240,8 +255,7 @@ } $this->migration->setMigrationResult($return); - $this->migration->getEventDispatcher()->dispatch(MigrateEvents::POST_IMPORT, - new MigratePostImportEvent($this->migration)); + $this->eventDispatcher->dispatch(MigrateEvents::POST_IMPORT, new MigrateImportEvent($this->migration)); return $return; } reverted: --- b/core/modules/migrate/src/MigrateMapDeleteEvent.php +++ /dev/null @@ -1,65 +0,0 @@ -map = $map; - $this->sourceId = $source_id; - } - - /** - * Gets map object. - * - * @return \Drupal\migrate\Plugin\MigrateIdMapInterface - * The map object that caused the event to fire. - */ - public function getMap() { - return $this->map; - } - - /** - * Gets the source ID of the item being removed from the map. - * - * @return array - * Array of source ID fields. - */ - public function getSourceId() { - return $this->sourceId; - } - -} reverted: --- b/core/modules/migrate/src/MigrateMapSaveEvent.php +++ /dev/null @@ -1,65 +0,0 @@ -map = $map; - $this->fields = $fields; - } - - /** - * Gets map object. - * - * @return \Drupal\migrate\Plugin\MigrateIdMapInterface - * The map object that caused the event to fire. - */ - public function getMap() { - return $this->map; - } - - /** - * Gets the fields about to be saved to the map. - * - * @return array - * Array of map fields, keyed by field name. - */ - public function getFields() { - return $this->fields; - } - -} reverted: --- b/core/modules/migrate/src/MigratePostImportEvent.php +++ /dev/null @@ -1,45 +0,0 @@ -migration = $migration; - } - - /** - * Gets migration object. - * - * @return \Drupal\migrate\Entity\MigrationInterface - * The migration object just finishing an import operation. - */ - public function getMigration() { - return $this->migration; - } - -} reverted: --- b/core/modules/migrate/src/MigratePostSaveEvent.php +++ /dev/null @@ -1,85 +0,0 @@ -migration = $migration; - $this->row = $row; - $this->destinationIdValues = $destination_id_values; - } - - /** - * Gets migration object. - * - * @return \Drupal\migrate\Entity\MigrationInterface - * The migration object being imported. - */ - public function getMigration() { - return $this->migration; - } - - /** - * Gets row object. - * - * @return \Drupal\migrate\Row - * The row object just imported. - */ - public function getRow() { - return $this->migration; - } - - /** - * Gets destination ID values. - * - * @return array - * The destination ID as an array. - */ - public function getDestinationIdValues() { - return $this->destinationIdValues; - } - -} reverted: --- b/core/modules/migrate/src/MigratePreImportEvent.php +++ /dev/null @@ -1,45 +0,0 @@ -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; - } - -} reverted: --- b/core/modules/migrate/src/MigratePreSaveEvent.php +++ /dev/null @@ -1,63 +0,0 @@ -migration = $migration; - $this->row = $row; - } - - /** - * Gets migration object. - * - * @return \Drupal\migrate\Entity\MigrationInterface - * The migration object being imported. - */ - public function getMigration() { - return $this->migration; - } - - /** - * Gets row object. - * - * @return \Drupal\migrate\Row - * The row object about to be imported. - */ - public function getRow() { - return $this->migration; - } - -} diff -u b/core/modules/migrate/src/Plugin/migrate/id_map/Sql.php b/core/modules/migrate/src/Plugin/migrate/id_map/Sql.php --- b/core/modules/migrate/src/Plugin/migrate/id_map/Sql.php +++ b/core/modules/migrate/src/Plugin/migrate/id_map/Sql.php @@ -9,16 +9,19 @@ use Drupal\Component\Utility\Unicode; use Drupal\Core\Database\Connection; +use Drupal\Core\Entity\EntityTypeInterface; use Drupal\Core\Field\BaseFieldDefinition; +use Drupal\Core\Plugin\ContainerFactoryPluginInterface; use Drupal\Core\Plugin\PluginBase; use Drupal\migrate\Entity\MigrationInterface; use Drupal\migrate\MigrateException; use Drupal\migrate\MigrateMessageInterface; use Drupal\migrate\Plugin\MigrateIdMapInterface; use Drupal\migrate\Row; -use Drupal\migrate\MigrateEvents; -use Drupal\migrate\MigrateMapSaveEvent; -use Drupal\migrate\MigrateMapDeleteEvent; +use Drupal\migrate\Event\MigrateEvents; +use Drupal\migrate\Event\MigrateMapSaveEvent; +use Drupal\migrate\Event\MigrateMapDeleteEvent; +use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\EventDispatcher\EventDispatcherInterface; /** @@ -29,7 +32,7 @@ * * @PluginID("sql") */ -class Sql extends PluginBase implements MigrateIdMapInterface { +class Sql extends PluginBase implements MigrateIdMapInterface, ContainerFactoryPluginInterface { /** * An event dispatcher instance to use for map events. @@ -148,10 +151,23 @@ * @param \Drupal\migrate\Entity\MigrationInterface $migration * The migration to do. */ - public function __construct(array $configuration, $plugin_id, $plugin_definition, MigrationInterface $migration) { + public function __construct(array $configuration, $plugin_id, $plugin_definition, MigrationInterface $migration, EventDispatcherInterface $event_dispatcher) { parent::__construct($configuration, $plugin_id, $plugin_definition); $this->migration = $migration; - $this->eventDispatcher = $migration->getEventDispatcher(); + $this->eventDispatcher = $event_dispatcher; + } + + /** + * {@inheritdoc} + */ + public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition, MigrationInterface $migration = NULL) { + return new static( + $configuration, + $plugin_id, + $plugin_definition, + $migration, + $container->get('event_dispatcher') + ); } /** @@ -236,6 +252,15 @@ } /** + * Gets the injected event dispatcher. + * + * @return \Symfony\Component\EventDispatcher\EventDispatcherInterface + */ + protected function getEventDispatcher() { + return $this->eventDispatcher; + } + + /** * Initialize the plugin. */ protected function init() { @@ -516,7 +541,7 @@ } if ($keys) { // Notify anyone listening of the map row we're about to save. - $this->eventDispatcher->dispatch(MigrateEvents::MAP_SAVE, new MigrateMapSaveEvent($this, $keys + $fields)); + $this->getEventDispatcher()->dispatch(MigrateEvents::MAP_SAVE, new MigrateMapSaveEvent($this, $keys + $fields)); $this->getDatabase()->merge($this->mapTableName()) ->key($keys) ->fields($fields) @@ -634,7 +659,7 @@ if (!$messages_only) { // Notify anyone listening of the map row we're about to delete. - $this->eventDispatcher->dispatch(MigrateEvents::MAP_DELETE, new MigrateMapDeleteEvent($this, $source_id_values)); + $this->getEventDispatcher()->dispatch(MigrateEvents::MAP_DELETE, new MigrateMapDeleteEvent($this, $source_id_values)); $map_query->execute(); } $message_query->execute(); @@ -654,7 +679,7 @@ $count++; } // Notify anyone listening of the map row we're about to delete. - $this->eventDispatcher->dispatch(MigrateEvents::MAP_DELETE, new MigrateMapDeleteEvent($this, $source_id)); + $this->getEventDispatcher()->dispatch(MigrateEvents::MAP_DELETE, new MigrateMapDeleteEvent($this, $source_id)); $map_query->execute(); $count = 1; foreach ($source_id as $key_value) { @@ -691,7 +716,7 @@ $sourceids = array(); foreach ($source_id_values as $source_id) { // Notify anyone listening of the map rows we're about to delete. - $this->eventDispatcher->dispatch(MigrateEvents::MAP_DELETE, new MigrateMapDeleteEvent($this, $source_id)); + $this->getEventDispatcher()->dispatch(MigrateEvents::MAP_DELETE, new MigrateMapDeleteEvent($this, $source_id)); $sourceids[] = $source_id; } $this->getDatabase()->delete($this->mapTableName()) @@ -704,7 +729,7 @@ else { foreach ($source_id_values as $source_id) { // Notify anyone listening of the map rows we're deleting. - $this->eventDispatcher->dispatch(MigrateEvents::MAP_DELETE, new MigrateMapDeleteEvent($this, $source_id)); + $this->getEventDispatcher()->dispatch(MigrateEvents::MAP_DELETE, new MigrateMapDeleteEvent($this, $source_id)); $map_query = $this->getDatabase()->delete($this->mapTableName()); $message_query = $this->getDatabase()->delete($this->messageTableName()); $count = 1; diff -u b/core/modules/migrate/tests/src/Unit/MigrateExecutableTest.php b/core/modules/migrate/tests/src/Unit/MigrateExecutableTest.php --- b/core/modules/migrate/tests/src/Unit/MigrateExecutableTest.php +++ b/core/modules/migrate/tests/src/Unit/MigrateExecutableTest.php @@ -50,8 +50,8 @@ parent::setUp(); $this->migration = $this->getMigration(); $this->message = $this->getMock('Drupal\migrate\MigrateMessageInterface'); - - $this->executable = new TestMigrateExecutable($this->migration, $this->message); + $event_dispatcher = $this->getMock('Symfony\Component\EventDispatcher\EventDispatcherInterface'); + $this->executable = new TestMigrateExecutable($this->migration, $this->message, $event_dispatcher); $this->executable->setStringTranslation($this->getStringTranslationStub()); } 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 @@ -205,7 +205,9 @@ $migration->expects($this->any()) ->method('getDestinationPlugin') ->willReturn($plugin); - $map = new TestSqlIdMap($database, array(), 'sql', array(), $migration); + /** @var \Symfony\Component\EventDispatcher\EventDispatcherInterface $event_dispatcher */ + $event_dispatcher = $this->getMock('Symfony\Component\EventDispatcher\EventDispatcherInterface'); + $map = new TestSqlIdMap($database, array(), 'sql', array(), $migration, $event_dispatcher); $map->getDatabase(); } diff -u b/core/modules/migrate/tests/src/Unit/MigrateSqlIdMapTest.php b/core/modules/migrate/tests/src/Unit/MigrateSqlIdMapTest.php --- b/core/modules/migrate/tests/src/Unit/MigrateSqlIdMapTest.php +++ b/core/modules/migrate/tests/src/Unit/MigrateSqlIdMapTest.php @@ -103,11 +103,8 @@ ->method('getDestinationPlugin') ->willReturn($plugin); $event_dispatcher = $this->getMock('Symfony\Component\EventDispatcher\EventDispatcherInterface'); - $migration->expects($this->any()) - ->method('getEventDispatcher') - ->will($this->returnValue($event_dispatcher)); - - $id_map = new TestSqlIdMap($this->database, [], 'sql', [], $migration); + + $id_map = new TestSqlIdMap($this->database, [], 'sql', [], $migration, $event_dispatcher); $migration ->method('getIdMap') ->willReturn($id_map); diff -u b/core/modules/migrate/tests/src/Unit/MigrateTestCase.php b/core/modules/migrate/tests/src/Unit/MigrateTestCase.php --- b/core/modules/migrate/tests/src/Unit/MigrateTestCase.php +++ b/core/modules/migrate/tests/src/Unit/MigrateTestCase.php @@ -27,6 +27,10 @@ protected function getMigration() { $this->migrationConfiguration += ['migrationClass' => 'Drupal\migrate\Entity\Migration']; $this->idMap = $this->getMock('Drupal\migrate\Plugin\MigrateIdMapInterface'); + $event_dispatcher = $this->getMock('Symfony\Component\EventDispatcher\EventDispatcherInterface'); + $this->idMap + ->method('getEventDispatcher') + ->willReturn($event_dispatcher); $this->idMap->expects($this->any()) ->method('getQualifiedMapTableName') @@ -51,10 +55,6 @@ $migration->expects($this->any()) ->method('id') ->will($this->returnValue($configuration['id'])); - $event_dispatcher = $this->getMock('Symfony\Component\EventDispatcher\EventDispatcherInterface'); - $migration->expects($this->any()) - ->method('getEventDispatcher') - ->willReturn($event_dispatcher); return $migration; } only in patch2: unchanged: --- /dev/null +++ b/core/modules/migrate/src/Event/MigrateEvents.php @@ -0,0 +1,109 @@ +migration = $migration; + } + + /** + * Gets migration object. + * + * @return \Drupal\migrate\Entity\MigrationInterface + * The migration object involved. + */ + public function getMigration() { + return $this->migration; + } + +} only in patch2: unchanged: --- /dev/null +++ b/core/modules/migrate/src/Event/MigrateMapDeleteEvent.php @@ -0,0 +1,65 @@ +map = $map; + $this->sourceId = $source_id; + } + + /** + * Gets map object. + * + * @return \Drupal\migrate\Plugin\MigrateIdMapInterface + * The map object that caused the event to fire. + */ + public function getMap() { + return $this->map; + } + + /** + * Gets the source ID of the item being removed from the map. + * + * @return array + * Array of source ID fields. + */ + public function getSourceId() { + return $this->sourceId; + } + +} only in patch2: unchanged: --- /dev/null +++ b/core/modules/migrate/src/Event/MigrateMapSaveEvent.php @@ -0,0 +1,65 @@ +map = $map; + $this->fields = $fields; + } + + /** + * Gets map object. + * + * @return \Drupal\migrate\Plugin\MigrateIdMapInterface + * The map object that caused the event to fire. + */ + public function getMap() { + return $this->map; + } + + /** + * Gets the fields about to be saved to the map. + * + * @return array + * Array of map fields, keyed by field name. + */ + public function getFields() { + return $this->fields; + } + +} only in patch2: unchanged: --- /dev/null +++ b/core/modules/migrate/src/Event/MigratePostRowSaveEvent.php @@ -0,0 +1,43 @@ +destinationIdValues = $destination_id_values; + } + + /** + * Gets destination ID values. + * + * @return array + * The destination ID as an array. + */ + public function getDestinationIdValues() { + return $this->destinationIdValues; + } + +} only in patch2: unchanged: --- /dev/null +++ b/core/modules/migrate/src/Event/MigratePreRowSaveEvent.php @@ -0,0 +1,64 @@ +migration = $migration; + $this->row = $row; + } + + /** + * Gets migration object. + * + * @return \Drupal\migrate\Entity\MigrationInterface + * The migration object being imported. + */ + public function getMigration() { + return $this->migration; + } + + /** + * Gets row object. + * + * @return \Drupal\migrate\Row + * The row object about to be imported. + */ + public function getRow() { + return $this->migration; + } + +} only in patch2: unchanged: --- a/core/modules/migrate/src/Plugin/MigrateDestinationInterface.php +++ b/core/modules/migrate/src/Plugin/MigrateDestinationInterface.php @@ -55,33 +55,6 @@ public function getIds(); */ public function fields(MigrationInterface $migration = NULL); - - /** - * Allows pre-processing of an import. - * - * Derived classes may implement preImport() to do any processing they need - * done before over all source rows. - */ - public function preImport(); - - /** - * Allows pre-processing of a rollback. - */ - public function preRollback(); - - /** - * Allows post-processing of an import. - * - * Derived classes may implement postImport(), to do any processing they need - * done after looping over all source rows. - */ - public function postImport(); - - /** - * Allows post-processing of a rollback. - */ - public function postRollback(); - /** * Import the row. * only in patch2: unchanged: --- a/core/modules/migrate/src/Plugin/migrate/destination/DestinationBase.php +++ b/core/modules/migrate/src/Plugin/migrate/destination/DestinationBase.php @@ -60,34 +60,6 @@ public function checkRequirements() { } /** - * Modify the Row before it is imported. - */ - public function preImport() { - // By default we do nothing. - } - - /** - * Modify the Row before it is rolled back. - */ - public function preRollback() { - // By default we do nothing. - } - - /** - * {@inheritdoc} - */ - public function postImport() { - // By default we do nothing. - } - - /** - * {@inheritdoc} - */ - public function postRollback() { - // By default we do nothing. - } - - /** * {@inheritdoc} */ public function rollbackMultiple(array $destination_identifiers) { only in patch2: unchanged: --- a/core/modules/migrate/src/Plugin/migrate/source/SqlBase.php +++ b/core/modules/migrate/src/Plugin/migrate/source/SqlBase.php @@ -29,11 +29,6 @@ protected $query; /** - * @var \Drupal\migrate\Entity\MigrationInterface - */ - protected $migration; - - /** * @var \Drupal\Core\Database\Connection */ protected $database; only in patch2: unchanged: --- a/core/modules/migrate/tests/src/Unit/MigrateSourceTest.php +++ b/core/modules/migrate/tests/src/Unit/MigrateSourceTest.php @@ -238,8 +238,11 @@ public function testNewHighwater() { * The migrate executable. */ protected function getMigrateExecutable($migration) { + /** @var \Drupal\migrate\MigrateMessageInterface $message */ $message = $this->getMock('Drupal\migrate\MigrateMessageInterface'); - return new MigrateExecutable($migration, $message); + /** @var \Symfony\Component\EventDispatcher\EventDispatcherInterface $event_dispatcher */ + $event_dispatcher = $this->getMock('Symfony\Component\EventDispatcher\EventDispatcherInterface'); + return new MigrateExecutable($migration, $message, $event_dispatcher); } } only in patch2: unchanged: --- a/core/modules/migrate/tests/src/Unit/TestSqlIdMap.php +++ b/core/modules/migrate/tests/src/Unit/TestSqlIdMap.php @@ -12,6 +12,7 @@ use Drupal\migrate\Entity\MigrationInterface; use Drupal\migrate\MigrateException; use Drupal\migrate\Plugin\migrate\id_map\Sql; +use Symfony\Component\EventDispatcher\EventDispatcherInterface; /** * Defines a SQL ID map for use in tests. @@ -32,9 +33,9 @@ class TestSqlIdMap extends Sql implements \Iterator { * @param \Drupal\migrate\Entity\MigrationInterface $migration * The migration to do. */ - public function __construct(Connection $database, array $configuration, $plugin_id, $plugin_definition, MigrationInterface $migration) { + public function __construct(Connection $database, array $configuration, $plugin_id, $plugin_definition, MigrationInterface $migration, EventDispatcherInterface $event_dispatcher) { $this->database = $database; - parent::__construct($configuration, $plugin_id, $plugin_definition, $migration); + parent::__construct($configuration, $plugin_id, $plugin_definition, $migration, $event_dispatcher); } /** only in patch2: unchanged: --- a/core/modules/migrate/tests/src/Unit/process/IteratorTest.php +++ b/core/modules/migrate/tests/src/Unit/process/IteratorTest.php @@ -61,7 +61,8 @@ public function testIterator() { $migration->expects($this->at(2)) ->method('getProcessPlugins') ->will($this->returnValue($key_plugin)); - $migrate_executable = new MigrateExecutable($migration, $this->getMock('Drupal\migrate\MigrateMessageInterface')); + $event_dispatcher = $this->getMock('Symfony\Component\EventDispatcher\EventDispatcherInterface'); + $migrate_executable = new MigrateExecutable($migration, $this->getMock('Drupal\migrate\MigrateMessageInterface'), $event_dispatcher); // The current value of the pipeline. $current_value = array(