diff --git a/core/modules/forum/tests/src/Kernel/Migrate/d6/MigrateForumConfigsTest.php b/core/modules/forum/tests/src/Kernel/Migrate/d6/MigrateForumConfigsTest.php index 7aa848e6df8a6b8aef20d3a41f57d0077a662a5d..302c3d1aee3042b9181a1a383a7cd7028e1d1f4f 100644 --- a/core/modules/forum/tests/src/Kernel/Migrate/d6/MigrateForumConfigsTest.php +++ b/core/modules/forum/tests/src/Kernel/Migrate/d6/MigrateForumConfigsTest.php @@ -36,7 +36,7 @@ public function testForumSettings() { $this->assertIdentical(15, $config->get('topics.hot_threshold')); $this->assertIdentical(25, $config->get('topics.page_limit')); $this->assertIdentical(1, $config->get('topics.order')); - $this->assertIdentical('vocabulary_1_i_0_', $config->get('vocabulary')); + $this->assertIdentical('forums', $config->get('vocabulary')); // This is 'forum_block_num_0' in D6, but block:active:limit' in D8. $this->assertSame(3, $config->get('block.active.limit')); // This is 'forum_block_num_1' in D6, but 'block:new:limit' in D8. diff --git a/core/modules/forum/tests/src/Kernel/Migrate/d6/MigrateForumTest.php b/core/modules/forum/tests/src/Kernel/Migrate/d6/MigrateForumTest.php new file mode 100644 index 0000000000000000000000000000000000000000..6f5d48c1dd4e7bdd1a70253245f8bdd5a9dc0d3d --- /dev/null +++ b/core/modules/forum/tests/src/Kernel/Migrate/d6/MigrateForumTest.php @@ -0,0 +1,77 @@ +installEntitySchema('comment'); + $this->installSchema('comment', ['comment_entity_statistics']); + $this->installSchema('forum', ['forum', 'forum_index']); + $this->installConfig(['comment', 'forum']); + $this->migrateContent(); + $this->migrateTaxonomy(); + $this->executeMigrations([ + 'd6_comment_type', + 'd6_comment_field', + 'd6_comment_field_instance', + 'd6_comment_entity_display', + 'd6_comment_entity_form_display', + 'd6_comment', + 'd6_term_node', + ]); + } + + /** + * Tests forum migration. + */ + public function testForumMigration() { + // Tests that the taxonomy_forums field storage config exists. + $field_storage_config = FieldStorageConfig::load('node.taxonomy_forums'); + $this->assertInstanceOf(FieldStorageConfig::class, $field_storage_config); + + // Tests that the taxonomy_forums field config exists. + $field_config = FieldConfig::load('node.forum.taxonomy_forums'); + $this->assertInstanceOf(FieldConfig::class, $field_config); + + // Tests that the taxonomy_forums entity view display component exists. + $entity_view_display = EntityViewDisplay::load('node.forum.default')->getComponent('taxonomy_forums'); + $this->assertTrue(is_array($entity_view_display)); + + // Tests that the taxonomy_forums entity form display component exists. + $entity_form_display = EntityFormDisplay::load('node.forum.default')->getComponent('taxonomy_forums'); + $this->assertTrue(is_array($entity_form_display)); + + // Test that the taxonomy_forums field has the right value. + $node = Node::load(19); + $this->assertEquals(8, $node->taxonomy_forums->target_id); + } + +} diff --git a/core/modules/migrate_drupal/migrate_drupal.module b/core/modules/migrate_drupal/migrate_drupal.module index 8399f3f4fa884e21c4546bc3f66e70dfec9ff315..2de259515c43ed997658c04378c3db064d686f7f 100644 --- a/core/modules/migrate_drupal/migrate_drupal.module +++ b/core/modules/migrate_drupal/migrate_drupal.module @@ -58,7 +58,15 @@ function migrate_drupal_migration_plugins_alter(&$definitions) { foreach ($plugin_ids as $plugin_id) { // Match the field name derivation in d6_vocabulary_field.yml. $field_name = substr('field_' . $row->getDestinationProperty('vid'), 0, 32); - $definitions[$plugin_id]['process'][$field_name] = 'tid'; + + // The Forum module is expecting 'taxonomy_forums' as the field name + // for the forum nodes. The 'forum_vocabulary' source property is + // evaluated in Drupal\taxonomy\Plugin\migrate\source\d6\Vocabulary + // and is set to true if the vocabulary vid being migrated is the + // same as the one in the 'forum_nav_vocabulary' variable on the + // source site. + $destination_vid = $row->getSourceProperty('forum_vocabulary') ? 'taxonomy_forums' : $field_name; + $definitions[$plugin_id]['process'][$destination_vid] = 'tid'; } } } diff --git a/core/modules/migrate_drupal/tests/fixtures/drupal6.php b/core/modules/migrate_drupal/tests/fixtures/drupal6.php index a7beb5b439a1aee2eca36d576918cfbd94fe197f..4ca588b9c7d5a5746484fd156c8749d774122d0f 100644 --- a/core/modules/migrate_drupal/tests/fixtures/drupal6.php +++ b/core/modules/migrate_drupal/tests/fixtures/drupal6.php @@ -1942,6 +1942,54 @@ 'mail' => 'comment3@example.com', 'homepage' => 'https://www.drupal.org', )) +->values(array( + 'cid' => '4', + 'pid' => '0', + 'nid' => '19', + 'uid' => '1', + 'subject' => 'Subject 1', + 'comment' => 'Comment 1', + 'hostname' => '127.0.0.1', + 'timestamp' => '1501955780', + 'status' => '0', + 'format' => '1', + 'thread' => '01/', + 'name' => 'root', + 'mail' => '', + 'homepage' => '', +)) +->values(array( + 'cid' => '5', + 'pid' => '4', + 'nid' => '19', + 'uid' => '1', + 'subject' => 'Subject 2', + 'comment' => 'Comment 2', + 'hostname' => '127.0.0.1', + 'timestamp' => '1501955792', + 'status' => '0', + 'format' => '1', + 'thread' => '01.00/', + 'name' => 'root', + 'mail' => '', + 'homepage' => '', +)) +->values(array( + 'cid' => '6', + 'pid' => '5', + 'nid' => '19', + 'uid' => '1', + 'subject' => 'Subject 3', + 'comment' => 'Comment 3', + 'hostname' => '127.0.0.1', + 'timestamp' => '1501955803', + 'status' => '0', + 'format' => '1', + 'thread' => '01.00.00/', + 'name' => 'root', + 'mail' => '', + 'homepage' => '', +)) ->execute(); $connection->schema()->createTable('config', array( @@ -8345,6 +8393,19 @@ 'mysql_character_set' => 'utf8', )); +$connection->insert('forum') +->fields(array( + 'nid', + 'vid', + 'tid', +)) +->values(array( + 'nid' => '19', + 'vid' => '22', + 'tid' => '8', +)) +->execute(); + $connection->schema()->createTable('history', array( 'fields' => array( 'uid' => array( @@ -8424,6 +8485,11 @@ 'nid' => '18', 'timestamp' => '1493066711', )) +->values(array( + 'uid' => '1', + 'nid' => '19', + 'timestamp' => '1501955803', +)) ->execute(); $connection->schema()->createTable('i18n_blocks', array( @@ -9566,6 +9632,14 @@ 'objectindex' => '6', 'format' => '0', )) +->values(array( + 'lid' => '1673', + 'objectid' => '7', + 'type' => 'vocabulary', + 'property' => 'name', + 'objectindex' => '7', + 'format' => '0', +)) ->execute(); $connection->schema()->createTable('i18n_variable', array( @@ -22025,6 +22099,13 @@ 'source' => 'Type', 'version' => '1', )) +->values(array( + 'lid' => '1673', + 'location' => 'vocabulary:7:name', + 'textgroup' => 'taxonomy', + 'source' => 'Forums', + 'version' => '1', +)) ->execute(); $connection->schema()->createTable('locales_target', array( @@ -43185,6 +43266,23 @@ 'tnid' => '0', 'translate' => '0', )) +->values(array( + 'nid' => '19', + 'vid' => '22', + 'type' => 'forum', + 'language' => '', + 'title' => 'New Forum Topic', + 'uid' => '1', + 'status' => '1', + 'created' => '1501955771', + 'changed' => '1501955771', + 'comment' => '2', + 'promote' => '0', + 'moderate' => '0', + 'sticky' => '0', + 'tnid' => '0', + 'translate' => '0', +)) ->execute(); $connection->schema()->createTable('node_access', array( @@ -43384,6 +43482,13 @@ 'last_comment_uid' => '1', 'comment_count' => '0', )) +->values(array( + 'nid' => '19', + 'last_comment_timestamp' => '1501955803', + 'last_comment_name' => '', + 'last_comment_uid' => '1', + 'comment_count' => '3', +)) ->execute(); $connection->schema()->createTable('node_counter', array( @@ -43459,6 +43564,12 @@ 'daycount' => '1', 'timestamp' => '1493066711', )) +->values(array( + 'nid' => '19', + 'totalcount' => '4', + 'daycount' => '4', + 'timestamp' => '1501955803', +)) ->execute(); $connection->schema()->createTable('node_revisions', array( @@ -43765,6 +43876,17 @@ 'timestamp' => '1494966544', 'format' => '1', )) +->values(array( + 'nid' => '19', + 'vid' => '22', + 'uid' => '1', + 'title' => 'New Forum Topic', + 'body' => 'New Forum Body', + 'teaser' => 'New Forum Body', + 'log' => '', + 'timestamp' => '1501955771', + 'format' => '1', +)) ->execute(); $connection->schema()->createTable('node_type', array( @@ -46041,6 +46163,15 @@ 'language' => 'fr', 'trid' => '0', )) +->values(array( + 'tid' => '8', + 'vid' => '7', + 'name' => 'General discussion', + 'description' => '', + 'weight' => '0', + 'language' => '', + 'trid' => '0', +)) ->execute(); $connection->schema()->createTable('term_hierarchy', array( @@ -46088,6 +46219,10 @@ 'tid' => '7', 'parent' => '0', )) +->values(array( + 'tid' => '8', + 'parent' => '0', +)) ->values(array( 'tid' => '3', 'parent' => '2', @@ -46173,6 +46308,11 @@ 'vid' => '2', 'tid' => '5', )) +->values(array( + 'nid' => '19', + 'vid' => '22', + 'tid' => '8', +)) ->execute(); $connection->schema()->createTable('term_relation', array( @@ -47651,7 +47791,7 @@ )) ->values(array( 'name' => 'forum_nav_vocabulary', - 'value' => 's:1:"1";', + 'value' => 's:1:"7";', )) ->values(array( 'name' => 'forum_order', @@ -48255,6 +48395,20 @@ 'weight' => '0', 'language' => '', )) +->values(array( + 'vid' => '7', + 'name' => 'Forums', + 'description' => '', + 'help' => '', + 'relations' => '1', + 'hierarchy' => '0', + 'multiple' => '0', + 'required' => '0', + 'tags' => '0', + 'module' => 'taxonomy', + 'weight' => '0', + 'language' => '', +)) ->execute(); $connection->schema()->createTable('vocabulary_node_types', array( @@ -48290,7 +48444,7 @@ 'type' => 'article', )) ->values(array( - 'vid' => '1', + 'vid' => '7', 'type' => 'forum', )) ->values(array( 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 418addc899c0c9e92a551b76c476f6f5d9f97c8e..993fdf493d78a0ee0a79c6cf2872a027b7f2d399 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 @@ -39,19 +39,19 @@ protected function getEntityCounts() { 'block' => 35, 'block_content' => 2, 'block_content_type' => 1, - 'comment' => 3, + 'comment' => 6, 'comment_type' => 3, 'contact_form' => 5, 'configurable_language' => 5, 'editor' => 2, - 'field_config' => 73, + 'field_config' => 72, 'field_storage_config' => 48, 'file' => 7, 'filter_format' => 7, 'image_style' => 5, 'language_content_settings' => 2, 'migration' => 105, - 'node' => 16, + 'node' => 17, 'node_type' => 13, 'rdf_mapping' => 7, 'search_page' => 2, @@ -59,7 +59,7 @@ protected function getEntityCounts() { 'shortcut_set' => 1, 'action' => 23, 'menu' => 8, - 'taxonomy_term' => 7, + 'taxonomy_term' => 8, 'taxonomy_vocabulary' => 7, 'tour' => 4, 'user' => 7, diff --git a/core/modules/taxonomy/migration_templates/d6_vocabulary_entity_display.yml b/core/modules/taxonomy/migration_templates/d6_vocabulary_entity_display.yml index e0f462531bad85c1633b09ca7b1c6c75561a2a8f..7f3fea8a912f2d6f520d5c6886e6006387480513 100644 --- a/core/modules/taxonomy/migration_templates/d6_vocabulary_entity_display.yml +++ b/core/modules/taxonomy/migration_templates/d6_vocabulary_entity_display.yml @@ -44,6 +44,11 @@ process: - plugin: substr length: 32 + - + # This plugin checks if the vocabulary being migrated is the one used for + # forums. If it is, the field name is set to 'taxonomy_forums' as it is + # what the Forum module is expecting. Otherwise, it is left unchanged. + plugin: forum_vocabulary destination: plugin: component_entity_display migration_dependencies: diff --git a/core/modules/taxonomy/migration_templates/d6_vocabulary_entity_form_display.yml b/core/modules/taxonomy/migration_templates/d6_vocabulary_entity_form_display.yml index 20bb0e40c96a886cd099fdc2b2f51dd6f0070a88..607e735be1de63bcd94582c84773ffdfd53f2b39 100644 --- a/core/modules/taxonomy/migration_templates/d6_vocabulary_entity_form_display.yml +++ b/core/modules/taxonomy/migration_templates/d6_vocabulary_entity_form_display.yml @@ -48,6 +48,11 @@ process: - plugin: substr length: 32 + - + # This plugin checks if the vocabulary being migrated is the one used for + # forums. If it is, the field name is set to 'taxonomy_forums' as it is + # what the Forum module is expecting. Otherwise, it is left unchanged. + plugin: forum_vocabulary destination: plugin: component_entity_form_display migration_dependencies: diff --git a/core/modules/taxonomy/migration_templates/d6_vocabulary_field.yml b/core/modules/taxonomy/migration_templates/d6_vocabulary_field.yml index bb4a94223f905957c5df733557c75bfc91d0916b..264655555c7a879c6b87caca914de801ac78ac00 100644 --- a/core/modules/taxonomy/migration_templates/d6_vocabulary_field.yml +++ b/core/modules/taxonomy/migration_templates/d6_vocabulary_field.yml @@ -32,6 +32,11 @@ process: - plugin: substr length: 32 + - + # This plugin checks if the vocabulary being migrated is the one used for + # forums. If it is, the field name is set to 'taxonomy_forums' as it is + # what the Forum module is expecting. Otherwise, it is left unchanged. + plugin: forum_vocabulary 'settings/target_type': 'constants/target_entity_type' cardinality: cardinality destination: diff --git a/core/modules/taxonomy/migration_templates/d6_vocabulary_field_instance.yml b/core/modules/taxonomy/migration_templates/d6_vocabulary_field_instance.yml index 6d9ffa63f9a6bccf71daa9fa9152e1796adc387c..f49456d5feb365f1a704b0308b1a361422655dd0 100644 --- a/core/modules/taxonomy/migration_templates/d6_vocabulary_field_instance.yml +++ b/core/modules/taxonomy/migration_templates/d6_vocabulary_field_instance.yml @@ -39,6 +39,11 @@ process: - plugin: substr length: 32 + - + # This plugin checks if the vocabulary being migrated is the one used for + # forums. If it is, the field name is set to 'taxonomy_forums' as it is + # what the Forum module is expecting. Otherwise, it is left unchanged. + plugin: forum_vocabulary label: name 'settings/handler': 'constants/selection_handler' 'settings/handler_settings/target_bundles/0': '@field_name' diff --git a/core/modules/taxonomy/src/Plugin/migrate/process/ForumVocabulary.php b/core/modules/taxonomy/src/Plugin/migrate/process/ForumVocabulary.php new file mode 100644 index 0000000000000000000000000000000000000000..be4b9cc0b09dacde776363029618ca58b924ad7e --- /dev/null +++ b/core/modules/taxonomy/src/Plugin/migrate/process/ForumVocabulary.php @@ -0,0 +1,34 @@ +getSourceProperty('forum_vocabulary')) { + $value = 'taxonomy_forums'; + } + return $value; + } + +} diff --git a/core/modules/taxonomy/src/Plugin/migrate/source/d6/Vocabulary.php b/core/modules/taxonomy/src/Plugin/migrate/source/d6/Vocabulary.php index a1c2f6912e4e5f57866b3adec71a1f3620d78b92..f8c601d8ebc6de5f4d31a584cce1813e1f172df4 100644 --- a/core/modules/taxonomy/src/Plugin/migrate/source/d6/Vocabulary.php +++ b/core/modules/taxonomy/src/Plugin/migrate/source/d6/Vocabulary.php @@ -69,6 +69,14 @@ public function prepareRow(Row $row) { ->fetchCol(); $row->setSourceProperty('node_types', $node_types); $row->setSourceProperty('cardinality', ($row->getSourceProperty('tags') == 1 || $row->getSourceProperty('multiple') == 1) ? FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED : 1); + + // If the vid of the vocabulary being migrated is equal to the vid in the + // 'forum_nav_vocabulary' variable, set the 'forum_vocabulary' source + // property to true so we can know this is the vocabulary used for forums. + if ($this->variableGet('forum_nav_vocabulary', 0) == $row->getSourceProperty('vid')) { + $row->setSourceProperty('forum_vocabulary', TRUE); + } + return parent::prepareRow($row); }