summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNathaniel Catchpole2017-08-18 14:52:47 +0900
committerNathaniel Catchpole2017-08-18 14:52:51 +0900
commit31b67bbb34903a9bf9a0392d0ba4fdace119d4b7 (patch)
tree38c5b09abf71b4469f462dea148b6946a9a0f315
parent93b23b76eeb1ea834f303042a3a399d968907c27 (diff)
Issue #2669030 by maxocub, sbogner: D6 Forum vocabulary is migrated to the wrong D8 field name
(cherry picked from commit 82284fa0bbc8deb689bad2c652902e8f9525bc87)
-rw-r--r--core/modules/forum/tests/src/Kernel/Migrate/d6/MigrateForumConfigsTest.php2
-rw-r--r--core/modules/forum/tests/src/Kernel/Migrate/d6/MigrateForumTest.php77
-rw-r--r--core/modules/migrate_drupal/migrate_drupal.module10
-rw-r--r--core/modules/migrate_drupal/tests/fixtures/drupal6.php158
-rw-r--r--core/modules/migrate_drupal_ui/tests/src/Functional/d6/MigrateUpgrade6Test.php8
-rw-r--r--core/modules/taxonomy/migration_templates/d6_vocabulary_entity_display.yml5
-rw-r--r--core/modules/taxonomy/migration_templates/d6_vocabulary_entity_form_display.yml5
-rw-r--r--core/modules/taxonomy/migration_templates/d6_vocabulary_field.yml5
-rw-r--r--core/modules/taxonomy/migration_templates/d6_vocabulary_field_instance.yml5
-rw-r--r--core/modules/taxonomy/src/Plugin/migrate/process/ForumVocabulary.php34
-rw-r--r--core/modules/taxonomy/src/Plugin/migrate/source/d6/Vocabulary.php8
11 files changed, 309 insertions, 8 deletions
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 7aa848e..302c3d1 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 @@ class MigrateForumConfigsTest extends MigrateDrupal6TestBase {
$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 0000000..6f5d48c
--- /dev/null
+++ b/core/modules/forum/tests/src/Kernel/Migrate/d6/MigrateForumTest.php
@@ -0,0 +1,77 @@
+<?php
+
+namespace Drupal\Tests\forum\Kernel\Migrate\d6;
+
+use Drupal\Core\Entity\Entity\EntityFormDisplay;
+use Drupal\Core\Entity\Entity\EntityViewDisplay;
+use Drupal\field\Entity\FieldConfig;
+use Drupal\field\Entity\FieldStorageConfig;
+use Drupal\node\Entity\Node;
+use Drupal\Tests\node\Kernel\Migrate\d6\MigrateNodeTestBase;
+
+/**
+ * Tests forum migration from Drupal 6 to Drupal 8.
+ *
+ * @group migrate_drupal_6
+ */
+class MigrateForumTest extends MigrateNodeTestBase {
+
+ /**
+ * {@inheritdoc}
+ */
+ public static $modules = [
+ 'comment',
+ 'forum',
+ 'menu_ui',
+ 'taxonomy',
+ ];
+
+ /**
+ * {@inheritdoc}
+ */
+ protected function setUp() {
+ parent::setUp();
+
+ $this->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 8399f3f..2de2595 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 a7beb5b..4ca588b 100644
--- a/core/modules/migrate_drupal/tests/fixtures/drupal6.php
+++ b/core/modules/migrate_drupal/tests/fixtures/drupal6.php
@@ -1942,6 +1942,54 @@ $connection->insert('comments')
'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 @@ $connection->schema()->createTable('forum', array(
'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 @@ $connection->insert('history')
'nid' => '18',
'timestamp' => '1493066711',
))
+->values(array(
+ 'uid' => '1',
+ 'nid' => '19',
+ 'timestamp' => '1501955803',
+))
->execute();
$connection->schema()->createTable('i18n_blocks', array(
@@ -9566,6 +9632,14 @@ $connection->insert('i18n_strings')
'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 @@ $connection->insert('locales_source')
'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 @@ $connection->insert('node')
'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 @@ $connection->insert('node_comment_statistics')
'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 @@ $connection->insert('node_counter')
'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 @@ $connection->insert('node_revisions')
'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 @@ $connection->insert('term_data')
'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(
@@ -46089,6 +46220,10 @@ $connection->insert('term_hierarchy')
'parent' => '0',
))
->values(array(
+ 'tid' => '8',
+ 'parent' => '0',
+))
+->values(array(
'tid' => '3',
'parent' => '2',
))
@@ -46173,6 +46308,11 @@ $connection->insert('term_node')
'vid' => '2',
'tid' => '5',
))
+->values(array(
+ 'nid' => '19',
+ 'vid' => '22',
+ 'tid' => '8',
+))
->execute();
$connection->schema()->createTable('term_relation', array(
@@ -47651,7 +47791,7 @@ $connection->insert('variable')
))
->values(array(
'name' => 'forum_nav_vocabulary',
- 'value' => 's:1:"1";',
+ 'value' => 's:1:"7";',
))
->values(array(
'name' => 'forum_order',
@@ -48255,6 +48395,20 @@ $connection->insert('vocabulary')
'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 @@ $connection->insert('vocabulary_node_types')
'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 418addc..993fdf4 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 @@ class MigrateUpgrade6Test extends MigrateUpgradeTestBase {
'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 @@ class MigrateUpgrade6Test extends MigrateUpgradeTestBase {
'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 e0f4625..7f3fea8 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 20bb0e4..607e735 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 bb4a942..2646555 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 6d9ffa6..f49456d 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 0000000..be4b9cc
--- /dev/null
+++ b/core/modules/taxonomy/src/Plugin/migrate/process/ForumVocabulary.php
@@ -0,0 +1,34 @@
+<?php
+
+namespace Drupal\taxonomy\Plugin\migrate\process;
+
+use Drupal\migrate\MigrateExecutableInterface;
+use Drupal\migrate\ProcessPluginBase;
+use Drupal\migrate\Row;
+
+/**
+ * Checks if the vocabulary being migrated is the one used for forums.
+ *
+ * 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.
+ *
+ * @MigrateProcessPlugin(
+ * id = "forum_vocabulary"
+ * )
+ */
+class ForumVocabulary extends ProcessPluginBase {
+
+ /**
+ * {@inheritdoc}
+ */
+ public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) {
+ if ($row->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 a1c2f69..f8c601d 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 @@ class Vocabulary extends DrupalSqlBase {
->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);
}