diff -u b/core/modules/migrate/src/Plugin/migrate/destination/EntityContentComplete.php b/core/modules/migrate/src/Plugin/migrate/destination/EntityContentComplete.php --- b/core/modules/migrate/src/Plugin/migrate/destination/EntityContentComplete.php +++ b/core/modules/migrate/src/Plugin/migrate/destination/EntityContentComplete.php @@ -55,11 +55,18 @@ $revision_id = $old_destination_id_values ? $old_destination_id_values[1] : $row->getDestinationProperty($this->getKey('revision')); + // If we are re-running a migration with set revision IDs and the + // destination revision ID already exists then do not create a new revision. if (!empty($revision_id) && ($entity = $this->storage->loadRevision($revision_id))) { $entity->setNewRevision(FALSE); } elseif (($entity_id = $row->getDestinationProperty($this->getKey('id'))) && ($entity = $this->storage->load($entity_id))) { + // We want to create a new entity. Set enforceIsNew() FALSE is necessary + // to properly save a new entity while setting the ID. Without it, the + // system would see that the ID is already set and assume it is an update. $entity->enforceIsNew(FALSE); + // Intentionally create a new revision. Setting new revision TRUE here may + // not be necessary, it is done for clarity. $entity->setNewRevision(TRUE); } else { @@ -85,6 +92,10 @@ // other translations. /** @var \Drupal\Core\Entity\ContentEntityInterface|\Drupal\Core\Entity\EntityChangedInterface $entity */ foreach ($entity->getTranslationLanguages() as $langcode => $language) { + // If we updated an untranslated field, then set the changed time for + // for all translations to match the current row that we are saving. + // In this context, getChangedTime() should return the value we just + // set in the updateEntity() call above. if ($entity->getTranslation($langcode)->hasTranslationChanges()) { $entity->getTranslation($langcode)->setChangedTime($entity->getChangedTime()); } diff -u b/core/modules/migrate_drupal/tests/fixtures/drupal7.php b/core/modules/migrate_drupal/tests/fixtures/drupal7.php --- b/core/modules/migrate_drupal/tests/fixtures/drupal7.php +++ b/core/modules/migrate_drupal/tests/fixtures/drupal7.php @@ -5089,7 +5089,7 @@ 'bundle' => 'article', 'deleted' => '0', 'entity_id' => '2', - 'revision_id' => '11', + 'revision_id' => '2', 'language' => 'und', 'delta' => '0', 'body_value' => "...is that it's the absolute best show ever. Trust me, I would know.", @@ -5101,7 +5101,7 @@ 'bundle' => 'article', 'deleted' => '0', 'entity_id' => '3', - 'revision_id' => '12', + 'revision_id' => '3', 'language' => 'und', 'delta' => '0', 'body_value' => "is - ...is that it's the absolute best show ever. Trust me, I would know.", @@ -5117,7 +5117,7 @@ 'bundle' => 'article', 'deleted' => '0', 'entity_id' => '2', - 'revision_id' => '2', + 'revision_id' => '11', 'language' => 'und', 'delta' => '0', 'body_value' => "...is that it's the absolute best show ever. Trust me, I would know.", @@ -5129,7 +5129,7 @@ 'bundle' => 'article', 'deleted' => '0', 'entity_id' => '3', - 'revision_id' => '3', + 'revision_id' => '12', 'language' => 'und', 'delta' => '0', 'body_value' => "is - ...is that it's the absolute best show ever. Trust me, I would know.", @@ -6945,23 +6945,23 @@ 'bundle' => 'article', 'deleted' => '0', 'entity_id' => '2', - 'revision_id' => '11', + 'revision_id' => '2', 'language' => 'und', 'delta' => '0', 'field_link_url' => '', - 'field_link_title' => NULL, - 'field_link_attributes' => 'a:1:{s:5:"title";s:0:"";}', + 'field_link_title' => 'Home', + 'field_link_attributes' => 'a:0:{}', )) ->values(array( 'entity_type' => 'node', 'bundle' => 'article', 'deleted' => '0', 'entity_id' => '3', - 'revision_id' => '12', + 'revision_id' => '3', 'language' => 'und', 'delta' => '0', 'field_link_url' => '', - 'field_link_title' => NULL, + 'field_link_title' => 'Home', 'field_link_attributes' => 'a:1:{s:5:"title";s:0:"";}', )) ->execute(); @@ -6994,23 +6994,23 @@ 'bundle' => 'article', 'deleted' => '0', 'entity_id' => '2', - 'revision_id' => '2', + 'revision_id' => '11', 'language' => 'und', 'delta' => '0', 'field_link_url' => '', - 'field_link_title' => 'Home', - 'field_link_attributes' => 'a:0:{}', + 'field_link_title' => NULL, + 'field_link_attributes' => 'a:1:{s:5:"title";s:0:"";}', )) ->values(array( 'entity_type' => 'node', 'bundle' => 'article', 'deleted' => '0', 'entity_id' => '3', - 'revision_id' => '3', + 'revision_id' => '12', 'language' => 'und', 'delta' => '0', 'field_link_url' => '', - 'field_link_title' => 'Home', + 'field_link_title' => NULL, 'field_link_attributes' => 'a:1:{s:5:"title";s:0:"";}', )) ->execute(); @@ -7573,7 +7573,7 @@ 'bundle' => 'article', 'deleted' => '0', 'entity_id' => '2', - 'revision_id' => '11', + 'revision_id' => '2', 'language' => 'und', 'delta' => '0', 'field_reference_target_id' => '5', @@ -7583,7 +7583,7 @@ 'bundle' => 'article', 'deleted' => '0', 'entity_id' => '3', - 'revision_id' => '12', + 'revision_id' => '3', 'language' => 'und', 'delta' => '0', 'field_reference_target_id' => '4', @@ -7593,7 +7593,7 @@ 'bundle' => 'article', 'deleted' => '0', 'entity_id' => '4', - 'revision_id' => '13', + 'revision_id' => '4', 'language' => 'und', 'delta' => '0', 'field_reference_target_id' => '3', @@ -7603,7 +7603,7 @@ 'bundle' => 'article', 'deleted' => '0', 'entity_id' => '5', - 'revision_id' => '14', + 'revision_id' => '5', 'language' => 'und', 'delta' => '0', 'field_reference_target_id' => '2', @@ -7622,7 +7622,7 @@ 'bundle' => 'article', 'deleted' => '0', 'entity_id' => '2', - 'revision_id' => '2', + 'revision_id' => '11', 'language' => 'und', 'delta' => '0', 'field_reference_target_id' => '5', @@ -7632,7 +7632,7 @@ 'bundle' => 'article', 'deleted' => '0', 'entity_id' => '3', - 'revision_id' => '3', + 'revision_id' => '12', 'language' => 'und', 'delta' => '0', 'field_reference_target_id' => '4', @@ -7642,7 +7642,7 @@ 'bundle' => 'article', 'deleted' => '0', 'entity_id' => '4', - 'revision_id' => '4', + 'revision_id' => '13', 'language' => 'und', 'delta' => '0', 'field_reference_target_id' => '3', @@ -7652,7 +7652,7 @@ 'bundle' => 'article', 'deleted' => '0', 'entity_id' => '5', - 'revision_id' => '5', + 'revision_id' => '14', 'language' => 'und', 'delta' => '0', 'field_reference_target_id' => '2', @@ -7709,7 +7709,7 @@ 'bundle' => 'article', 'deleted' => '0', 'entity_id' => '2', - 'revision_id' => '11', + 'revision_id' => '2', 'language' => 'und', 'delta' => '0', 'field_reference_2_target_id' => '5', @@ -7719,7 +7719,7 @@ 'bundle' => 'article', 'deleted' => '0', 'entity_id' => '3', - 'revision_id' => '12', + 'revision_id' => '3', 'language' => 'und', 'delta' => '0', 'field_reference_2_target_id' => '4', @@ -7729,7 +7729,7 @@ 'bundle' => 'article', 'deleted' => '0', 'entity_id' => '4', - 'revision_id' => '13', + 'revision_id' => '4', 'language' => 'und', 'delta' => '0', 'field_reference_2_target_id' => '3', @@ -7739,7 +7739,7 @@ 'bundle' => 'article', 'deleted' => '0', 'entity_id' => '5', - 'revision_id' => '14', + 'revision_id' => '5', 'language' => 'und', 'delta' => '0', 'field_reference_2_target_id' => '2', @@ -7758,7 +7758,7 @@ 'bundle' => 'article', 'deleted' => '0', 'entity_id' => '2', - 'revision_id' => '2', + 'revision_id' => '11', 'language' => 'und', 'delta' => '0', 'field_reference_2_target_id' => '5', @@ -7768,7 +7768,7 @@ 'bundle' => 'article', 'deleted' => '0', 'entity_id' => '3', - 'revision_id' => '3', + 'revision_id' => '12', 'language' => 'und', 'delta' => '0', 'field_reference_2_target_id' => '4', @@ -7778,7 +7778,7 @@ 'bundle' => 'article', 'deleted' => '0', 'entity_id' => '4', - 'revision_id' => '4', + 'revision_id' => '13', 'language' => 'und', 'delta' => '0', 'field_reference_2_target_id' => '3', @@ -7788,7 +7788,7 @@ 'bundle' => 'article', 'deleted' => '0', 'entity_id' => '5', - 'revision_id' => '5', + 'revision_id' => '14', 'language' => 'und', 'delta' => '0', 'field_reference_2_target_id' => '2', @@ -7822,7 +7822,7 @@ 'bundle' => 'article', 'deleted' => '0', 'entity_id' => '2', - 'revision_id' => '11', + 'revision_id' => '2', 'language' => 'und', 'delta' => '0', 'field_tags_tid' => '9', @@ -7832,7 +7832,7 @@ 'bundle' => 'article', 'deleted' => '0', 'entity_id' => '3', - 'revision_id' => '12', + 'revision_id' => '3', 'language' => 'und', 'delta' => '0', 'field_tags_tid' => '9', @@ -7842,7 +7842,7 @@ 'bundle' => 'article', 'deleted' => '0', 'entity_id' => '2', - 'revision_id' => '11', + 'revision_id' => '2', 'language' => 'und', 'delta' => '1', 'field_tags_tid' => '14', @@ -7852,7 +7852,7 @@ 'bundle' => 'article', 'deleted' => '0', 'entity_id' => '3', - 'revision_id' => '12', + 'revision_id' => '3', 'language' => 'und', 'delta' => '1', 'field_tags_tid' => '14', @@ -7862,7 +7862,7 @@ 'bundle' => 'article', 'deleted' => '0', 'entity_id' => '2', - 'revision_id' => '11', + 'revision_id' => '2', 'language' => 'und', 'delta' => '2', 'field_tags_tid' => '17', @@ -7871,7 +7871,7 @@ 'bundle' => 'article', 'deleted' => '0', 'entity_id' => '2', - 'revision_id' => '2', + 'revision_id' => '11', 'language' => 'und', 'delta' => '0', 'field_tags_tid' => '9', @@ -7881,7 +7881,7 @@ 'bundle' => 'article', 'deleted' => '0', 'entity_id' => '3', - 'revision_id' => '3', + 'revision_id' => '12', 'language' => 'und', 'delta' => '0', 'field_tags_tid' => '9', @@ -7891,7 +7891,7 @@ 'bundle' => 'article', 'deleted' => '0', 'entity_id' => '2', - 'revision_id' => '2', + 'revision_id' => '11', 'language' => 'und', 'delta' => '1', 'field_tags_tid' => '14', @@ -7901,7 +7901,7 @@ 'bundle' => 'article', 'deleted' => '0', 'entity_id' => '3', - 'revision_id' => '3', + 'revision_id' => '12', 'language' => 'und', 'delta' => '1', 'field_tags_tid' => '14', @@ -7911,7 +7911,7 @@ 'bundle' => 'article', 'deleted' => '0', 'entity_id' => '2', - 'revision_id' => '2', + 'revision_id' => '11', 'language' => 'und', 'delta' => '2', 'field_tags_tid' => '17', diff -u b/core/modules/node/node.module b/core/modules/node/node.module --- b/core/modules/node/node.module +++ b/core/modules/node/node.module @@ -1469,160 +1469,22 @@ function node_migration_plugins_alter(array &$definitions) { - // If the complete node migrate_map tables have data then the any migration - // use a node migration in a migration_lookup needs to be altered to use - // both the classic and complete node migration. - if ((new NodeMigrateType)->getNodeMigrateType($definitions, NULL) !== NodeMigrateType::NODE_MIGRATE_TYPE_CLASSIC) { - + // If this is complete node migration then for of migrations, except the + // classic node migrations, replace the dependency on a classic node migration + // with a dependency on the complete node migration. + if ((new NodeMigrateType)->getNodeMigrateType($definitions, NULL) == NodeMigrateType::NODE_MIGRATE_TYPE_COMPLETE) { // Anonymous function to replace classic node migration plugin IDs with the - // complete plugin ID. + // node complete plugin ID. $replace_with_complete_migration = function (&$value) { if (is_string($value)) { - $value = preg_replace('/d([67])_(node|node_translation|node_revision)($|:.*)/', 'd$1_node_complete$3', $value); + $value = preg_replace('/d([67])_(node|node_translation|node_revision|node_entity_translation)($|:.*)/', 'd$1_node_complete$3', $value); } return $value; }; - // Alter references to the classic node migration to the complete node - // migration in all relevant core migrations. The references altered are - // those in migration_dependencies and in the process pipeline. In the - // process pipeline we are concerned with references to classic node - // migrations in a migration_lookup process. - // - // The process pipeline is altered so that the migration_lookup returns - // the correct IDs. For example, the classic d6_node_revision migration - // has a single ID, the revision ID, but the d6_node_complete has three IDs, - // the node ID, the revision ID and the language. To ensure the pipeline - // works for both migrations we need to insert a process to return only - // the revision ID if the complete node migration was used. - // - // Example: d6_term_node_revision - // - // Before - // vid: - // - - // plugin: migration_lookup - // migration: d6_node_revision - // source: vid - // - - // plugin: skip_on_empty - // method: row - // After - // vid: - // - - // plugin: migration_lookup - // migration: - // - d6_node_revision - // - d6_node_complete - // source: vid - // - - // plugin: skip_on_empty - // method: row - // - - // plugin: node_complete_node_lookup - // - // The classic node migrations are not altered. - // - // See \Drupal\migrate_drupal\Plugin\migrate\process\NodeCompleteNodeLookup - // See \Drupal\migrate_drupal\Plugin\migrate\process\NodeCompleteNodeRevisionLookup - // See \Drupal\migrate_drupal\Plugin\migrate\process\NodeCompleteNodeTranslationLookup + foreach ($definitions as &$definition) { - $is_node_classic_migration = preg_match('/d([67])_(node|node_translation|node_revision)($|:.*)/', $definition['id']); + $is_node_classic_migration = preg_match('/d([67])_(node|node_translation|node_revision|node_entity_translation)($|:.*)/', $definition['id']); if (!$is_node_classic_migration && isset($definition['migration_dependencies'])) { array_walk_recursive($definition['migration_dependencies'], $replace_with_complete_migration); } - - // Alter the migration_lookup process so the node ID is returned. - if (preg_match('/d6_term_node($|:.*)/', $definition['id'])) { - $tmp = $definition['process']['nid'][0]['migration']; - $definition['process']['nid'][0]['migration'] = _insert_migration($tmp); - $definition['process']['nid'][2] = [ - 'plugin' => 'node_complete_node_lookup', - ]; - } - // Alter the migration_lookup process so the revision ID is returned. - if (preg_match('/d6_term_node_revision($|:.*)/', $definition['id'])) { - $tmp = $definition['process']['vid'][0]['migration']; - $definition['process']['vid'][0]['migration'] = _insert_migration($tmp); - $definition['process']['vid'][2] = [ - 'plugin' => 'node_complete_node_revision_lookup', - ]; - } - // Alter the migration_lookup process so the node ID and langcode are - // returned. - if (preg_match('/d6_term_node_translation($|:.*)/', $definition['id'])) { - $tmp = $definition['process']['dest_nid'][0]['migration']; - $definition['process']['dest_nid'][0]['migration'] = _insert_migration($tmp); - $definition['process']['dest_nid'][2] = [ - 'plugin' => 'node_complete_node_translation_lookup', - ]; - } - } - - // Alter the migration_lookup process so the node ID is returned. - if (isset($definitions['d6_comment'])) { - $tmp = $definitions['d6_comment']['process']['entity_id'][0]['migration']; - $definitions['d6_comment']['process']['entity_id'][0]['migration'] = _insert_migration($tmp); - $definitions['d6_comment']['process']['entity_id'][2] = [ - 'plugin' => 'node_complete_node_lookup', - ]; - } - // Alter the migration_lookup process so the node ID and langcode are - // returned. - if (isset($definitions['d6_url_alias'])) { - $tmp = $definitions['d6_url_alias']['process']['node_translation'][2]['migration']; - $definitions['d6_url_alias']['process']['node_translation'][2]['migration'] = _insert_migration($tmp); - $definitions['d6_url_alias']['process']['node_translation'][3] = [ - 'plugin' => 'node_complete_node_translation_lookup', - ]; } - // Alter the migration_lookup process so the node ID is returned. - if (isset($definitions['d7_comment'])) { - $tmp = $definitions['d7_comment']['process']['entity_id'][0]['migration']; - $definitions['d7_comment']['process']['entity_id'][0]['migration'] = _insert_migration($tmp); - $definitions['d7_comment']['process']['entity_id'][2] = [ - 'plugin' => 'node_complete_node_lookup', - ]; - } - // Alter the migration_lookup process so the node ID and langcode are - // returned. - if (isset($definitions['d7_url_alias'])) { - $tmp = $definitions['d7_url_alias']['process']['node_translation'][2]['migration']; - $definitions['d7_url_alias']['process']['node_translation'][2]['migration'] = _insert_migration($tmp); - $definitions['d7_url_alias']['process']['node_translation'][3] = [ - 'plugin' => 'node_complete_node_translation_lookup', - ]; - } - // Alter the migration_lookup process so the node ID is returned. - if (isset($definitions['statistics_node_counter'])) { - $tmp = $definitions['statistics_node_counter']['process']['nid'][0]['migration']; - $definitions['statistics_node_counter']['process']['nid'][0]['migration'] = _insert_migration($tmp); - $definitions['statistics_node_counter']['process']['nid'][2] = [ - 'plugin' => 'node_complete_node_lookup', - ]; - } - // Alter the migration_lookup process to include the complete node migration. - // A node_complete_node*_lookup process is not needed because the - // migration_lookup is followed by an extract process which will get the - // node ID. - if (isset($definitions['node_translation_menu_links'])) { - $tmp = $definitions['node_translation_menu_links']['process']['new_nid'][4]['migration']; - $definitions['node_translation_menu_links']['process']['new_nid'][4]['migration'] = _insert_migration($tmp); - } - } -} - -/** - * Add dN_node_complete to the migrations array of a migration_lookup plugin. - * - * @internal - * Only to be used by node_migration_plugins_alter(). - */ -function _insert_migration($migrations) { - if (!is_array($migrations)) { - $migrations = [$migrations]; - } - $new_migration_list = []; - foreach ($migrations as $migration) { - $tmp = substr($migration, 0, 2) . '_node_complete'; - array_unshift($new_migration_list, $tmp, $migration); } - return array_unique($new_migration_list); } reverted: --- b/core/modules/node/tests/src/Kernel/MigrationPluginAlterTest.php +++ a/core/modules/migrate_drupal/tests/src/Kernel/MigrationPluginAlterTest.php @@ -1,23 +1,20 @@ install($modules); - // Version 6 is used so that term node migrations are tested. - $this->makeNodeMigrateMapTable($type, '6'); - $definitions = $migration_definitions; migrate_drupal_migration_plugins_alter($definitions); - node_migration_plugins_alter($definitions); // Ensure the results have an 'id' key. foreach ($definitions as $definition) { $this->assertArrayHasKey('id', $definition); @@ -65,29 +45,19 @@ public function providerMigrationPluginAlter() { $tests = []; + // Test without a d6_taxonomy_vocabulary definition. + $tests[0]['source_data'] = [ - // Tests migrations that should never be altered, once without an extra - // module installed and then with content_translation installed. - $system_site_migration = [ - 'system_site' => [ - 'id' => 'system_site', - 'source' => [ - 'plugin' => 'variable', - 'variables' => [ - 'site_name', - 'site_mail', - ], - 'source_module' => 'system', - ], - 'process' => [], - ], - ]; - $migrations = [ 'test' => [ 'id' => 'test', 'process' => [ 'nid' => 'nid', ], ], + ]; + $tests[0]['expected_data'] = $tests[0]['source_data']; + + // Test with a d6_taxonomy_vocabulary definition. + $tests[1]['source_data'] = [ 'd6_taxonomy_vocabulary' => [ 'id' => 'd6_taxonomy_vocabulary', 'process' => [ @@ -96,137 +66,116 @@ ], ], ], + 'test' => [ + 'id' => 'test', - ]; - $migrations += $system_site_migration; - $tests[0]['modules'] = []; - $tests[0]['type'] = NodeMigrateType::NODE_MIGRATE_TYPE_CLASSIC; - $tests[0]['migrations'] = $migrations; - $tests[0]['expected_data'] = $tests[0]['migrations']; - - $tests[1] = $tests[0]; - $tests[1]['modules'] = ['content_translation']; - - $tests[2] = $tests[0]; - $tests[2]['modules'] = []; - $tests[2]['type'] = NodeMigrateType::NODE_MIGRATE_TYPE_CLASSIC; - - // Test d6_term_node and d6_term_node revisions are not altered without - // d6_taxonomy_vocabulary. d6_term_node_translation is not changed. - $migrations_src = [ - 'd6_term_node:2' => [ - 'id' => 'd6_term_node:2', 'process' => [ + 'nid' => 'nid', - 'nid' => [ - [ - 'plugin' => 'migration_lookup', - 'migration' => 'd6_node', - 'source' => 'nid', - ], - ], - ], - 'destination' => [ - 'plugin' => 'entity:node', ], ], + ]; + $tests[1]['expected_data'] = $tests[1]['source_data']; + + // Test with a d6_taxonomy_vocabulary and term_node definitions. + $tests[2] = $tests[1]; + $tests[2]['source_data']['d6_term_node:2'] = [ + 'id' => 'd6_term_node:2', + 'process' => [ + 'vid' => [ + 'plugin' => 'machine_name', - 'd6_term_node_revision:4' => [ - 'id' => 'd6_term_node_revision:4', - 'process' => [ - 'vid' => [ - [ - 'plugin' => 'migration_lookup', - 'migration' => 'd6_node_revision', - 'source' => 'vid', - ], - ], ], ], + ]; + $tests[2]['source_data']['d6_term_node_revision:4'] = [ + 'id' => 'd6_term_node_revision:4', + 'process' => [ + 'vid' => [ + 'plugin' => 'machine_name', - 'd6_term_node_translation:2' => [ - 'id' => 'd6_term_node_translation:2', - 'process' => [ - 'dest_nid' => [ - [ - 'plugin' => 'migration_lookup', - 'migration' => 'd6_node_translation', - 'source' => 'nid', - ], - ], ], ], ]; + $tests[2]['expected_data'] = $tests[2]['source_data']; + $tests[2]['expected_data']['d6_term_node:2']['process']['taxonomy_forums'] = 'tid'; + $tests[2]['expected_data']['d6_term_node_revision:4']['process']['field_'] = 'tid'; - $tests[3]['modules'] = []; - $tests[3]['type'] = NodeMigrateType::NODE_MIGRATE_TYPE_CLASSIC; - $tests[3]['migrations'] = $migrations_src + $system_site_migration; - $tests[3]['expected_data'] = $tests[3]['migrations']; + // Test with a d6_taxonomy_vocabulary and term_node_translation definition. + $tests[3] = $tests[1]; + $tests[3]['source_data']['d6_term_node_translation:2'] = [ + 'id' => 'd6_term_node_translation:2', - // d6_term_node and d6_term_node revisions altered with - // d6_taxonomy_vocabulary. d6_term_node_translation is not altered. - $migrations_src['d6_taxonomy_vocabulary'] = [ - 'id' => 'd6_taxonomy_vocabulary', 'process' => [ 'vid' => [ 'plugin' => 'machine_name', ], ], ]; - $tests[4]['modules'] = []; - $tests[4]['type'] = NodeMigrateType::NODE_MIGRATE_TYPE_CLASSIC; - $tests[4]['migrations'] = $migrations_src + $system_site_migration; - $tests[4]['expected_data'] = $tests[4]['migrations']; - $tests[4]['expected_data']['d6_term_node:2']['process']['taxonomy_forums'] = 'tid'; - $tests[4]['expected_data']['d6_term_node_revision:4']['process']['field_'] = 'tid'; + $tests[3]['expected_data'] = $tests[3]['source_data']; + return $tests; + } - // d6_term_node and d6_term_node revisions altered with - // d6_taxonomy_vocabulary. d6_term_node_translation is also altered - // when content_translation is enabled. - $tests[5]['modules'] = ['content_translation']; - $tests[5]['type'] = NodeMigrateType::NODE_MIGRATE_TYPE_CLASSIC; - $tests[5]['migrations'] = $migrations_src + $system_site_migration; - $tests[5]['expected_data'] = $tests[5]['migrations']; - $tests[5]['expected_data']['d6_term_node:2']['process']['taxonomy_forums'] = 'tid'; - $tests[5]['expected_data']['d6_term_node_revision:4']['process']['field_'] = 'tid'; - $tests[5]['expected_data']['d6_term_node_translation:2']['process']['taxonomy_forums'] = 'tid'; + /** + * Tests migrate_drupal_migrations_plugin_alter. + * + * @dataProvider providerMigrationPluginAlterTranslation + */ + public function testMigrationPluginAlterTranslation($source, $expected) { + /** @var \Drupal\Core\Extension\ModuleInstaller $module_installer */ + $module_installer = \Drupal::service('module_installer'); + $module_installer->install(['content_translation']); + $definitions = $source; + migrate_drupal_migration_plugins_alter($definitions); + // Ensure the results have an 'id' key. + foreach ($definitions as $definition) { + $this->assertArrayHasKey('id', $definition); + } + $this->assertSame($expected, $definitions); + + } + + /** + * Data provider for providerMigrationPluginAlterTranslation(). + */ + public function providerMigrationPluginAlterTranslation() { + $tests = []; + + // Test with a d6_taxonomy_vocabulary definition and + // d6_term_node_translation definitions. + $tests[0]['source_data'] = [ + 'd6_taxonomy_vocabulary' => [ + 'id' => 'd6_taxonomy_vocabulary', + 'process' => [ + 'vid' => [ + 'plugin' => 'machine_name', + ], + ], + ], + 'test' => [ + 'id' => 'test', + 'process' => [ + 'nid' => 'nid', + ], - // Tests term node migrations when complete type migration. - $tests[6] = $tests[2]; - $tests[6]['modules'] = ['content_translation']; - $tests[6]['type'] = 'complete'; - $tests[6]['migrations'] = $migrations_src + $system_site_migration; - $tests[6]['expected_data'] = $tests[5]['expected_data']; - $tests[6]['expected_data']['d6_term_node:2']['process']['nid'][0] = [ - 'plugin' => 'migration_lookup', - 'migration' => [ - 'd6_node_complete', - 'd6_node', ], + 'd6_term_node_translation:2' => [ + 'id' => 'd6_term_node_translation:2', + 'process' => [ + 'vid' => [ + 'plugin' => 'machine_name', + ], + ], - 'source' => 'nid', - ]; - $tests[6]['expected_data']['d6_term_node:2']['process']['nid'][2] = [ - 'plugin' => 'node_complete_node_lookup', - ]; - $tests[6]['expected_data']['d6_term_node_revision:4']['process']['vid'][0] = [ - 'plugin' => 'migration_lookup', - 'migration' => [ - 'd6_node_complete', - 'd6_node_revision', ], + 'd6_term_node_translation:4' => [ + 'id' => 'd6_term_node_translation:4', + 'process' => [ + 'vid' => [ + 'plugin' => 'machine_name', + ], + ], - 'source' => 'vid', - ]; - $tests[6]['expected_data']['d6_term_node_revision:4']['process']['vid'][2] = [ - 'plugin' => 'node_complete_node_revision_lookup', - ]; - $tests[6]['expected_data']['d6_term_node_translation:2']['process']['dest_nid'][0] = [ - 'plugin' => 'migration_lookup', - 'migration' => [ - 'd6_node_complete', - 'd6_node_translation', ], - 'source' => 'nid', - ]; - $tests[6]['expected_data']['d6_term_node_translation:2']['process']['dest_nid'][2] = [ - 'plugin' => 'node_complete_node_translation_lookup', ]; + $tests[0]['expected_data'] = $tests[0]['source_data']; + $tests[0]['expected_data']['d6_term_node_translation:2']['process']['taxonomy_forums'] = 'tid'; + $tests[0]['expected_data']['d6_term_node_translation:4']['process']['field_'] = 'tid'; return $tests; } @@ -254,12 +203,6 @@ 'size' => 'normal', 'default' => '0', ], - 'schema_version' => [ - 'type' => 'int', - 'not null' => TRUE, - 'size' => 'normal', - 'default' => '-1', - ], ], ]); $this->sourceDatabase->insert('system') @@ -267,19 +210,11 @@ 'name', 'type', 'status', - 'schema_version', ]) ->values([ 'name' => 'taxonomy', 'type' => 'module', 'status' => '1', - 'schema_version' => '6001', - ]) - ->values([ - 'name' => 'system', - 'type' => 'module', - 'status' => '1', - 'schema_version' => '6056', ]) ->execute(); only in patch2: unchanged: --- a/core/modules/comment/migrations/d6_comment.yml +++ b/core/modules/comment/migrations/d6_comment.yml @@ -24,9 +24,12 @@ process: - plugin: migration_lookup migration: + - d6_node_complete - d6_node - d6_node_translation source: nid + - + plugin: node_complete_node_lookup - plugin: skip_on_empty method: row only in patch2: unchanged: --- a/core/modules/comment/migrations/d7_comment.yml +++ b/core/modules/comment/migrations/d7_comment.yml @@ -25,9 +25,12 @@ process: - plugin: migration_lookup migration: + - d7_node_complete - d7_node - d7_node_translation source: nid + - + plugin: node_complete_node_lookup - plugin: skip_on_empty method: row only in patch2: unchanged: --- a/core/modules/content_translation/migrations/d6_term_node_translation.yml +++ b/core/modules/content_translation/migrations/d6_term_node_translation.yml @@ -11,8 +11,12 @@ process: dest_nid: - plugin: migration_lookup - migration: d6_node_translation + migration: + - d6_node_complete + - d6_node_translation source: nid + - + plugin: node_complete_node_translation_lookup - plugin: skip_on_empty method: row only in patch2: unchanged: --- a/core/modules/content_translation/migrations/node_translation_menu_links.yml +++ b/core/modules/content_translation/migrations/node_translation_menu_links.yml @@ -61,6 +61,8 @@ process: # d7_node_translation mapping tables to find the new node ID. plugin: migration_lookup migration: + - d6_node_complete + - d7_node_complete - d6_node_translation - d7_node_translation no_stub: true only in patch2: unchanged: --- a/core/modules/migrate_drupal/tests/src/Kernel/MigrationPluginAlterTest.php +++ /dev/null @@ -1,377 +0,0 @@ -setupDb(); - } - - /** - * Tests migrate_drupal_migrations_plugin_alter without content_translation. - * - * @dataProvider providerMigrationPluginAlter - */ - public function testMigrationPluginAlterNoTranslation($source, $expected) { - $definitions = $source; - migrate_drupal_migration_plugins_alter($definitions); - // Ensure the results have an 'id' key. - foreach ($definitions as $definition) { - $this->assertArrayHasKey('id', $definition); - } - $this->assertSame($expected, $definitions); - } - - /** - * Data provider for testMigrationPluginAlter(). - */ - public function providerMigrationPluginAlter() { - $tests = []; - - // Test without a d6_taxonomy_vocabulary definition. - $tests[0]['source_data'] = [ - 'test' => [ - 'id' => 'test', - 'process' => [ - 'nid' => 'nid', - ], - ], - ]; - $tests[0]['expected_data'] = $tests[0]['source_data']; - - // Test with a d6_taxonomy_vocabulary definition. - $tests[1]['source_data'] = [ - 'd6_taxonomy_vocabulary' => [ - 'id' => 'd6_taxonomy_vocabulary', - 'process' => [ - 'vid' => [ - 'plugin' => 'machine_name', - ], - ], - ], - 'test' => [ - 'id' => 'test', - 'process' => [ - 'nid' => 'nid', - ], - ], - ]; - $tests[1]['expected_data'] = $tests[1]['source_data']; - - // Test with a d6_taxonomy_vocabulary and term_node definitions. - $tests[2] = $tests[1]; - $tests[2]['source_data']['d6_term_node:2'] = [ - 'id' => 'd6_term_node:2', - 'process' => [ - 'vid' => [ - 'plugin' => 'machine_name', - ], - ], - ]; - $tests[2]['source_data']['d6_term_node_revision:4'] = [ - 'id' => 'd6_term_node_revision:4', - 'process' => [ - 'vid' => [ - 'plugin' => 'machine_name', - ], - ], - ]; - - $tests[2]['expected_data'] = $tests[2]['source_data']; - $tests[2]['expected_data']['d6_term_node:2']['process']['taxonomy_forums'] = 'tid'; - $tests[2]['expected_data']['d6_term_node_revision:4']['process']['field_'] = 'tid'; - - // Test with a d6_taxonomy_vocabulary and term_node_translation definition. - $tests[3] = $tests[1]; - $tests[3]['source_data']['d6_term_node_translation:2'] = [ - 'id' => 'd6_term_node_translation:2', - 'process' => [ - 'vid' => [ - 'plugin' => 'machine_name', - ], - ], - ]; - - $tests[3]['expected_data'] = $tests[3]['source_data']; - return $tests; - } - - /** - * Tests migrate_drupal_migrations_plugin_alter. - * - * @dataProvider providerMigrationPluginAlterTranslation - */ - public function testMigrationPluginAlterTranslation($source, $expected) { - /** @var \Drupal\Core\Extension\ModuleInstaller $module_installer */ - $module_installer = \Drupal::service('module_installer'); - $module_installer->install(['content_translation']); - $definitions = $source; - migrate_drupal_migration_plugins_alter($definitions); - // Ensure the results have an 'id' key. - foreach ($definitions as $definition) { - $this->assertArrayHasKey('id', $definition); - } - $this->assertSame($expected, $definitions); - - } - - /** - * Data provider for providerMigrationPluginAlterTranslation(). - */ - public function providerMigrationPluginAlterTranslation() { - $tests = []; - - // Test with a d6_taxonomy_vocabulary definition and - // d6_term_node_translation definitions. - $tests[0]['source_data'] = [ - 'd6_taxonomy_vocabulary' => [ - 'id' => 'd6_taxonomy_vocabulary', - 'process' => [ - 'vid' => [ - 'plugin' => 'machine_name', - ], - ], - ], - 'test' => [ - 'id' => 'test', - 'process' => [ - 'nid' => 'nid', - ], - ], - 'd6_term_node_translation:2' => [ - 'id' => 'd6_term_node_translation:2', - 'process' => [ - 'vid' => [ - 'plugin' => 'machine_name', - ], - ], - ], - 'd6_term_node_translation:4' => [ - 'id' => 'd6_term_node_translation:4', - 'process' => [ - 'vid' => [ - 'plugin' => 'machine_name', - ], - ], - ], - ]; - - $tests[0]['expected_data'] = $tests[0]['source_data']; - $tests[0]['expected_data']['d6_term_node_translation:2']['process']['taxonomy_forums'] = 'tid'; - $tests[0]['expected_data']['d6_term_node_translation:4']['process']['field_'] = 'tid'; - return $tests; - } - - /** - * Creates data in the source database. - */ - protected function setupDb() { - $this->sourceDatabase->schema()->createTable('system', [ - 'fields' => [ - 'name' => [ - 'type' => 'varchar', - 'not null' => TRUE, - 'length' => '255', - 'default' => '', - ], - 'type' => [ - 'type' => 'varchar', - 'not null' => TRUE, - 'length' => '255', - 'default' => '', - ], - 'status' => [ - 'type' => 'int', - 'not null' => TRUE, - 'size' => 'normal', - 'default' => '0', - ], - ], - ]); - $this->sourceDatabase->insert('system') - ->fields([ - 'name', - 'type', - 'status', - ]) - ->values([ - 'name' => 'taxonomy', - 'type' => 'module', - 'status' => '1', - ]) - ->execute(); - - $this->sourceDatabase->schema()->createTable('variable', [ - 'fields' => [ - 'name' => [ - 'type' => 'varchar', - 'not null' => TRUE, - 'length' => '128', - 'default' => '', - ], - 'value' => [ - 'type' => 'text', - 'not null' => TRUE, - 'size' => 'normal', - ], - ], - ]); - $this->sourceDatabase->insert('variable') - ->fields([ - 'name', - 'value', - ]) - ->values([ - 'name' => 'forum_nav_vocabulary', - 'value' => 's:1:"2";', - ]) - ->execute(); - - $this->sourceDatabase->schema()->createTable('vocabulary', [ - 'fields' => [ - 'vid' => [ - 'type' => 'serial', - 'not null' => TRUE, - 'size' => 'normal', - 'unsigned' => TRUE, - ], - 'name' => [ - 'type' => 'varchar', - 'not null' => TRUE, - 'length' => '255', - 'default' => '', - ], - 'description' => [ - 'type' => 'text', - 'not null' => FALSE, - 'size' => 'normal', - ], - 'help' => [ - 'type' => 'varchar', - 'not null' => TRUE, - 'length' => '255', - 'default' => '', - ], - 'relations' => [ - 'type' => 'int', - 'not null' => TRUE, - 'size' => 'normal', - 'default' => '0', - 'unsigned' => TRUE, - ], - 'hierarchy' => [ - 'type' => 'int', - 'not null' => TRUE, - 'size' => 'normal', - 'default' => '0', - 'unsigned' => TRUE, - ], - 'multiple' => [ - 'type' => 'int', - 'not null' => TRUE, - 'size' => 'normal', - 'default' => '0', - 'unsigned' => TRUE, - ], - 'required' => [ - 'type' => 'int', - 'not null' => TRUE, - 'size' => 'normal', - 'default' => '0', - 'unsigned' => TRUE, - ], - 'tags' => [ - 'type' => 'int', - 'not null' => TRUE, - 'size' => 'normal', - 'default' => '0', - 'unsigned' => TRUE, - ], - 'module' => [ - 'type' => 'varchar', - 'not null' => TRUE, - 'length' => '255', - 'default' => '', - ], - 'weight' => [ - 'type' => 'int', - 'not null' => TRUE, - 'size' => 'normal', - 'default' => '0', - ], - ], - 'primary key' => ['vid'], - ]); - - $this->sourceDatabase->insert('vocabulary') - ->fields([ - 'vid', - 'name', - ]) - ->values([ - 'vid' => '4', - 'name' => 'Tags', - ]) - ->values([ - 'vid' => '2', - 'name' => 'Forums', - ]) - ->execute(); - - $this->sourceDatabase->schema()->createTable('vocabulary_node_types', [ - 'fields' => [ - 'vid' => [ - 'type' => 'int', - 'not null' => TRUE, - 'size' => 'normal', - 'default' => '0', - 'unsigned' => TRUE, - ], - 'type' => [ - 'type' => 'varchar', - 'not null' => TRUE, - 'length' => '32', - 'default' => '', - ], - ], - 'primary key' => [ - 'vid', - 'type', - ], - 'mysql_character_set' => 'utf8', - ]); - - $this->sourceDatabase->insert('vocabulary_node_types') - ->fields([ - 'vid', - 'type', - ]) - ->values([ - 'vid' => '4', - 'type' => 'article', - ]) - ->values([ - 'vid' => '2', - 'type' => 'forum', - ]) - ->execute(); - } - -} only in patch2: unchanged: --- a/core/modules/path/migrations/d6_url_alias.yml +++ b/core/modules/path/migrations/d6_url_alias.yml @@ -35,7 +35,11 @@ process: - 1 - plugin: migration_lookup - migration: d6_node_translation + migration: + - d6_node_complete + - d6_node_translation + - + plugin: node_complete_node_translation_lookup langcode: - plugin: null_coalesce only in patch2: unchanged: --- a/core/modules/path/migrations/d7_url_alias.yml +++ b/core/modules/path/migrations/d7_url_alias.yml @@ -34,7 +34,11 @@ process: - 1 - plugin: migration_lookup - migration: d7_node_translation + migration: + - d7_node_complete + - d7_node_translation + - + plugin: node_complete_node_translation_lookup langcode: plugin: null_coalesce source: only in patch2: unchanged: --- a/core/modules/statistics/migrations/statistics_node_counter.yml +++ b/core/modules/statistics/migrations/statistics_node_counter.yml @@ -10,8 +10,14 @@ process: nid: - plugin: migration_lookup - migration: [d6_node, d7_node] + migration: + - d6_node_complete + - d7_node_complete + - d6_node + - d7_node source: nid + - + plugin: node_complete_node_lookup - plugin: skip_on_empty method: row only in patch2: unchanged: --- a/core/modules/taxonomy/migrations/d6_term_node.yml +++ b/core/modules/taxonomy/migrations/d6_term_node.yml @@ -10,8 +10,12 @@ process: nid: - plugin: migration_lookup - migration: d6_node + migration: + - d6_node_complete + - d6_node source: nid + - + plugin: node_complete_node_lookup - plugin: skip_on_empty method: row only in patch2: unchanged: --- a/core/modules/taxonomy/migrations/d6_term_node_revision.yml +++ b/core/modules/taxonomy/migrations/d6_term_node_revision.yml @@ -11,8 +11,12 @@ process: vid: - plugin: migration_lookup - migration: d6_node_revision + migration: + - d6_node_copmplete + - d6_node_revision source: vid + - + plugin: node_complete_node_revision_lookup - plugin: skip_on_empty method: row