diff --git a/core/modules/migrate_drupal/migrate_drupal.module b/core/modules/migrate_drupal/migrate_drupal.module index b0b9881d68..bbb0622184 100644 --- a/core/modules/migrate_drupal/migrate_drupal.module +++ b/core/modules/migrate_drupal/migrate_drupal.module @@ -96,7 +96,7 @@ function migrate_drupal_migration_plugins_alter(&$definitions) { // If this source database is multilingual then we are only running the // dN_node_master migration and not any other dN_node* migration. Alter all // instances of migration_lookup in core migrations to use dN_node_master. - if ((new NodeMigrateType)->useMasterNodeMigration($definitions) === NodeMigrateType::NODE_MIGRATE_TYPE_MASTER) { + if ((new NodeMigrateType)->getNodeMigrateType($definitions) === NodeMigrateType::NODE_MIGRATE_TYPE_MASTER) { // Anonymous function to replace classic node migration plugin IDs with the // master plugin ID. @@ -139,11 +139,6 @@ function migrate_drupal_migration_plugins_alter(&$definitions) { 'plugin' => 'node_master_node_translation_lookup', ]; } - - // Pipeline does not extract the migration_lookup return value. - if (preg_match('/d[6,7]_entity_reference_translation($|:.*)/', $definition['id'])) { - $a = 1; - } } // Pipeline does not extract the migration_lookup return value. diff --git a/core/modules/migrate_drupal/src/MigrationConfigurationTrait.php b/core/modules/migrate_drupal/src/MigrationConfigurationTrait.php index b9f30a6669..00c3ffd3ea 100644 --- a/core/modules/migrate_drupal/src/MigrationConfigurationTrait.php +++ b/core/modules/migrate_drupal/src/MigrationConfigurationTrait.php @@ -129,7 +129,7 @@ protected function getMigrations($database_state_key, $drupal_version) { // entity translation migrations. Conversely, if the source database is not // multilingual then we want to run all dN_node* migrations except // dN_node_master. Here we unset the migrations we don't want to run. - $type = $this->useMasterNodeMigration($all_migrations, $drupal_version); + $type = $this->getNodeMigrateType($all_migrations, $drupal_version); if ($type === NodeMigrateType::NODE_MIGRATE_TYPE_MASTER) { $patterns = '/(d' . $drupal_version . '_node:)|(d' . $drupal_version . '_node_translation:)|(d' . $drupal_version . '_node_revision:)|(entity_translation)/'; } @@ -297,15 +297,20 @@ protected function getState() { } /** - * Determines is the node master migration is to be used. + * Determines the type of node migration to be used. * * The node master migration is the default. It is not used when there - * are existing tables for dNnode. + * are existing tables for dN_node. + * + * @param array $migrations + * An array of migrations keyed by migration ID. + * @param string $version + * The legacy Drupal version. * * @return string * Indicator of the node migration map tables in use. */ - protected function useMasterNodeMigration($migrations, $version) { + protected function getNodeMigrateType(array $migrations, $version) { $migrate_type = NodeMigrateType::NODE_MIGRATE_TYPE_MASTER; $node_exists = FALSE; $node_master_exists = FALSE; diff --git a/core/modules/migrate_drupal/src/NodeMigrateType.php b/core/modules/migrate_drupal/src/NodeMigrateType.php index 885f294f79..103982f542 100644 --- a/core/modules/migrate_drupal/src/NodeMigrateType.php +++ b/core/modules/migrate_drupal/src/NodeMigrateType.php @@ -23,7 +23,7 @@ final class NodeMigrateType { const NODE_MIGRATE_TYPE_BOTH = 'BOTH'; /** - * Determines is the node master migration is to be used. + * Determines the type of node migration to be used. * * The node master migration is the default. It is not used when there * are existing tables for dN_node. @@ -42,7 +42,7 @@ final class NodeMigrateType { * @internal * Only to be used by migrate_drupal_migration_plugins_alter(). */ - public function useMasterNodeMigration(array $definitions) { + public function getNodeMigrateType(array $definitions) { $migrate_type = static::NODE_MIGRATE_TYPE_MASTER; $version = ''; @@ -103,7 +103,7 @@ public function useMasterNodeMigration(array $definitions) { $connection = \Drupal::database(); // Find out what migrate map tables exist for the node migrations. It is - // either the classic, 'd*_node', or the master, 'd*_node_master', or both + // either the classic, 'dN_node', or the master, 'dN_node_master', or both // This is used to set the type of migration that is being run. $bases = ['node', 'node_master']; $tables = $connection->schema() diff --git a/core/modules/migrate_drupal/tests/src/Kernel/MigrationPluginAlterTest.php b/core/modules/migrate_drupal/tests/src/Kernel/MigrationPluginAlterTest.php index 74dd7ee219..9c9a5c669c 100644 --- a/core/modules/migrate_drupal/tests/src/Kernel/MigrationPluginAlterTest.php +++ b/core/modules/migrate_drupal/tests/src/Kernel/MigrationPluginAlterTest.php @@ -5,7 +5,7 @@ use Drupal\Tests\migrate\Kernel\MigrateTestBase; /** - * Tests migrate_drupal_migrations_plugin_alter for d6 term node migrations. + * Tests migrate_drupal_migrations_plugin_alter. * * @group migrate_drupal */ @@ -14,7 +14,7 @@ class MigrationPluginAlterTest extends MigrateTestBase { /** * {@inheritdoc} */ - public static $modules = ['migrate_drupal', 'taxonomy', 'node_migrate_master']; + public static $modules = ['migrate_drupal', 'taxonomy']; /** * {@inheritdoc} @@ -25,12 +25,24 @@ protected function setUp() { } /** - * Tests migrate_drupal_migrations_plugin_alter without content_translation. + * Tests migrate_drupal_migrations_plugin_alter. + * + * @param array $modules + * An array of modules to install. + * @param array $migrations + * An array of migrations. + * @param array $expected + * The expected results.. + * + * @dataProvider providerMigrationPluginAlter * - * @dataProvider providerMigrationPluginAlterNoTranslation + * @throws \Drupal\Core\Extension\MissingDependencyException */ - public function testMigrationPluginAlterNoTranslation($source, $expected) { - $definitions = $source; + public function testMigrationPluginAlter(array $modules, array $migrations, array $expected) { + /** @var \Drupal\Core\Extension\ModuleInstaller $module_installer */ + $module_installer = \Drupal::service('module_installer'); + $module_installer->install($modules); + $definitions = $migrations; migrate_drupal_migration_plugins_alter($definitions); // Ensure the results have an 'id' key. foreach ($definitions as $definition) { @@ -40,197 +52,88 @@ public function testMigrationPluginAlterNoTranslation($source, $expected) { } /** - * Data provider for testMigrationPluginAlterNoTranslation(). + * Data provider for testMigrationPluginAlter(). */ - public function providerMigrationPluginAlterNoTranslation() { - $tests = $this->getTestData(); + public function providerMigrationPluginAlter() { + $tests = []; - // Test with a d6_taxonomy_vocabulary definition and term node definitions. - $tests[2]['expected_data']['d6_taxonomy_vocabulary'] = [ - 'id' => 'd6_taxonomy_vocabulary', - 'process' => [ - 'vid' => [ - 'plugin' => 'machine_name', - ], - ], - ]; - $tests[2]['expected_data']['d6_term_node:2'] = [ - 'id' => 'd6_term_node:2', - 'process' => [ - 'nid' => [ - 0 => [ - 'plugin' => 'migration_lookup', - 'migration' => [ - 'd6_node_master', - 'd6_node', - ], - 'source' => 'nid', - ], - 2 => [ - 'plugin' => 'node_master_node_lookup', - ], - ], - 'taxonomy_forums' => 'tid', - ], - 'destination' => [ - 'plugin' => 'entity_master:node', - ], - ]; - $tests[2]['expected_data']['d6_term_node_revision:4'] = [ - 'id' => 'd6_term_node_revision:4', - 'process' => [ - 'vid' => [ - 0 => [ - 'plugin' => 'migration_lookup', - 'migration' => [ - 'd6_node_master', - 'd6_node_revision', - ], - 'source' => 'vid', - ], - 2 => [ - 'plugin' => 'node_master_node_revision_lookup', - ], + // Tests migrations that should never be altered, once without an extra + // modules installed, then with content_translation installed and finally + // with 'node_migrate_master' installed. + $migrations = [ + 'test' => [ + 'id' => 'test', + 'process' => [ + 'nid' => 'nid', ], - 'field_' => 'tid', ], - ]; - $tests[2]['expected_data']['d6_term_node_translation:2'] = [ - 'id' => 'd6_term_node_translation:2', - 'process' => [ - 'dest_nid' => [ - 0 => [ - 'plugin' => 'migration_lookup', - 'migration' => [ - 'd6_node_master', - 'd6_node_translation', - ], - 'source' => 'nid', - ], - 2 => [ - 'plugin' => 'node_master_node_translation_lookup', + 'd6_taxonomy_vocabulary' => [ + 'id' => 'd6_taxonomy_vocabulary', + 'process' => [ + 'vid' => [ + 'plugin' => 'machine_name', ], ], ], ]; + $tests[0]['modules'] = []; + $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'] = ['node_migrate_master']; - // Repeat test2 without a d6_taxonomy_vocabulary definition. - $tests[3] = $tests[2]; - unset($tests[3]['source_data']['d6_taxonomy_vocabulary']); - unset($tests[3]['expected_data']['d6_taxonomy_vocabulary']); - unset($tests[3]['expected_data']['d6_term_node:2']['process']['taxonomy_forums']); - unset($tests[3]['expected_data']['d6_term_node_revision:4']['process']['field_']); - - // Test migration dependency changes. - $tests[4]['source_data'] = [ - 'd7_node_revision' => [ - 'id' => 'd7_node_revision', - 'destination' => [ - 'plugin' => 'entity_revision:node', - ], - 'migration_dependencies' => [ - 'required' => ['d7_node'], - ], - ], - ]; - $tests[4]['source_data'] = [ - 'node_translation_menu_links' => [ - 'id' => 'node_translation_menu_links', + // 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' => [ - 'new_nid' => [ - 0 => 'foo', - 1 => 'foo', - 2 => 'foo', - 3 => 'foo', - 4 => [ - 'migration' => [], + 'nid' => [ + [ + 'plugin' => 'migration_lookup', + 'migration' => 'd6_node', + 'source' => 'nid', ], ], ], 'destination' => [ 'plugin' => 'entity:node', ], - 'migration_dependencies' => [ - 'required' => [], - 'optional' => [ - 'd6_menu_links', - 'd6_node_translation', - 'd7_menu_links', - 'd7_node_translation', - ], - ], ], - ]; - - $tests[4]['expected_data'] = [ - 'd7_node_revision' => [ - 'id' => 'd7_node_revision', - 'destination' => [ - 'plugin' => 'entity_master:node', - ], - 'migration_dependencies' => [ - 'required' => ['d7_node'], - ], - ], - ]; - $tests[4]['expected_data'] = [ - 'node_translation_menu_links' => [ - 'id' => 'node_translation_menu_links', + 'd6_term_node_revision:4' => [ + 'id' => 'd6_term_node_revision:4', 'process' => [ - 'new_nid' => [ - 0 => 'foo', - 1 => 'foo', - 2 => 'foo', - 3 => 'foo', - 4 => [ - 'migration' => [], + 'vid' => [ + [ + 'plugin' => 'migration_lookup', + 'migration' => 'd6_node_revision', + 'source' => 'vid', ], ], ], - 'destination' => [ - 'plugin' => 'entity_master:node', - ], - 'migration_dependencies' => [ - 'required' => [], - 'optional' => [ - 'd6_menu_links', - 'd6_node_master', - 'd7_menu_links', - 'd7_node_master', + ], + 'd6_term_node_translation:2' => [ + 'id' => 'd6_term_node_translation:2', + 'process' => [ + 'dest_nid' => [ + [ + 'plugin' => 'migration_lookup', + 'migration' => 'd6_node_translation', + 'source' => 'nid', + ], ], ], ], ]; + $tests[3]['modules'] = []; + $tests[3]['migrations'] = $migrations_src; + $tests[3]['expected_data'] = $migrations_src; - 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 = $this->getTestData(); - - // Test with a d6_taxonomy_vocabulary definition and term node definitions. - $tests[2]['expected_data']['d6_taxonomy_vocabulary'] = [ + // 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' => [ @@ -238,168 +141,58 @@ public function providerMigrationPluginAlterTranslation() { ], ], ]; - $tests[2]['expected_data']['d6_term_node:2'] = [ - 'id' => 'd6_term_node:2', - 'process' => [ - 'nid' => [ - 0 => [ - 'plugin' => 'migration_lookup', - 'migration' => [ - 'd6_node_master', - 'd6_node', - ], - 'source' => 'nid', - ], - 2 => [ - 'plugin' => 'node_master_node_lookup', - ], - ], - 'taxonomy_forums' => 'tid', - ], - 'destination' => [ - 'plugin' => 'entity_master:node', - ], - ]; - $tests[2]['expected_data']['d6_term_node_revision:4'] = [ - 'id' => 'd6_term_node_revision:4', - 'process' => [ - 'vid' => [ - 0 => [ - 'plugin' => 'migration_lookup', - 'migration' => [ - 'd6_node_master', - 'd6_node_revision', - ], - 'source' => 'vid', - ], - 2 => [ - 'plugin' => 'node_master_node_revision_lookup', - ], - ], - 'field_' => 'tid', - ], - ]; - $tests[2]['expected_data']['d6_term_node_translation:2'] = [ - 'id' => 'd6_term_node_translation:2', - 'process' => [ - 'dest_nid' => [ - 0 => [ - 'plugin' => 'migration_lookup', - 'migration' => [ - 'd6_node_master', - 'd6_node_translation', - ], - 'source' => 'nid', - ], - 2 => [ - 'plugin' => 'node_master_node_translation_lookup', - ], - ], - 'taxonomy_forums' => 'tid', - ], - ]; + $tests[4]['modules'] = []; + $tests[4]['migrations'] = $migrations_src; + $tests[4]['expected_data'] = $migrations_src; + $tests[4]['expected_data']['d6_term_node:2']['process']['taxonomy_forums'] = 'tid'; + $tests[4]['expected_data']['d6_term_node_revision:4']['process']['field_'] = 'tid'; - // Repeat test2 without a d6_taxonomy_vocabulary definition. - $tests[3] = $tests[2]; - unset($tests[3]['source_data']['d6_taxonomy_vocabulary']); - unset($tests[3]['expected_data']['d6_taxonomy_vocabulary']); - unset($tests[3]['expected_data']['d6_term_node:2']['process']['taxonomy_forums']); - unset($tests[3]['expected_data']['d6_term_node_revision:4']['process']['field_']); - unset($tests[3]['expected_data']['d6_term_node_translation:2']['process']['taxonomy_forums']); - 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]['migrations'] = $migrations_src; + $tests[5]['expected_data'] = $tests[4]['expected_data']; + $tests[5]['expected_data']['d6_term_node_translation:2']['process']['taxonomy_forums'] = 'tid'; - /** - * Source data for testing with and without content_translation installed. - */ - protected function getTestData() { - $tests = []; - - // Test without a d6_taxonomy_vocabulary definition. - $tests[0]['source_data'] = [ - 'test' => [ - 'id' => 'test', - 'process' => [ - 'nid' => 'nid', - ], + // Tests term node migrations when node_migrate_master is installed. + $tests[6] = $tests[2]; + $tests[6]['modules'] = ['content_translation', 'node_migrate_master']; + $tests[6]['migrations'] = $migrations_src; + $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_master', + 'd6_node', ], + 'source' => '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[6]['expected_data']['d6_term_node:2']['process']['nid'][2] = [ + 'plugin' => 'node_master_node_lookup', ]; - $tests[1]['expected_data'] = $tests[1]['source_data']; - - // Test with a d6_taxonomy_vocabulary definition and term node definitions. - $tests[2]['source_data'] = [ - 'd6_taxonomy_vocabulary' => [ - 'id' => 'd6_taxonomy_vocabulary', - 'process' => [ - 'vid' => [ - 'plugin' => 'machine_name', - ], - ], + $tests[6]['expected_data']['d6_term_node_revision:4']['process']['vid'][0] = [ + 'plugin' => 'migration_lookup', + 'migration' => [ + 'd6_node_master', + 'd6_node_revision', ], + 'source' => 'vid', ]; - $tests[2]['source_data']['d6_term_node:2'] = [ - 'id' => 'd6_term_node:2', - 'process' => [ - 'nid' => [ - [ - 'plugin' => 'migration_lookup', - 'migration' => 'd6_node', - 'source' => 'nid', - ], - ], - ], - 'destination' => [ - 'plugin' => 'entity:node', - ], + $tests[6]['expected_data']['d6_term_node_revision:4']['process']['vid'][2] = [ + 'plugin' => 'node_master_node_revision_lookup', ]; - $tests[2]['source_data']['d6_term_node_revision:4'] = [ - 'id' => 'd6_term_node_revision:4', - 'process' => [ - 'vid' => [ - [ - 'plugin' => 'migration_lookup', - 'migration' => 'd6_node_revision', - 'source' => 'vid', - ], - ], + $tests[6]['expected_data']['d6_term_node_translation:2']['process']['dest_nid'][0] = [ + 'plugin' => 'migration_lookup', + 'migration' => [ + 'd6_node_master', + 'd6_node_translation', ], + 'source' => 'nid', ]; - $tests[2]['source_data']['d6_term_node_translation:2'] = [ - 'id' => 'd6_term_node_translation:2', - 'process' => [ - 'dest_nid' => [ - [ - 'plugin' => 'migration_lookup', - 'migration' => 'd6_node_translation', - 'source' => 'nid', - ], - ], - ], + $tests[6]['expected_data']['d6_term_node_translation:2']['process']['dest_nid'][2] = [ + 'plugin' => 'node_master_node_translation_lookup', ]; - - // Repeat test2 without a d6_taxonomy_vocabulary definition. - $tests[3] = $tests[2]; - unset($tests[3]['source_data']['d6_taxonomy_vocabulary']); - return $tests; }