diff -u b/core/modules/comment/migrations/d6_comment.yml b/core/modules/comment/migrations/d6_comment.yml --- b/core/modules/comment/migrations/d6_comment.yml +++ b/core/modules/comment/migrations/d6_comment.yml @@ -65,10 +65,9 @@ required: + - d6_node - d6_comment_type - d6_comment_entity_display - d6_comment_entity_form_display - d6_user - d6_filter_format optional: - - d6_node - - d6_node_complete - d6_node_translation diff -u b/core/modules/comment/migrations/d7_comment.yml b/core/modules/comment/migrations/d7_comment.yml --- b/core/modules/comment/migrations/d7_comment.yml +++ b/core/modules/comment/migrations/d7_comment.yml @@ -62,6 +62,5 @@ required: + - d7_node - d7_comment_type optional: - - d7_node - - d7_node_complete - d7_node_translation diff -u b/core/modules/content_translation/migrations/d6_term_node_translation.yml b/core/modules/content_translation/migrations/d6_term_node_translation.yml --- b/core/modules/content_translation/migrations/d6_term_node_translation.yml +++ b/core/modules/content_translation/migrations/d6_term_node_translation.yml @@ -47,5 +47,3 @@ - d6_vocabulary_entity_form_display - optional: - d6_node - - d6_node_complete - d6_node_translation diff -u b/core/modules/content_translation/migrations/node_translation_menu_links.yml b/core/modules/content_translation/migrations/node_translation_menu_links.yml --- b/core/modules/content_translation/migrations/node_translation_menu_links.yml +++ b/core/modules/content_translation/migrations/node_translation_menu_links.yml @@ -115,8 +115,6 @@ no_stub: true migration_dependencies: optional: - - d6_node_complete - - d7_node_complete - d6_menu_links - d6_node_translation - d7_menu_links 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 @@ -1464,0 +1465,29 @@ + + +/** + * Implements hook_migration_plugins_alter(). + */ +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) { + + // Anonymous function to replace classic node migration plugin IDs with the + // complete plugin ID. + $replace_with_complete_migration = function (&$value) { + if (is_string($value)) { + $value = preg_replace('/d([67])_(node|node_translation|node_revision|node_entity_translation)($|:.*)/', 'd$1_node_complete$3', $value); + } + return $value; + }; + + foreach ($definitions as &$definition) { + $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); + } + } + + } +} 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(); diff -u b/core/modules/taxonomy/migrations/d6_term_node.yml b/core/modules/taxonomy/migrations/d6_term_node.yml --- b/core/modules/taxonomy/migrations/d6_term_node.yml +++ b/core/modules/taxonomy/migrations/d6_term_node.yml @@ -30,3 +30 @@ - optional: - d6_node - - d6_node_complete diff -u b/core/modules/taxonomy/migrations/d6_term_node_revision.yml b/core/modules/taxonomy/migrations/d6_term_node_revision.yml --- b/core/modules/taxonomy/migrations/d6_term_node_revision.yml +++ b/core/modules/taxonomy/migrations/d6_term_node_revision.yml @@ -29,4 +29,2 @@ - d6_term_node - optional: - - d6_node_complete - d6_node_revision 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(); - } - -}