Commit 82284fa0 authored by catch's avatar catch

Issue #2669030 by maxocub, sbogner: D6 Forum vocabulary is migrated to the wrong D8 field name

parent a47d8c49
......@@ -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.
......
<?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);
}
}
......@@ -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';
}
}
}
......
......@@ -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(
......@@ -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,
......
......@@ -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:
......
......@@ -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:
......
......@@ -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:
......
......@@ -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'
......
<?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;
}
}
......@@ -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);
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment