diff --git a/core/modules/aggregator/migration_templates/d6_aggregator_item.yml b/core/modules/aggregator/migration_templates/d6_aggregator_item.yml index fb4040ab1240b17bcb11813617bcfb434430ca74..e14dbd60ed59b7357ccaeaff005f4a0269f485d8 100644 --- a/core/modules/aggregator/migration_templates/d6_aggregator_item.yml +++ b/core/modules/aggregator/migration_templates/d6_aggregator_item.yml @@ -7,7 +7,7 @@ source: process: iid: iid fid: - plugin: migration + plugin: migration_lookup migration: d6_aggregator_feed source: fid title: title diff --git a/core/modules/aggregator/migration_templates/d7_aggregator_item.yml b/core/modules/aggregator/migration_templates/d7_aggregator_item.yml index 9735e19da21fdee5f8ff0ef6da7cbe0d0e4770f2..054ba439f5db97f2180b100edaa20c457d368163 100644 --- a/core/modules/aggregator/migration_templates/d7_aggregator_item.yml +++ b/core/modules/aggregator/migration_templates/d7_aggregator_item.yml @@ -7,7 +7,7 @@ source: process: iid: iid fid: - plugin: migration + plugin: migration_lookup migration: d7_aggregator_feed source: fid title: title diff --git a/core/modules/block_content/migration_templates/d6_custom_block.yml b/core/modules/block_content/migration_templates/d6_custom_block.yml index 8394c64488b9f9717d1fff98783358046ca63f4b..55fbcb5c9dc8119579b690c5e7344d1fe64f1b15 100644 --- a/core/modules/block_content/migration_templates/d6_custom_block.yml +++ b/core/modules/block_content/migration_templates/d6_custom_block.yml @@ -8,7 +8,7 @@ process: id: bid info: info 'body/format': - plugin: migration + plugin: migration_lookup migration: d6_filter_format source: format 'body/value': body diff --git a/core/modules/block_content/migration_templates/d7_custom_block.yml b/core/modules/block_content/migration_templates/d7_custom_block.yml index 42021fb2f0e4c8fbe884208714af11cdaf398086..ca06cf04f91a35a9780a521872707ce80a63dc1f 100644 --- a/core/modules/block_content/migration_templates/d7_custom_block.yml +++ b/core/modules/block_content/migration_templates/d7_custom_block.yml @@ -8,7 +8,7 @@ process: id: bid info: info 'body/format': - plugin: migration + plugin: migration_lookup migration: d7_filter_format source: format 'body/value': body diff --git a/core/modules/book/migration_templates/d6_book.yml b/core/modules/book/migration_templates/d6_book.yml index f5020c3604169a7b75510681cb8f1d9f93fad125..94d7a8f0c429501b47e5060f260b1c6abd922302 100644 --- a/core/modules/book/migration_templates/d6_book.yml +++ b/core/modules/book/migration_templates/d6_book.yml @@ -14,7 +14,7 @@ process: method: process source: plid - - plugin: migration + plugin: migration_lookup migration: d6_book destination: plugin: book diff --git a/core/modules/comment/migration_templates/d6_comment.yml b/core/modules/comment/migration_templates/d6_comment.yml index f4dff98e29022e645f44f0d90a44ad2f2480f8d9..06820d462a5d1aa6ac2ab276a101b1709fae6fb5 100644 --- a/core/modules/comment/migration_templates/d6_comment.yml +++ b/core/modules/comment/migration_templates/d6_comment.yml @@ -11,7 +11,7 @@ process: # the cid field to allow incremental migrations. cid: cid pid: - plugin: migration + plugin: migration_lookup migration: d6_comment source: pid entity_id: nid @@ -32,7 +32,7 @@ process: thread: thread 'comment_body/value': comment 'comment_body/format': - plugin: migration + plugin: migration_lookup migration: d6_filter_format source: format destination: diff --git a/core/modules/comment/migration_templates/d7_comment.yml b/core/modules/comment/migration_templates/d7_comment.yml index d4e3c57cb1b887f77d93da5882d21fef05b147d1..94a28844770caeca3e9dc5dc998a1734c2adceb4 100644 --- a/core/modules/comment/migration_templates/d7_comment.yml +++ b/core/modules/comment/migration_templates/d7_comment.yml @@ -11,7 +11,7 @@ process: # the cid field to allow incremental migrations. cid: cid pid: - plugin: migration + plugin: migration_lookup migration: d7_comment source: pid entity_id: nid diff --git a/core/modules/contact/migration_templates/d6_contact_settings.yml b/core/modules/contact/migration_templates/d6_contact_settings.yml index 452ebb236416cee17e0048f9b1429f68484bb1ec..dbe020581e104e35cc891e7fb0dd5479f5abe482 100644 --- a/core/modules/contact/migration_templates/d6_contact_settings.yml +++ b/core/modules/contact/migration_templates/d6_contact_settings.yml @@ -11,7 +11,7 @@ process: user_default_enabled: contact_default_status 'flood/limit': contact_hourly_threshold default_form: - plugin: migration + plugin: migration_lookup migration: contact_category source: default_category destination: diff --git a/core/modules/contact/migration_templates/d7_contact_settings.yml b/core/modules/contact/migration_templates/d7_contact_settings.yml index a0f3a3b51a40cfecfae583307d254aa8ffdfd66d..9feebe53090d98d91b3f1a2732641c985311c99f 100644 --- a/core/modules/contact/migration_templates/d7_contact_settings.yml +++ b/core/modules/contact/migration_templates/d7_contact_settings.yml @@ -11,7 +11,7 @@ process: user_default_enabled: contact_default_status 'flood/limit': contact_threshold_limit default_form: - plugin: migration + plugin: migration_lookup migration: contact_category source: default_category destination: diff --git a/core/modules/field/migration_templates/d6_field_formatter_settings.yml b/core/modules/field/migration_templates/d6_field_formatter_settings.yml index 7496db3931741a06ff46cda538421a45e964d432..d60449184bb412dbc285405b16ec7f0704e7d2bb 100644 --- a/core/modules/field/migration_templates/d6_field_formatter_settings.yml +++ b/core/modules/field/migration_templates/d6_field_formatter_settings.yml @@ -15,7 +15,7 @@ process: # field migration. field_type_exists: - - plugin: migration + plugin: migration_lookup migration: d6_field source: - field_name @@ -29,7 +29,7 @@ process: entity_type: 'constants/entity_type' bundle: - - plugin: migration + plugin: migration_lookup migration: d6_node_type source: type_name - @@ -37,7 +37,7 @@ process: method: row view_mode: - - plugin: migration + plugin: migration_lookup migration: d6_view_modes source: - view_mode diff --git a/core/modules/field/migration_templates/d6_field_instance.yml b/core/modules/field/migration_templates/d6_field_instance.yml index b5035c2a579b51a50b363a9c122a3b40ae20953a..19343035cba70b8fefa06ca489ef132409805812 100644 --- a/core/modules/field/migration_templates/d6_field_instance.yml +++ b/core/modules/field/migration_templates/d6_field_instance.yml @@ -14,7 +14,7 @@ process: # field migration. field_type_exists: - - plugin: migration + plugin: migration_lookup migration: d6_field source: - field_name @@ -29,7 +29,7 @@ process: field_name: field_name bundle: - - plugin: migration + plugin: migration_lookup migration: d6_node_type source: type_name - diff --git a/core/modules/field/migration_templates/d6_field_instance_widget_settings.yml b/core/modules/field/migration_templates/d6_field_instance_widget_settings.yml index 8b1fb47ca10680b696bae31169e50330112ad7c2..90009b7df98e3ab43ee3406e99a21a20939c1051 100644 --- a/core/modules/field/migration_templates/d6_field_instance_widget_settings.yml +++ b/core/modules/field/migration_templates/d6_field_instance_widget_settings.yml @@ -16,7 +16,7 @@ process: # field migration. field_type_exists: - - plugin: migration + plugin: migration_lookup migration: d6_field source: - field_name @@ -29,7 +29,7 @@ process: method: row bundle: - - plugin: migration + plugin: migration_lookup migration: d6_node_type source: type_name - diff --git a/core/modules/field/migration_templates/d7_field_formatter_settings.yml b/core/modules/field/migration_templates/d7_field_formatter_settings.yml index 14cdd661ab3a142094a4aea20cd660aedce42a8b..126fd29a20b05af3d33dcb61f3403e598bdb85c4 100644 --- a/core/modules/field/migration_templates/d7_field_formatter_settings.yml +++ b/core/modules/field/migration_templates/d7_field_formatter_settings.yml @@ -13,7 +13,7 @@ process: # field migration. field_type_exists: - - plugin: migration + plugin: migration_lookup migration: d7_field source: - field_name @@ -29,7 +29,7 @@ process: bundle: bundle view_mode: - - plugin: migration + plugin: migration_lookup migration: d7_view_modes source: - entity_type diff --git a/core/modules/field/migration_templates/d7_field_instance_widget_settings.yml b/core/modules/field/migration_templates/d7_field_instance_widget_settings.yml index b5ee4170107641ba61b432e03ffa50423403a69d..e2bbcf4496d8490af72a064c0136c380d86b8313 100644 --- a/core/modules/field/migration_templates/d7_field_instance_widget_settings.yml +++ b/core/modules/field/migration_templates/d7_field_instance_widget_settings.yml @@ -14,7 +14,7 @@ process: # field migration. field_type_exists: - - plugin: migration + plugin: migration_lookup migration: d7_field source: - field_name diff --git a/core/modules/file/migration_templates/d6_upload.yml b/core/modules/file/migration_templates/d6_upload.yml index 75164a89972d88cfcdb63379a973ca1eaf89218e..8289d563d36486febbb0cd53098f510f90615f42 100644 --- a/core/modules/file/migration_templates/d6_upload.yml +++ b/core/modules/file/migration_templates/d6_upload.yml @@ -13,7 +13,7 @@ process: source: upload process: target_id: - plugin: migration + plugin: migration_lookup migration: d6_file source: fid display: list diff --git a/core/modules/file/migration_templates/d6_upload_field_instance.yml b/core/modules/file/migration_templates/d6_upload_field_instance.yml index 5bd7c9a2c5891d9407341185eb192850a5cd3cc5..732153a0438fda3edaf6b8c400a4c29abd8e40ab 100644 --- a/core/modules/file/migration_templates/d6_upload_field_instance.yml +++ b/core/modules/file/migration_templates/d6_upload_field_instance.yml @@ -13,7 +13,7 @@ process: entity_type: 'constants/entity_type' bundle: - - plugin: migration + plugin: migration_lookup migration: d6_node_type source: node_type - diff --git a/core/modules/forum/migration_templates/d6_forum_settings.yml b/core/modules/forum/migration_templates/d6_forum_settings.yml index 5516848e42a21bec97a3de7a006caf62c746cf03..18ba8d403f6d75dd28dafd8ccb9a0f5a30492d9d 100644 --- a/core/modules/forum/migration_templates/d6_forum_settings.yml +++ b/core/modules/forum/migration_templates/d6_forum_settings.yml @@ -18,7 +18,7 @@ process: 'topics/page_limit': forum_per_page 'topics/order': forum_order vocabulary: - plugin: migration + plugin: migration_lookup migration: d6_taxonomy_vocabulary source: forum_nav_vocabulary destination: diff --git a/core/modules/forum/migration_templates/d7_forum_settings.yml b/core/modules/forum/migration_templates/d7_forum_settings.yml index b84d485989960d26e5f635f4df10f6ce3e90acf2..086d3e6fc91c7921e2d0cbef78c105f0996473a8 100644 --- a/core/modules/forum/migration_templates/d7_forum_settings.yml +++ b/core/modules/forum/migration_templates/d7_forum_settings.yml @@ -18,7 +18,7 @@ process: 'topics/page_limit': forum_per_page 'topics/order': forum_order vocabulary: - plugin: migration + plugin: migration_lookup migration: d7_taxonomy_vocabulary source: forum_nav_vocabulary destination: diff --git a/core/modules/menu_link_content/migration_templates/d6_menu_links.yml b/core/modules/menu_link_content/migration_templates/d6_menu_links.yml index c418bfebdd29d655ecc54586f31fa45b68e0563e..2c8ad4a45a039069e1870caf868cfeffd7a42adb 100644 --- a/core/modules/menu_link_content/migration_templates/d6_menu_links.yml +++ b/core/modules/menu_link_content/migration_templates/d6_menu_links.yml @@ -10,7 +10,7 @@ process: description: description menu_name: - - plugin: migration + plugin: migration_lookup # The menu migration is in the system module. migration: d6_menu source: menu_name diff --git a/core/modules/menu_link_content/migration_templates/d7_menu_links.yml b/core/modules/menu_link_content/migration_templates/d7_menu_links.yml index 7f049f7acf771b082a479117c950c3b0eee4f700..200a79204791008c5e40a8e00aa4f65d34f42ab1 100644 --- a/core/modules/menu_link_content/migration_templates/d7_menu_links.yml +++ b/core/modules/menu_link_content/migration_templates/d7_menu_links.yml @@ -13,7 +13,7 @@ process: description: description menu_name: - - plugin: migration + plugin: migration_lookup migration: d7_menu source: menu_name - diff --git a/core/modules/migrate/src/Plugin/migrate/process/DefaultValue.php b/core/modules/migrate/src/Plugin/migrate/process/DefaultValue.php index 5829f7473a5fad91de62529c269826d1ccdc7902..a5e63888e2e6d6fc2a37a0877fedb0306d112056 100644 --- a/core/modules/migrate/src/Plugin/migrate/process/DefaultValue.php +++ b/core/modules/migrate/src/Plugin/migrate/process/DefaultValue.php @@ -27,7 +27,7 @@ * process: * uid: * - - * plugin: migration + * plugin: migration_lookup * migration: users * source: author * - diff --git a/core/modules/migrate/src/Plugin/migrate/process/Migration.php b/core/modules/migrate/src/Plugin/migrate/process/Migration.php index e07505ff597a18db573de7bd4374a1ab20ed4bb9..1b4160a3e32bbd6e6dd06ce55107c4b2f739d355 100644 --- a/core/modules/migrate/src/Plugin/migrate/process/Migration.php +++ b/core/modules/migrate/src/Plugin/migrate/process/Migration.php @@ -2,16 +2,8 @@ namespace Drupal\migrate\Plugin\migrate\process; -use Drupal\Core\Plugin\ContainerFactoryPluginInterface; -use Drupal\migrate\MigrateSkipProcessException; -use Drupal\migrate\Plugin\MigratePluginManagerInterface; -use Drupal\migrate\Plugin\MigrationPluginManagerInterface; -use Drupal\migrate\Plugin\MigrateIdMapInterface; -use Drupal\migrate\ProcessPluginBase; -use Drupal\migrate\Plugin\MigrationInterface; -use Drupal\migrate\MigrateExecutableInterface; -use Drupal\migrate\Row; -use Symfony\Component\DependencyInjection\ContainerInterface; +@trigger_error('The ' . __NAMESPACE__ . '\Migration is deprecated in +Drupal 8.4.0 and will be removed before Drupal 9.0.0. Instead, use ' . __NAMESPACE__ . '\MigrationLookup', E_USER_DEPRECATED); /** * Calculates the value of a property based on a previous migration. @@ -21,156 +13,8 @@ * @MigrateProcessPlugin( * id = "migration" * ) + * + * @deprecated in Drupal 8.3.x and will be removed in Drupal 9.0.x. + * Use \Drupal\migrate\Plugin\migrate\process\MigrationLookup instead. */ -class Migration extends ProcessPluginBase implements ContainerFactoryPluginInterface { - - /** - * The process plugin manager. - * - * @var \Drupal\migrate\Plugin\MigratePluginManager - */ - protected $processPluginManager; - - /** - * The migration plugin manager. - * - * @var \Drupal\migrate\Plugin\MigrationPluginManagerInterface - */ - protected $migrationPluginManager; - - /** - * The migration to be executed. - * - * @var \Drupal\migrate\Plugin\MigrationInterface - */ - protected $migration; - - /** - * {@inheritdoc} - */ - public function __construct(array $configuration, $plugin_id, $plugin_definition, MigrationInterface $migration, MigrationPluginManagerInterface $migration_plugin_manager, MigratePluginManagerInterface $process_plugin_manager) { - parent::__construct($configuration, $plugin_id, $plugin_definition); - $this->migrationPluginManager = $migration_plugin_manager; - $this->migration = $migration; - $this->processPluginManager = $process_plugin_manager; - } - - /** - * {@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('plugin.manager.migration'), - $container->get('plugin.manager.migrate.process') - ); - } - - /** - * {@inheritdoc} - */ - public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) { - $migration_ids = $this->configuration['migration']; - if (!is_array($migration_ids)) { - $migration_ids = [$migration_ids]; - } - if (!is_array($value)) { - $value = [$value]; - } - $this->skipOnEmpty($value); - $self = FALSE; - /** @var \Drupal\migrate\Plugin\MigrationInterface[] $migrations */ - $destination_ids = NULL; - $source_id_values = []; - $migrations = $this->migrationPluginManager->createInstances($migration_ids); - foreach ($migrations as $migration_id => $migration) { - if ($migration_id == $this->migration->id()) { - $self = TRUE; - } - if (isset($this->configuration['source_ids'][$migration_id])) { - $configuration = ['source' => $this->configuration['source_ids'][$migration_id]]; - $source_id_values[$migration_id] = $this->processPluginManager - ->createInstance('get', $configuration, $this->migration) - ->transform(NULL, $migrate_executable, $row, $destination_property); - } - else { - $source_id_values[$migration_id] = $value; - } - // Break out of the loop as soon as a destination ID is found. - if ($destination_ids = $migration->getIdMap()->lookupDestinationId($source_id_values[$migration_id])) { - break; - } - } - - if (!$destination_ids && !empty($this->configuration['no_stub'])) { - return NULL; - } - - if (!$destination_ids && ($self || isset($this->configuration['stub_id']) || count($migrations) == 1)) { - // If the lookup didn't succeed, figure out which migration will do the - // stubbing. - if ($self) { - $migration = $this->migration; - } - elseif (isset($this->configuration['stub_id'])) { - $migration = $migrations[$this->configuration['stub_id']]; - } - else { - $migration = reset($migrations); - } - $destination_plugin = $migration->getDestinationPlugin(TRUE); - // Only keep the process necessary to produce the destination ID. - $process = $migration->getProcess(); - - // We already have the source ID values but need to key them for the Row - // constructor. - $source_ids = $migration->getSourcePlugin()->getIds(); - $values = []; - foreach (array_keys($source_ids) as $index => $source_id) { - $values[$source_id] = $source_id_values[$migration->id()][$index]; - } - - $stub_row = new Row($values + $migration->getSourceConfiguration(), $source_ids, TRUE); - - // Do a normal migration with the stub row. - $migrate_executable->processRow($stub_row, $process); - $destination_ids = []; - try { - $destination_ids = $destination_plugin->import($stub_row); - } - catch (\Exception $e) { - $migration->getIdMap()->saveMessage($stub_row->getSourceIdValues(), $e->getMessage()); - } - - if ($destination_ids) { - $migration->getIdMap()->saveIdMapping($stub_row, $destination_ids, MigrateIdMapInterface::STATUS_NEEDS_UPDATE); - } - } - if ($destination_ids) { - if (count($destination_ids) == 1) { - return reset($destination_ids); - } - else { - return $destination_ids; - } - } - } - - /** - * Skips the migration process entirely if the value is FALSE. - * - * @param mixed $value - * The incoming value to transform. - * - * @throws \Drupal\migrate\MigrateSkipProcessException - */ - protected function skipOnEmpty(array $value) { - if (!array_filter($value)) { - throw new MigrateSkipProcessException(); - } - } - -} +class Migration extends MigrationLookup { } diff --git a/core/modules/migrate/src/Plugin/migrate/process/MigrationLookup.php b/core/modules/migrate/src/Plugin/migrate/process/MigrationLookup.php new file mode 100644 index 0000000000000000000000000000000000000000..f387df5233fdb7613aa3c806faf5e541401afc0f --- /dev/null +++ b/core/modules/migrate/src/Plugin/migrate/process/MigrationLookup.php @@ -0,0 +1,260 @@ +migrationPluginManager = $migration_plugin_manager; + $this->migration = $migration; + $this->processPluginManager = $process_plugin_manager; + } + + /** + * {@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('plugin.manager.migration'), + $container->get('plugin.manager.migrate.process') + ); + } + + /** + * {@inheritdoc} + */ + public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) { + $migration_ids = $this->configuration['migration']; + if (!is_array($migration_ids)) { + $migration_ids = [$migration_ids]; + } + if (!is_array($value)) { + $value = [$value]; + } + $this->skipOnEmpty($value); + $self = FALSE; + /** @var \Drupal\migrate\Plugin\MigrationInterface[] $migrations */ + $destination_ids = NULL; + $source_id_values = []; + $migrations = $this->migrationPluginManager->createInstances($migration_ids); + foreach ($migrations as $migration_id => $migration) { + if ($migration_id == $this->migration->id()) { + $self = TRUE; + } + if (isset($this->configuration['source_ids'][$migration_id])) { + $configuration = ['source' => $this->configuration['source_ids'][$migration_id]]; + $source_id_values[$migration_id] = $this->processPluginManager + ->createInstance('get', $configuration, $this->migration) + ->transform(NULL, $migrate_executable, $row, $destination_property); + } + else { + $source_id_values[$migration_id] = $value; + } + // Break out of the loop as soon as a destination ID is found. + if ($destination_ids = $migration->getIdMap()->lookupDestinationId($source_id_values[$migration_id])) { + break; + } + } + + if (!$destination_ids && !empty($this->configuration['no_stub'])) { + return NULL; + } + + if (!$destination_ids && ($self || isset($this->configuration['stub_id']) || count($migrations) == 1)) { + // If the lookup didn't succeed, figure out which migration will do the + // stubbing. + if ($self) { + $migration = $this->migration; + } + elseif (isset($this->configuration['stub_id'])) { + $migration = $migrations[$this->configuration['stub_id']]; + } + else { + $migration = reset($migrations); + } + $destination_plugin = $migration->getDestinationPlugin(TRUE); + // Only keep the process necessary to produce the destination ID. + $process = $migration->getProcess(); + + // We already have the source ID values but need to key them for the Row + // constructor. + $source_ids = $migration->getSourcePlugin()->getIds(); + $values = []; + foreach (array_keys($source_ids) as $index => $source_id) { + $values[$source_id] = $source_id_values[$migration->id()][$index]; + } + + $stub_row = new Row($values + $migration->getSourceConfiguration(), $source_ids, TRUE); + + // Do a normal migration with the stub row. + $migrate_executable->processRow($stub_row, $process); + $destination_ids = []; + try { + $destination_ids = $destination_plugin->import($stub_row); + } + catch (\Exception $e) { + $migration->getIdMap()->saveMessage($stub_row->getSourceIdValues(), $e->getMessage()); + } + + if ($destination_ids) { + $migration->getIdMap()->saveIdMapping($stub_row, $destination_ids, MigrateIdMapInterface::STATUS_NEEDS_UPDATE); + } + } + if ($destination_ids) { + if (count($destination_ids) == 1) { + return reset($destination_ids); + } + else { + return $destination_ids; + } + } + } + + /** + * Skips the migration process entirely if the value is FALSE. + * + * @param mixed $value + * The incoming value to transform. + * + * @throws \Drupal\migrate\MigrateSkipProcessException + */ + protected function skipOnEmpty(array $value) { + if (!array_filter($value)) { + throw new MigrateSkipProcessException(); + } + } + +} diff --git a/core/modules/migrate/tests/modules/migrate_external_translated_test/migrations/migrate.migration.external_translated_test_node_translation.yml b/core/modules/migrate/tests/modules/migrate_external_translated_test/migrations/migrate.migration.external_translated_test_node_translation.yml index ff29084fb911fe205d4e021d545e2404f6e4cd9b..0363aa20214b1f49550a041fc1d420aab7208488 100644 --- a/core/modules/migrate/tests/modules/migrate_external_translated_test/migrations/migrate.migration.external_translated_test_node_translation.yml +++ b/core/modules/migrate/tests/modules/migrate_external_translated_test/migrations/migrate.migration.external_translated_test_node_translation.yml @@ -7,7 +7,7 @@ source: type: external_test process: nid: - plugin: migration + plugin: migration_lookup source: name migration: external_translated_test_node type: constants/type diff --git a/core/modules/migrate/tests/src/Unit/process/MigrationLookupTest.php b/core/modules/migrate/tests/src/Unit/process/MigrationLookupTest.php new file mode 100644 index 0000000000000000000000000000000000000000..f30c184458da96031b37731da6e070e33920b969 --- /dev/null +++ b/core/modules/migrate/tests/src/Unit/process/MigrationLookupTest.php @@ -0,0 +1,202 @@ +prophesize(MigrationInterface::class); + $migration_plugin_manager = $this->prophesize(MigrationPluginManagerInterface::class); + $process_plugin_manager = $this->prophesize(MigratePluginManager::class); + + $destination_id_map = $this->prophesize(MigrateIdMapInterface::class); + $destination_migration = $this->prophesize(MigrationInterface::class); + $destination_migration->getIdMap()->willReturn($destination_id_map->reveal()); + $destination_id_map->lookupDestinationId([1])->willReturn(NULL); + + // Ensure the migration plugin manager returns our migration. + $migration_plugin_manager->createInstances(Argument::exact(['destination_migration'])) + ->willReturn(['destination_migration' => $destination_migration->reveal()]); + + $configuration = [ + 'no_stub' => TRUE, + 'migration' => 'destination_migration', + ]; + + $migration_plugin->id()->willReturn('actual_migration'); + $destination_migration->getDestinationPlugin(TRUE)->shouldNotBeCalled(); + + $migration = new MigrationLookup($configuration, '', [], $migration_plugin->reveal(), $migration_plugin_manager->reveal(), $process_plugin_manager->reveal()); + $result = $migration->transform(1, $this->migrateExecutable, $this->row, ''); + $this->assertNull($result); + } + + /** + * @covers ::transform + */ + public function testTransformWithStubbing() { + $migration_plugin = $this->prophesize(MigrationInterface::class); + $migration_plugin_manager = $this->prophesize(MigrationPluginManagerInterface::class); + $process_plugin_manager = $this->prophesize(MigratePluginManager::class); + + $destination_id_map = $this->prophesize(MigrateIdMapInterface::class); + $destination_migration = $this->prophesize('Drupal\migrate\Plugin\Migration'); + $destination_migration->getIdMap()->willReturn($destination_id_map->reveal()); + $migration_plugin_manager->createInstances(['destination_migration']) + ->willReturn(['destination_migration' => $destination_migration->reveal()]); + $destination_id_map->lookupDestinationId([1])->willReturn(NULL); + $destination_id_map->saveIdMapping(Argument::any(), Argument::any(), MigrateIdMapInterface::STATUS_NEEDS_UPDATE)->willReturn(NULL); + + $configuration = [ + 'no_stub' => FALSE, + 'migration' => 'destination_migration', + ]; + + $migration_plugin->id()->willReturn('actual_migration'); + $destination_migration->id()->willReturn('destination_migration'); + $destination_migration->getDestinationPlugin(TRUE)->shouldBeCalled(); + $destination_migration->getProcess()->willReturn([]); + $destination_migration->getSourceConfiguration()->willReturn([]); + + $source_plugin = $this->prophesize(MigrateSourceInterface::class); + $source_plugin->getIds()->willReturn(['nid']); + $destination_migration->getSourcePlugin()->willReturn($source_plugin->reveal()); + $destination_plugin = $this->prophesize(MigrateDestinationInterface::class); + $destination_plugin->import(Argument::any())->willReturn([2]); + $destination_migration->getDestinationPlugin(TRUE)->willReturn($destination_plugin->reveal()); + + $migration = new MigrationLookup($configuration, '', [], $migration_plugin->reveal(), $migration_plugin_manager->reveal(), $process_plugin_manager->reveal()); + $result = $migration->transform(1, $this->migrateExecutable, $this->row, ''); + $this->assertEquals(2, $result); + } + + /** + * Tests that processing is skipped when the input value is empty. + */ + public function testSkipOnEmpty() { + $migration_plugin = $this->prophesize(MigrationInterface::class); + $migration_plugin_manager = $this->prophesize(MigrationPluginManagerInterface::class); + $process_plugin_manager = $this->prophesize(MigratePluginManager::class); + + $configuration = [ + 'migration' => 'foobaz', + ]; + $migration_plugin->id()->willReturn(uniqid()); + $migration = new MigrationLookup($configuration, 'migration_lookup', [], $migration_plugin->reveal(), $migration_plugin_manager->reveal(), $process_plugin_manager->reveal()); + $this->setExpectedException(MigrateSkipProcessException::class); + $migration->transform(0, $this->migrateExecutable, $this->row, 'foo'); + } + + /** + * Tests a successful lookup. + * + * @dataProvider successfulLookupDataProvider + * + * @param array $source_id_values + * The source id(s) of the migration map. + * @param array $destination_id_values + * The destination id(s) of the migration map. + * @param string|array $source_value + * The source value(s) for the migration process plugin. + * @param string|array $expected_value + * The expected value(s) of the migration process plugin. + */ + public function testSuccessfulLookup($source_id_values, $destination_id_values, $source_value, $expected_value) { + $migration_plugin = $this->prophesize(MigrationInterface::class); + $migration_plugin_manager = $this->prophesize(MigrationPluginManagerInterface::class); + $process_plugin_manager = $this->prophesize(MigratePluginManager::class); + + $configuration = [ + 'migration' => 'foobaz', + ]; + $migration_plugin->id()->willReturn(uniqid()); + + $id_map = $this->prophesize(MigrateIdMapInterface::class); + $id_map->lookupDestinationId($source_id_values)->willReturn($destination_id_values); + $migration_plugin->getIdMap()->willReturn($id_map->reveal()); + + $migration_plugin_manager->createInstances(['foobaz']) + ->willReturn(['foobaz' => $migration_plugin->reveal()]); + + $migrationStorage = $this->prophesize(EntityStorageInterface::class); + $migrationStorage + ->loadMultiple(['foobaz']) + ->willReturn([$migration_plugin->reveal()]); + + $migration = new MigrationLookup($configuration, 'migration_lookup', [], $migration_plugin->reveal(), $migration_plugin_manager->reveal(), $process_plugin_manager->reveal()); + $this->assertSame($expected_value, $migration->transform($source_value, $this->migrateExecutable, $this->row, 'foo')); + } + + /** + * Provides data for the successful lookup test. + * + * @return array + */ + public function successfulLookupDataProvider() { + return [ + // Test data for scalar to scalar. + [ + // Source ID of the migration map. + [1], + // Destination ID of the migration map. + [3], + // Input value for the migration plugin. + 1, + // Expected output value of the migration plugin. + 3, + ], + // Test data for scalar to array. + [ + // Source ID of the migration map. + [1], + // Destination IDs of the migration map. + [3, 'foo'], + // Input value for the migration plugin. + 1, + // Expected output values of the migration plugin. + [3, 'foo'], + ], + // Test data for array to scalar. + [ + // Source IDs of the migration map. + [1, 3], + // Destination ID of the migration map. + ['foo'], + // Input values for the migration plugin. + [1, 3], + // Expected output value of the migration plugin. + 'foo', + ], + // Test data for array to array. + [ + // Source IDs of the migration map. + [1, 3], + // Destination IDs of the migration map. + [3, 'foo'], + // Input values for the migration plugin. + [1, 3], + // Expected output values of the migration plugin. + [3, 'foo'], + ], + ]; + } + +} diff --git a/core/modules/migrate/tests/src/Unit/process/MigrationTest.php b/core/modules/migrate/tests/src/Unit/process/MigrationTest.php index b571ba618fc497fa7b2eb53757891a41b91b55d1..843d1e558b5df4cdaf1dbe9c29b16e92c49cbadc 100644 --- a/core/modules/migrate/tests/src/Unit/process/MigrationTest.php +++ b/core/modules/migrate/tests/src/Unit/process/MigrationTest.php @@ -2,6 +2,9 @@ namespace Drupal\Tests\migrate\Unit\process; +@trigger_error('The ' . __NAMESPACE__ . '\MigrationTest is deprecated in +Drupal 8.4.0 and will be removed before Drupal 9.0.0. Instead, use ' . __NAMESPACE__ . '\MigrationLookupTest', E_USER_DEPRECATED); + use Drupal\Core\Entity\EntityStorageInterface; use Drupal\migrate\MigrateSkipProcessException; use Drupal\migrate\Plugin\MigrationInterface; @@ -14,6 +17,9 @@ use Prophecy\Argument; /** + * @deprecated in Drupal 8.4.x, to be removed before Drupal 9.0.x. Use + * \Drupal\Tests\migrate\Unit\process\MigrationLookupTest instead. + * * @coversDefaultClass \Drupal\migrate\Plugin\migrate\process\Migration * @group migrate */ diff --git a/core/modules/node/migration_templates/d6_node.yml b/core/modules/node/migration_templates/d6_node.yml index 4e19bb407f7d4602f33e011def4c8980858e0a2a..56d0459a81266cc418ab3a18e784f7c7068b63a8 100644 --- a/core/modules/node/migration_templates/d6_node.yml +++ b/core/modules/node/migration_templates/d6_node.yml @@ -25,7 +25,7 @@ process: promote: promote sticky: sticky 'body/format': - plugin: migration + plugin: migration_lookup migration: d6_filter_format source: format 'body/value': body diff --git a/core/modules/node/migration_templates/d6_node_revision.yml b/core/modules/node/migration_templates/d6_node_revision.yml index 046e9bbe4c56344f1f40a58dc5db78ab65627a63..f4ff3011c41ba0655a0d1bfc3685d0cabdf5d8c2 100644 --- a/core/modules/node/migration_templates/d6_node_revision.yml +++ b/core/modules/node/migration_templates/d6_node_revision.yml @@ -22,7 +22,7 @@ process: promote: promote sticky: sticky 'body/format': - plugin: migration + plugin: migration_lookup migration: d6_filter_format source: format 'body/value': body diff --git a/core/modules/node/migration_templates/d6_node_translation.yml b/core/modules/node/migration_templates/d6_node_translation.yml index 3b923d181ddbed00fbd61b01f17a6e5185db80d5..3eb06e8a7d7a364ee5ee88c7704227a541685ed8 100644 --- a/core/modules/node/migration_templates/d6_node_translation.yml +++ b/core/modules/node/migration_templates/d6_node_translation.yml @@ -23,7 +23,7 @@ process: promote: promote sticky: sticky 'body/format': - plugin: migration + plugin: migration_lookup migration: d6_filter_format source: format 'body/value': body diff --git a/core/modules/path/migration_templates/d6_url_alias.yml b/core/modules/path/migration_templates/d6_url_alias.yml index 968b1e694a03b535a7998cb697e4884a7213c9ed..fcf20364056e794d81aafc8e049b5db4bbcb15d5 100644 --- a/core/modules/path/migration_templates/d6_url_alias.yml +++ b/core/modules/path/migration_templates/d6_url_alias.yml @@ -30,7 +30,7 @@ process: index: - 1 - - plugin: migration + plugin: migration_lookup migration: d6_node_translation destination: plugin: url_alias diff --git a/core/modules/path/migration_templates/d7_url_alias.yml b/core/modules/path/migration_templates/d7_url_alias.yml index 713a34676f7f15778aab33f25fa188dbdedd24ae..dffaf46825d15c214131d7bc1551c679128e4638 100644 --- a/core/modules/path/migration_templates/d7_url_alias.yml +++ b/core/modules/path/migration_templates/d7_url_alias.yml @@ -28,7 +28,7 @@ process: index: - 1 - - plugin: migration + plugin: migration_lookup migration: d7_node_translation destination: plugin: url_alias diff --git a/core/modules/shortcut/migration_templates/d7_shortcut.yml b/core/modules/shortcut/migration_templates/d7_shortcut.yml index da3d894940ff526a90fbf75eaacf1c4326f51174..dac9354338218e48157f2f83334b9081b728f234 100644 --- a/core/modules/shortcut/migration_templates/d7_shortcut.yml +++ b/core/modules/shortcut/migration_templates/d7_shortcut.yml @@ -8,7 +8,7 @@ source: uri_scheme: 'internal:/' process: shortcut_set: - plugin: migration + plugin: migration_lookup migration: d7_shortcut_set source: menu_name title: link_title diff --git a/core/modules/shortcut/migration_templates/d7_shortcut_set_users.yml b/core/modules/shortcut/migration_templates/d7_shortcut_set_users.yml index a93c4bbab0cae28c4caaf3ef5cb7606fc16f0f7c..d0eb219962d611049de2f0c2e0646a51a937545b 100644 --- a/core/modules/shortcut/migration_templates/d7_shortcut_set_users.yml +++ b/core/modules/shortcut/migration_templates/d7_shortcut_set_users.yml @@ -7,14 +7,14 @@ source: process: uid: - - plugin: migration + plugin: migration_lookup migration: d7_user source: uid - plugin: skip_on_empty method: row set_name: - plugin: migration + plugin: migration_lookup migration: d7_shortcut_set source: set_name destination: diff --git a/core/modules/taxonomy/migration_templates/d6_taxonomy_term.yml b/core/modules/taxonomy/migration_templates/d6_taxonomy_term.yml index e5630fc62f783d63e3affb37366fb860209e1a5a..e3c3e3d3420b4fe5a7af62658431ac6c1161477e 100644 --- a/core/modules/taxonomy/migration_templates/d6_taxonomy_term.yml +++ b/core/modules/taxonomy/migration_templates/d6_taxonomy_term.yml @@ -9,7 +9,7 @@ process: # the tid field to allow incremental migrations. tid: tid vid: - plugin: migration + plugin: migration_lookup migration: d6_taxonomy_vocabulary source: vid name: name @@ -22,7 +22,7 @@ process: method: process source: parent - - plugin: migration + plugin: migration_lookup migration: d6_taxonomy_term parent: plugin: default_value diff --git a/core/modules/taxonomy/migration_templates/d6_term_node.yml b/core/modules/taxonomy/migration_templates/d6_term_node.yml index 63aec8563f5df7179759913d14bde65ac1717e4c..846334d4b9ca585ba4e512cb0db391bb0badccb4 100644 --- a/core/modules/taxonomy/migration_templates/d6_term_node.yml +++ b/core/modules/taxonomy/migration_templates/d6_term_node.yml @@ -8,7 +8,7 @@ source: process: nid: - - plugin: migration + plugin: migration_lookup migration: d6_node source: nid - diff --git a/core/modules/taxonomy/migration_templates/d6_term_node_revision.yml b/core/modules/taxonomy/migration_templates/d6_term_node_revision.yml index cf1c6829040acd51e6ad3c8055e7e6c1f76113ca..91c8362e63b887f4bbbe176d992d1cda75712c45 100644 --- a/core/modules/taxonomy/migration_templates/d6_term_node_revision.yml +++ b/core/modules/taxonomy/migration_templates/d6_term_node_revision.yml @@ -8,7 +8,7 @@ source: process: vid: - - plugin: migration + plugin: migration_lookup migration: d6_node source: vid - diff --git a/core/modules/taxonomy/migration_templates/d6_vocabulary_entity_display.yml b/core/modules/taxonomy/migration_templates/d6_vocabulary_entity_display.yml index e8d04c0c6f7bdc402abc45c6cdebe1d6caaa3c47..3c52a2fb04b10c3be4e8bbbb19b5606f41d74b91 100644 --- a/core/modules/taxonomy/migration_templates/d6_vocabulary_entity_display.yml +++ b/core/modules/taxonomy/migration_templates/d6_vocabulary_entity_display.yml @@ -17,7 +17,7 @@ process: options: 'constants/options' bundle: type field_name: - plugin: migration + plugin: migration_lookup migration: d6_taxonomy_vocabulary source: vid destination: diff --git a/core/modules/taxonomy/migration_templates/d6_vocabulary_entity_form_display.yml b/core/modules/taxonomy/migration_templates/d6_vocabulary_entity_form_display.yml index 2608877e9d5e764a2e77be39e71ce3db801a31d9..160f68c34c03af12fc26f2b23eac96bfe9ac0a9a 100644 --- a/core/modules/taxonomy/migration_templates/d6_vocabulary_entity_form_display.yml +++ b/core/modules/taxonomy/migration_templates/d6_vocabulary_entity_form_display.yml @@ -21,7 +21,7 @@ process: options/weight: 'constants/options/weight' bundle: type field_name: - plugin: migration + plugin: migration_lookup migration: d6_taxonomy_vocabulary source: vid destination: diff --git a/core/modules/taxonomy/migration_templates/d6_vocabulary_field.yml b/core/modules/taxonomy/migration_templates/d6_vocabulary_field.yml index 0e1a48728804fa9b22f88b02cb0d3749e1d63f19..082386fdffa6480412bdd4d10be3203642d1d913 100644 --- a/core/modules/taxonomy/migration_templates/d6_vocabulary_field.yml +++ b/core/modules/taxonomy/migration_templates/d6_vocabulary_field.yml @@ -13,7 +13,7 @@ process: type: 'constants/type' field_name: - - plugin: migration + plugin: migration_lookup migration: d6_taxonomy_vocabulary source: vid - diff --git a/core/modules/taxonomy/migration_templates/d6_vocabulary_field_instance.yml b/core/modules/taxonomy/migration_templates/d6_vocabulary_field_instance.yml index a7bbbbbc42ccafcc3f60be66a6610ee225f376d5..a3afd9b9458bf0efb8ca3d53e653db95cc10d2a1 100644 --- a/core/modules/taxonomy/migration_templates/d6_vocabulary_field_instance.yml +++ b/core/modules/taxonomy/migration_templates/d6_vocabulary_field_instance.yml @@ -13,7 +13,7 @@ process: bundle: type field_name: - - plugin: migration + plugin: migration_lookup migration: d6_taxonomy_vocabulary source: vid - diff --git a/core/modules/taxonomy/migration_templates/d7_taxonomy_term.yml b/core/modules/taxonomy/migration_templates/d7_taxonomy_term.yml index af8518006e2e3d2109a41bd902de092fd8796dd7..99004dfed6b7c3d8a7ef679e02735221f3602f4e 100644 --- a/core/modules/taxonomy/migration_templates/d7_taxonomy_term.yml +++ b/core/modules/taxonomy/migration_templates/d7_taxonomy_term.yml @@ -10,7 +10,7 @@ process: # the tid field to allow incremental migrations. tid: tid vid: - plugin: migration + plugin: migration_lookup migration: d7_taxonomy_vocabulary source: vid name: name @@ -24,7 +24,7 @@ process: method: process source: parent - - plugin: migration + plugin: migration_lookup migration: d7_taxonomy_term parent: plugin: default_value diff --git a/core/modules/taxonomy/tests/modules/taxonomy_term_stub_test/migrations/taxonomy_term_stub_test.yml b/core/modules/taxonomy/tests/modules/taxonomy_term_stub_test/migrations/taxonomy_term_stub_test.yml index ad56fff023e63cecc0e20378125c1b276fdb2479..4c3cd86710d6765064c55b1ddd3dd36c558713a6 100644 --- a/core/modules/taxonomy/tests/modules/taxonomy_term_stub_test/migrations/taxonomy_term_stub_test.yml +++ b/core/modules/taxonomy/tests/modules/taxonomy_term_stub_test/migrations/taxonomy_term_stub_test.yml @@ -19,7 +19,7 @@ process: name: name weight: weight parent: - plugin: migration + plugin: migration_lookup migration: taxonomy_term_stub_test source: parent destination: diff --git a/core/modules/user/migration_templates/d6_user.yml b/core/modules/user/migration_templates/d6_user.yml index c82c65750981c1daab87b3a65990a02bd9a97245..d58607b1507cee97bc13b3d27b0dc9791d6551a5 100644 --- a/core/modules/user/migration_templates/d6_user.yml +++ b/core/modules/user/migration_templates/d6_user.yml @@ -32,11 +32,11 @@ process: fallback_to_site_default: true init: init roles: - plugin: migration + plugin: migration_lookup migration: d6_user_role source: roles user_picture: - plugin: migration + plugin: migration_lookup migration: d6_user_picture_file source: uid no_stub: true diff --git a/core/modules/user/migration_templates/d7_user.yml b/core/modules/user/migration_templates/d7_user.yml index d68e2971e777defc349a682fcec31a0fc37d02f8..ae523844b122ee9a80dc1b33301259b8a27ce8a8 100644 --- a/core/modules/user/migration_templates/d7_user.yml +++ b/core/modules/user/migration_templates/d7_user.yml @@ -31,7 +31,7 @@ process: fallback_to_site_default: true init: init roles: - plugin: migration + plugin: migration_lookup migration: d7_user_role source: roles user_picture: @@ -40,7 +40,7 @@ process: source: picture default_value: null - - plugin: migration + plugin: migration_lookup migration: d7_file destination: plugin: entity:user