diff --git a/core/modules/migrate_drupal/src/Plugin/MigrationWithFollowUpInterface.php b/core/modules/migrate_drupal/src/Plugin/MigrationWithFollowUpInterface.php index ec540f647e..93ef8f9117 100644 --- a/core/modules/migrate_drupal/src/Plugin/MigrationWithFollowUpInterface.php +++ b/core/modules/migrate_drupal/src/Plugin/MigrationWithFollowUpInterface.php @@ -8,10 +8,10 @@ * Some migrations need to be derived and executed after other migrations have * been successfully executed. For example, a migration might need to be derived * based on previously migrated data. For such a case, the migration dependency - * system is not enough since all migration would still be derived before any + * system is not enough since all migrations would still be derived before any * one of them has been executed. * - * Those "follow-up" migrations need to be taged with the "Follow-up migration" + * Those "follow-up" migrations need to be tagged with the "Follow-up migration" * tag (or any tag in the "follow_up_migration_tags" configuration) and thus * they won't be derived with the other migrations. * diff --git a/core/modules/migrate_drupal/src/Plugin/migrate/EntityReferenceTranslationDeriver.php b/core/modules/migrate_drupal/src/Plugin/migrate/EntityReferenceTranslationDeriver.php index ea1f953269..d81b92cc10 100644 --- a/core/modules/migrate_drupal/src/Plugin/migrate/EntityReferenceTranslationDeriver.php +++ b/core/modules/migrate_drupal/src/Plugin/migrate/EntityReferenceTranslationDeriver.php @@ -48,13 +48,6 @@ class EntityReferenceTranslationDeriver extends DeriverBase implements Container use StringTranslationTrait; /** - * The base plugin ID this derivative is for. - * - * @var string - */ - protected $basePluginId; - - /** * The entity field manager. * * @var \Drupal\Core\Entity\EntityFieldManagerInterface @@ -79,7 +72,6 @@ class EntityReferenceTranslationDeriver extends DeriverBase implements Container * The entity type manager. */ public function __construct($base_plugin_id, EntityFieldManagerInterface $entity_field_manager, EntityTypeManagerInterface $entity_type_manager) { - $this->basePluginId = $base_plugin_id; $this->entityFieldManager = $entity_field_manager; $this->entityTypeManager = $entity_type_manager; } @@ -109,7 +101,7 @@ public function getDerivativeDefinitions($base_plugin_definition) { $target_type = $field_definitions[$field_name]->getSetting('target_type'); // If the field's target type is not supported, skip it. - if (!in_array($target_type, array_keys($base_plugin_definition['target_types']), TRUE)) { + if (!array_key_exists($target_type, $base_plugin_definition['target_types'])) { continue; } @@ -150,7 +142,7 @@ public function getDerivativeDefinitions($base_plugin_definition) { // Allow overwriting the entity reference field so we can update its // values with the ones found in the mapping table. - $derivative['destination']['overwrite_properties'][] = $field_name; + $derivative['destination']['overwrite_properties'][$field_name] = $field_name; // Add the entity reference field to the process pipeline. $derivative['process'][$field_name] = [ @@ -176,11 +168,16 @@ public function getDerivativeDefinitions($base_plugin_definition) { ], ]; - if (isset($this->derivatives[$derivative_key])) { - $this->derivatives[$derivative_key] += $derivative; + if (!isset($this->derivatives[$derivative_key])) { + // If this is a new derivative, add it to the returned derivatives. + $this->derivatives[$derivative_key] = $derivative; } else { - $this->derivatives[$derivative_key] = $derivative; + // If this is an existing derivative, it means this bundle has more + // than one entity reference field. In that case, we only want to add + // the field to the process pipeline and make it overwritable. + $this->derivatives[$derivative_key]['process'] += $derivative['process']; + $this->derivatives[$derivative_key]['destination']['overwrite_properties'] += $derivative['destination']['overwrite_properties']; } } } diff --git a/core/modules/migrate_drupal/tests/fixtures/drupal6.php b/core/modules/migrate_drupal/tests/fixtures/drupal6.php index d280af3256..7b0eba3e03 100644 --- a/core/modules/migrate_drupal/tests/fixtures/drupal6.php +++ b/core/modules/migrate_drupal/tests/fixtures/drupal6.php @@ -2765,6 +2765,18 @@ 'locked' => '0', )) ->values(array( + 'field_name' => 'field_reference_2', + 'type' => 'nodereference', + 'global_settings' => 'a:1:{s:19:"referenceable_types";a:11:{s:4:"page";s:4:"page";s:7:"article";i:0;s:7:"company";i:0;s:8:"employee";i:0;s:5:"forum";i:0;s:10:"test_event";i:0;s:9:"test_page";i:0;s:11:"test_planet";i:0;s:10:"test_story";i:0;s:7:"sponsor";i:0;s:5:"story";i:0;}}', + 'required' => '0', + 'multiple' => '0', + 'db_storage' => '1', + 'module' => 'nodereference', + 'db_columns' => 'a:1:{s:3:"nid";a:4:{s:4:"type";s:3:"int";s:8:"unsigned";b:1;s:8:"not null";b:0;s:5:"index";b:1;}}', + 'active' => '1', + 'locked' => '0', +)) +->values(array( 'field_name' => 'field_test', 'type' => 'text', 'global_settings' => 'a:4:{s:15:"text_processing";s:1:"1";s:10:"max_length";s:0:"";s:14:"allowed_values";s:0:"";s:18:"allowed_values_php";s:0:"";}', @@ -3159,6 +3171,18 @@ 'widget_active' => '1', )) ->values(array( + 'field_name' => 'field_reference_2', + 'type_name' => 'page', + 'weight' => '32', + 'label' => 'Reference', + 'widget_type' => 'nodereference_select', + 'widget_settings' => 'a:4:{s:18:"autocomplete_match";s:8:"contains";s:4:"size";i:60;s:13:"default_value";a:1:{i:0;a:1:{s:3:"nid";s:0:"";}}s:17:"default_value_php";N;}', + 'display_settings' => 'a:5:{s:5:"label";a:2:{s:6:"format";s:5:"above";s:7:"exclude";i:0;}i:5;a:2:{s:6:"format";s:7:"default";s:7:"exclude";i:0;}s:6:"teaser";a:2:{s:6:"format";s:7:"default";s:7:"exclude";i:0;}s:4:"full";a:2:{s:6:"format";s:7:"default";s:7:"exclude";i:0;}i:4;a:2:{s:6:"format";s:7:"default";s:7:"exclude";i:0;}}', + 'description' => '', + 'widget_module' => 'nodereference', + 'widget_active' => '1', +)) +->values(array( 'field_name' => 'field_test', 'type_name' => 'story', 'weight' => '1', @@ -3523,6 +3547,12 @@ 'size' => 'normal', 'unsigned' => TRUE, ), + 'field_reference_2_nid' => array( + 'type' => 'int', + 'not null' => FALSE, + 'size' => 'normal', + 'unsigned' => TRUE, + ), ), 'primary key' => array( 'vid', @@ -3531,6 +3561,9 @@ 'field_reference_nid' => array( 'field_reference_nid', ), + 'field_reference_2_nid' => array( + 'field_reference_2_nid', + ), ), 'mysql_character_set' => 'utf8', )); @@ -3541,30 +3574,35 @@ 'nid', 'field_text_field_value', 'field_reference_nid', + 'field_reference_2_nid', )) ->values(array( 'vid' => '13', 'nid' => '10', 'field_text_field_value' => NULL, 'field_reference_nid' => '13', + 'field_reference_2_nid' => '13', )) ->values(array( 'vid' => '14', 'nid' => '11', 'field_text_field_value' => NULL, 'field_reference_nid' => '20', + 'field_reference_2_nid' => '20', )) ->values(array( 'vid' => '16', 'nid' => '13', 'field_text_field_value' => NULL, 'field_reference_nid' => '10', + 'field_reference_2_nid' => '10', )) ->values(array( 'vid' => '23', 'nid' => '20', 'field_text_field_value' => NULL, 'field_reference_nid' => '11', + 'field_reference_2_nid' => '11', )) ->execute(); diff --git a/core/modules/migrate_drupal/tests/fixtures/drupal7.php b/core/modules/migrate_drupal/tests/fixtures/drupal7.php index 7915b53cc8..d77940e486 100644 --- a/core/modules/migrate_drupal/tests/fixtures/drupal7.php +++ b/core/modules/migrate_drupal/tests/fixtures/drupal7.php @@ -3664,6 +3664,21 @@ 'translatable' => '0', 'deleted' => '0', )) +->values(array( + 'id' => '39', + 'field_name' => 'field_reference_2', + 'type' => 'entityreference', + 'module' => 'entityreference', + 'active' => '1', + 'storage_type' => 'field_sql_storage', + 'storage_module' => 'field_sql_storage', + 'storage_active' => '1', + 'locked' => '0', + 'data' => 'a:7:{s:12:"translatable";s:1:"0";s:12:"entity_types";a:0:{}s:8:"settings";a:3:{s:11:"target_type";s:4:"node";s:7:"handler";s:4:"base";s:16:"handler_settings";a:2:{s:14:"target_bundles";a:1:{s:7:"article";s:7:"article";}s:4:"sort";a:1:{s:4:"type";s:4:"none";}}}s:7:"storage";a:5:{s:4:"type";s:17:"field_sql_storage";s:8:"settings";a:0:{}s:6:"module";s:17:"field_sql_storage";s:6:"active";s:1:"1";s:7:"details";a:1:{s:3:"sql";a:2:{s:18:"FIELD_LOAD_CURRENT";a:1:{s:28:"field_data_field_reference_2";a:1:{s:9:"target_id";s:27:"field_reference_2_target_id";}}s:19:"FIELD_LOAD_REVISION";a:1:{s:32:"field_revision_field_reference_2";a:1:{s:9:"target_id";s:27:"field_reference_2_target_id";}}}}}s:12:"foreign keys";a:1:{s:4:"node";a:2:{s:5:"table";s:4:"node";s:7:"columns";a:1:{s:9:"target_id";s:3:"nid";}}}s:7:"indexes";a:1:{s:9:"target_id";a:1:{i:0;s:9:"target_id";}}s:2:"id";s:2:"39";}', + 'cardinality' => '1', + 'translatable' => '0', + 'deleted' => '0', +)) ->execute(); $connection->schema()->createTable('field_config_instance', array( @@ -4282,6 +4297,15 @@ 'data' => 'a:7:{s:5:"label";s:9:"Reference";s:6:"widget";a:5:{s:6:"weight";s:2:"20";s:4:"type";s:14:"options_select";s:6:"module";s:7:"options";s:6:"active";i:1;s:8:"settings";a:0:{}}s:8:"settings";a:1:{s:18:"user_register_form";b:0;}s:7:"display";a:1:{s:7:"default";a:5:{s:5:"label";s:5:"above";s:4:"type";s:21:"entityreference_label";s:6:"weight";s:2:"20";s:8:"settings";a:2:{s:13:"bypass_access";i:0;s:4:"link";i:1;}s:6:"module";s:15:"entityreference";}}s:8:"required";i:0;s:11:"description";s:0:"";s:13:"default_value";N;}', 'deleted' => '0', )) +->values(array( + 'id' => '65', + 'field_id' => '39', + 'field_name' => 'field_reference_2', + 'entity_type' => 'node', + 'bundle' => 'article', + 'data' => 'a:6:{s:5:"label";s:11:"Reference 2";s:6:"widget";a:4:{s:4:"type";s:14:"options_select";s:6:"weight";s:2:"21";s:8:"settings";a:0:{}s:6:"module";s:7:"options";}s:8:"settings";a:1:{s:18:"user_register_form";b:0;}s:7:"display";a:1:{s:7:"default";a:5:{s:5:"label";s:5:"above";s:4:"type";s:21:"entityreference_label";s:8:"settings";a:2:{s:4:"link";b:0;s:13:"bypass_access";b:0;}s:6:"module";s:15:"entityreference";s:6:"weight";i:21;}}s:8:"required";b:0;s:11:"description";s:0:"";}', + 'deleted' => '0', +)) ->execute(); $connection->schema()->createTable('field_data_body', array( @@ -6326,6 +6350,143 @@ )) ->execute(); +$connection->schema()->createTable('field_data_field_reference_2', array( + 'fields' => array( + 'entity_type' => array( + 'type' => 'varchar', + 'not null' => TRUE, + 'length' => '128', + 'default' => '', + ), + 'bundle' => array( + 'type' => 'varchar', + 'not null' => TRUE, + 'length' => '128', + 'default' => '', + ), + 'deleted' => array( + 'type' => 'int', + 'not null' => TRUE, + 'size' => 'tiny', + 'default' => '0', + ), + 'entity_id' => array( + 'type' => 'int', + 'not null' => TRUE, + 'size' => 'normal', + 'unsigned' => TRUE, + ), + 'revision_id' => array( + 'type' => 'int', + 'not null' => FALSE, + 'size' => 'normal', + 'unsigned' => TRUE, + ), + 'language' => array( + 'type' => 'varchar', + 'not null' => TRUE, + 'length' => '32', + 'default' => '', + ), + 'delta' => array( + 'type' => 'int', + 'not null' => TRUE, + 'size' => 'normal', + 'unsigned' => TRUE, + ), + 'field_reference_2_target_id' => array( + 'type' => 'int', + 'not null' => TRUE, + 'size' => 'normal', + 'unsigned' => TRUE, + ), + ), + 'primary key' => array( + 'entity_type', + 'entity_id', + 'deleted', + 'delta', + 'language', + ), + 'indexes' => array( + 'entity_type' => array( + 'entity_type', + ), + 'bundle' => array( + 'bundle', + ), + 'deleted' => array( + 'deleted', + ), + 'entity_id' => array( + 'entity_id', + ), + 'revision_id' => array( + 'revision_id', + ), + 'language' => array( + 'language', + ), + 'field_reference_2_target_id' => array( + 'field_reference_2_target_id', + ), + ), + 'mysql_character_set' => 'utf8', +)); + +$connection->insert('field_data_field_reference_2') +->fields(array( + 'entity_type', + 'bundle', + 'deleted', + 'entity_id', + 'revision_id', + 'language', + 'delta', + 'field_reference_2_target_id', +)) +->values(array( + 'entity_type' => 'node', + 'bundle' => 'article', + 'deleted' => '0', + 'entity_id' => '2', + 'revision_id' => '2', + 'language' => 'und', + 'delta' => '0', + 'field_reference_2_target_id' => '5', +)) +->values(array( + 'entity_type' => 'node', + 'bundle' => 'article', + 'deleted' => '0', + 'entity_id' => '3', + 'revision_id' => '3', + 'language' => 'und', + 'delta' => '0', + 'field_reference_2_target_id' => '4', +)) +->values(array( + 'entity_type' => 'node', + 'bundle' => 'article', + 'deleted' => '0', + 'entity_id' => '4', + 'revision_id' => '4', + 'language' => 'und', + 'delta' => '0', + 'field_reference_2_target_id' => '3', +)) +->values(array( + 'entity_type' => 'node', + 'bundle' => 'article', + 'deleted' => '0', + 'entity_id' => '5', + 'revision_id' => '5', + 'language' => 'und', + 'delta' => '0', + 'field_reference_2_target_id' => '2', +)) +->execute(); + $connection->schema()->createTable('field_data_field_tags', array( 'fields' => array( 'entity_type' => array( @@ -9949,6 +10110,144 @@ )) ->execute(); +$connection->schema()->createTable('field_revision_field_reference_2', array( + 'fields' => array( + 'entity_type' => array( + 'type' => 'varchar', + 'not null' => TRUE, + 'length' => '128', + 'default' => '', + ), + 'bundle' => array( + 'type' => 'varchar', + 'not null' => TRUE, + 'length' => '128', + 'default' => '', + ), + 'deleted' => array( + 'type' => 'int', + 'not null' => TRUE, + 'size' => 'tiny', + 'default' => '0', + ), + 'entity_id' => array( + 'type' => 'int', + 'not null' => TRUE, + 'size' => 'normal', + 'unsigned' => TRUE, + ), + 'revision_id' => array( + 'type' => 'int', + 'not null' => TRUE, + 'size' => 'normal', + 'unsigned' => TRUE, + ), + 'language' => array( + 'type' => 'varchar', + 'not null' => TRUE, + 'length' => '32', + 'default' => '', + ), + 'delta' => array( + 'type' => 'int', + 'not null' => TRUE, + 'size' => 'normal', + 'unsigned' => TRUE, + ), + 'field_reference_2_target_id' => array( + 'type' => 'int', + 'not null' => TRUE, + 'size' => 'normal', + 'unsigned' => TRUE, + ), + ), + 'primary key' => array( + 'entity_type', + 'entity_id', + 'revision_id', + 'deleted', + 'delta', + 'language', + ), + 'indexes' => array( + 'entity_type' => array( + 'entity_type', + ), + 'bundle' => array( + 'bundle', + ), + 'deleted' => array( + 'deleted', + ), + 'entity_id' => array( + 'entity_id', + ), + 'revision_id' => array( + 'revision_id', + ), + 'language' => array( + 'language', + ), + 'field_reference_2_target_id' => array( + 'field_reference_2_target_id', + ), + ), + 'mysql_character_set' => 'utf8', +)); + +$connection->insert('field_revision_field_reference_2') +->fields(array( + 'entity_type', + 'bundle', + 'deleted', + 'entity_id', + 'revision_id', + 'language', + 'delta', + 'field_reference_2_target_id', +)) +->values(array( + 'entity_type' => 'node', + 'bundle' => 'article', + 'deleted' => '0', + 'entity_id' => '2', + 'revision_id' => '2', + 'language' => 'und', + 'delta' => '0', + 'field_reference_2_target_id' => '5', +)) +->values(array( + 'entity_type' => 'node', + 'bundle' => 'article', + 'deleted' => '0', + 'entity_id' => '3', + 'revision_id' => '3', + 'language' => 'und', + 'delta' => '0', + 'field_reference_2_target_id' => '4', +)) +->values(array( + 'entity_type' => 'node', + 'bundle' => 'article', + 'deleted' => '0', + 'entity_id' => '4', + 'revision_id' => '4', + 'language' => 'und', + 'delta' => '0', + 'field_reference_2_target_id' => '3', +)) +->values(array( + 'entity_type' => 'node', + 'bundle' => 'article', + 'deleted' => '0', + 'entity_id' => '5', + 'revision_id' => '5', + 'language' => 'und', + 'delta' => '0', + 'field_reference_2_target_id' => '2', +)) +->execute(); + $connection->schema()->createTable('field_revision_field_tags', array( 'fields' => array( 'entity_type' => array( diff --git a/core/modules/migrate_drupal/tests/src/Kernel/d6/FollowUpMigrationsTest.php b/core/modules/migrate_drupal/tests/src/Kernel/d6/FollowUpMigrationsTest.php index 33a1e35dde..dd237e1dda 100644 --- a/core/modules/migrate_drupal/tests/src/Kernel/d6/FollowUpMigrationsTest.php +++ b/core/modules/migrate_drupal/tests/src/Kernel/d6/FollowUpMigrationsTest.php @@ -41,15 +41,19 @@ public function testEntityReferenceTranslations() { // Test the entity reference field before the follow-up migrations. $node = Node::load(10); $this->assertSame([0 => ['target_id' => '13']], $node->get('field_reference')->getValue()); + $this->assertSame([0 => ['target_id' => '13']], $node->get('field_reference_2')->getValue()); $translation = $node->getTranslation('fr'); $this->assertSame([0 => ['target_id' => '20']], $translation->get('field_reference')->getValue()); + $this->assertSame([0 => ['target_id' => '20']], $translation->get('field_reference_2')->getValue()); $node = Node::load(12)->getTranslation('en'); $this->assertSame([0 => ['target_id' => '10']], $node->get('field_reference')->getValue()); + $this->assertSame([0 => ['target_id' => '10']], $node->get('field_reference_2')->getValue()); $translation = $node->getTranslation('fr'); $this->assertSame([0 => ['target_id' => '11']], $translation->get('field_reference')->getValue()); + $this->assertSame([0 => ['target_id' => '11']], $translation->get('field_reference_2')->getValue()); - // Run the follow-ups migrations. + // Run the follow-up migrations. $migration_plugin_manager = $this->container->get('plugin.manager.migration'); $migration_plugin_manager->clearCachedDefinitions(); $follow_up_migrations = $migration_plugin_manager->createInstances('d6_entity_reference_translation'); @@ -58,13 +62,17 @@ public function testEntityReferenceTranslations() { // Test the entity reference field after the follow-up migrations. $node = Node::load(10); $this->assertSame([0 => ['target_id' => '12']], $node->get('field_reference')->getValue()); + $this->assertSame([0 => ['target_id' => '12']], $node->get('field_reference_2')->getValue()); $translation = $node->getTranslation('fr'); $this->assertSame([0 => ['target_id' => '12']], $translation->get('field_reference')->getValue()); + $this->assertSame([0 => ['target_id' => '12']], $translation->get('field_reference_2')->getValue()); $node = Node::load(12)->getTranslation('en'); $this->assertSame([0 => ['target_id' => '10']], $node->get('field_reference')->getValue()); + $this->assertSame([0 => ['target_id' => '10']], $node->get('field_reference_2')->getValue()); $translation = $node->getTranslation('fr'); $this->assertSame([0 => ['target_id' => '10']], $translation->get('field_reference')->getValue()); + $this->assertSame([0 => ['target_id' => '10']], $translation->get('field_reference_2')->getValue()); } } diff --git a/core/modules/migrate_drupal/tests/src/Kernel/d7/FollowUpMigrationsTest.php b/core/modules/migrate_drupal/tests/src/Kernel/d7/FollowUpMigrationsTest.php index c94faaef8a..b1bc6af6f2 100644 --- a/core/modules/migrate_drupal/tests/src/Kernel/d7/FollowUpMigrationsTest.php +++ b/core/modules/migrate_drupal/tests/src/Kernel/d7/FollowUpMigrationsTest.php @@ -68,15 +68,19 @@ public function testEntityReferenceTranslations() { // Test the entity reference field before the follow-up migrations. $node = Node::load(2); $this->assertSame([0 => ['target_id' => '5']], $node->get('field_reference')->getValue()); + $this->assertSame([0 => ['target_id' => '5']], $node->get('field_reference_2')->getValue()); $translation = $node->getTranslation('is'); $this->assertSame([0 => ['target_id' => '4']], $translation->get('field_reference')->getValue()); + $this->assertSame([0 => ['target_id' => '4']], $translation->get('field_reference_2')->getValue()); $node = Node::load(4); $this->assertSame([0 => ['target_id' => '3']], $node->get('field_reference')->getValue()); + $this->assertSame([0 => ['target_id' => '3']], $node->get('field_reference_2')->getValue()); $translation = $node->getTranslation('en'); $this->assertSame([0 => ['target_id' => '2']], $translation->get('field_reference')->getValue()); + $this->assertSame([0 => ['target_id' => '2']], $translation->get('field_reference_2')->getValue()); - // Run the follow-ups migrations. + // Run the follow-up migrations. $migration_plugin_manager = $this->container->get('plugin.manager.migration'); $migration_plugin_manager->clearCachedDefinitions(); $follow_up_migrations = $migration_plugin_manager->createInstances('d7_entity_reference_translation'); @@ -85,13 +89,17 @@ public function testEntityReferenceTranslations() { // Test the entity reference field after the follow-up migrations. $node = Node::load(2); $this->assertSame([0 => ['target_id' => '4']], $node->get('field_reference')->getValue()); + $this->assertSame([0 => ['target_id' => '4']], $node->get('field_reference_2')->getValue()); $translation = $node->getTranslation('is'); $this->assertSame([0 => ['target_id' => '4']], $translation->get('field_reference')->getValue()); + $this->assertSame([0 => ['target_id' => '4']], $translation->get('field_reference_2')->getValue()); $node = Node::load(4); $this->assertSame([0 => ['target_id' => '2']], $node->get('field_reference')->getValue()); + $this->assertSame([0 => ['target_id' => '2']], $node->get('field_reference_2')->getValue()); $translation = $node->getTranslation('en'); $this->assertSame([0 => ['target_id' => '2']], $translation->get('field_reference')->getValue()); + $this->assertSame([0 => ['target_id' => '2']], $translation->get('field_reference_2')->getValue()); } } diff --git a/core/modules/migrate_drupal_ui/src/Batch/MigrateUpgradeImportBatch.php b/core/modules/migrate_drupal_ui/src/Batch/MigrateUpgradeImportBatch.php index 97817fb716..7145b8d249 100644 --- a/core/modules/migrate_drupal_ui/src/Batch/MigrateUpgradeImportBatch.php +++ b/core/modules/migrate_drupal_ui/src/Batch/MigrateUpgradeImportBatch.php @@ -148,11 +148,21 @@ public static function run($initial_ids, $config, &$context) { \Drupal::logger('migrate_drupal_ui')->notice($message); $context['sandbox']['num_processed'] = 0; $context['results']['successes']++; + + // If the completed migration has any follow-up migrations, add them + // to the batch migrations. + // @see onPostImport() if (!empty(static::$followUpMigrations)) { foreach (static::$followUpMigrations as $migration_id => $migration) { if (!in_array($migration_id, $context['sandbox']['migration_ids'], TRUE)) { + // Add the follow-up migration ID to the batch migration IDs for + // later execution. $context['sandbox']['migration_ids'][] = $migration_id; + // Increase the number of migrations in the batch to update the + // progress bar and keep it accurate. $context['sandbox']['max']++; + // Unset the follow-up migration to make sure it won't get added + // to the batch twice. unset(static::$followUpMigrations[$migration_id]); } } @@ -290,6 +300,11 @@ public static function onPostRowSave(MigratePostRowSaveEvent $event) { public static function onPostImport(MigrateImportEvent $event) { $migration = $event->getMigration(); if ($migration instanceof MigrationWithFollowUpInterface) { + // After the migration on which they depend has been successfully + // executed, the follow-up migrations are immediately added to the batch + // and removed from the $followUpMigrations property. This means that the + // $followUpMigrations property is always empty at this point and it's OK + // to override it with the next follow-up migrations. static::$followUpMigrations = $migration->generateFollowUpMigrations(); } } diff --git a/core/modules/migrate_drupal_ui/tests/src/Functional/d6/MigrateUpgrade6Test.php b/core/modules/migrate_drupal_ui/tests/src/Functional/d6/MigrateUpgrade6Test.php index 0dc6ca4d73..27f303dccf 100644 --- a/core/modules/migrate_drupal_ui/tests/src/Functional/d6/MigrateUpgrade6Test.php +++ b/core/modules/migrate_drupal_ui/tests/src/Functional/d6/MigrateUpgrade6Test.php @@ -64,8 +64,8 @@ protected function getEntityCounts() { 'contact_form' => 5, 'configurable_language' => 5, 'editor' => 2, - 'field_config' => 87, - 'field_storage_config' => 61, + 'field_config' => 88, + 'field_storage_config' => 62, 'file' => 8, 'filter_format' => 7, 'image_style' => 5, @@ -202,13 +202,17 @@ public function testMigrateUpgradeExecute() { protected function assertFollowUpMigrationResults() { $node = Node::load(10); $this->assertSame([0 => ['target_id' => '12']], $node->get('field_reference')->getValue()); + $this->assertSame([0 => ['target_id' => '12']], $node->get('field_reference_2')->getValue()); $translation = $node->getTranslation('fr'); $this->assertSame([0 => ['target_id' => '12']], $translation->get('field_reference')->getValue()); + $this->assertSame([0 => ['target_id' => '12']], $translation->get('field_reference_2')->getValue()); $node = Node::load(12)->getTranslation('en'); $this->assertSame([0 => ['target_id' => '10']], $node->get('field_reference')->getValue()); + $this->assertSame([0 => ['target_id' => '10']], $node->get('field_reference_2')->getValue()); $translation = $node->getTranslation('fr'); $this->assertSame([0 => ['target_id' => '10']], $translation->get('field_reference')->getValue()); + $this->assertSame([0 => ['target_id' => '10']], $translation->get('field_reference_2')->getValue()); } } diff --git a/core/modules/migrate_drupal_ui/tests/src/Functional/d7/MigrateUpgrade7Test.php b/core/modules/migrate_drupal_ui/tests/src/Functional/d7/MigrateUpgrade7Test.php index edf7939dde..d87e277ae4 100644 --- a/core/modules/migrate_drupal_ui/tests/src/Functional/d7/MigrateUpgrade7Test.php +++ b/core/modules/migrate_drupal_ui/tests/src/Functional/d7/MigrateUpgrade7Test.php @@ -66,8 +66,8 @@ protected function getEntityCounts() { 'configurable_language' => 4, 'contact_form' => 3, 'editor' => 2, - 'field_config' => 65, - 'field_storage_config' => 48, + 'field_config' => 66, + 'field_storage_config' => 49, 'file' => 3, 'filter_format' => 7, 'image_style' => 6, @@ -200,13 +200,17 @@ public function testMigrateUpgradeExecute() { protected function assertFollowUpMigrationResults() { $node = Node::load(2); $this->assertSame([0 => ['target_id' => '4']], $node->get('field_reference')->getValue()); + $this->assertSame([0 => ['target_id' => '4']], $node->get('field_reference_2')->getValue()); $translation = $node->getTranslation('is'); $this->assertSame([0 => ['target_id' => '4']], $translation->get('field_reference')->getValue()); + $this->assertSame([0 => ['target_id' => '4']], $translation->get('field_reference_2')->getValue()); $node = Node::load(4); $this->assertSame([0 => ['target_id' => '2']], $node->get('field_reference')->getValue()); + $this->assertSame([0 => ['target_id' => '2']], $node->get('field_reference_2')->getValue()); $translation = $node->getTranslation('en'); $this->assertSame([0 => ['target_id' => '2']], $translation->get('field_reference')->getValue()); + $this->assertSame([0 => ['target_id' => '2']], $translation->get('field_reference_2')->getValue()); }