Commit 53b2cf8b authored by catch's avatar catch

Issue #2981392 by masipila, maxocub: Comment migration corrupts data with multilingual sites

(cherry picked from commit b42529c4)
parent 5e1827e8
......@@ -16,7 +16,16 @@ process:
plugin: migration_lookup
migration: d6_comment
source: pid
entity_id: nid
entity_id:
-
plugin: migration_lookup
migration:
- d6_node
- d6_node_translation
source: nid
-
plugin: skip_on_empty
method: row
entity_type: 'constants/entity_type'
comment_type:
-
......@@ -26,6 +35,7 @@ process:
-
plugin: skip_on_empty
method: row
langcode: language
field_name: '@comment_type'
subject: subject
uid: uid
......@@ -52,3 +62,5 @@ migration_dependencies:
- d6_comment_entity_form_display
- d6_user
- d6_filter_format
optional:
- d6_node_translation
......@@ -17,7 +17,16 @@ process:
plugin: migration_lookup
migration: d7_comment
source: pid
entity_id: nid
entity_id:
-
plugin: migration_lookup
migration:
- d7_node
- d7_node_translation
source: nid
-
plugin: skip_on_empty
method: row
entity_type: 'constants/entity_type'
comment_type:
-
......@@ -27,6 +36,7 @@ process:
-
plugin: skip_on_empty
method: row
langcode: language
field_name: '@comment_type'
subject: subject
uid: uid
......@@ -45,3 +55,5 @@ migration_dependencies:
required:
- d7_node
- d7_comment_type
optional:
- d7_node_translation
......@@ -25,7 +25,7 @@ public function query() {
'mail', 'homepage', 'format',
]);
$query->innerJoin('node', 'n', 'c.nid = n.nid');
$query->fields('n', ['type']);
$query->fields('n', ['type', 'language']);
$query->orderBy('c.timestamp');
return $query;
}
......@@ -61,6 +61,13 @@ protected function prepareComment(Row $row) {
// In D6, status=0 means published, while in D8 means the opposite.
// See https://www.drupal.org/node/237636.
$row->setSourceProperty('status', !$row->getSourceProperty('status'));
// If node did not have a language, use site default language as a fallback.
if (!$row->getSourceProperty('language')) {
$language_default = $this->variableGet('language_default', NULL);
$language = $language_default ? $language_default->language : 'en';
$row->setSourceProperty('language', $language);
}
return $row;
}
......@@ -84,6 +91,7 @@ public function fields() {
'mail' => $this->t("The comment author's email address from the comment form, if user is anonymous, and the 'Anonymous users may/must leave their contact information' setting is turned on."),
'homepage' => $this->t("The comment author's home page address from the comment form, if user is anonymous, and the 'Anonymous users may/must leave their contact information' setting is turned on."),
'type' => $this->t("The {node}.type to which this comment is a reply."),
'language' => $this->t("The {node}.language to which this comment is a reply. Site default language is used as a fallback if node does not have a language."),
];
}
......
......@@ -72,6 +72,7 @@ public function fields() {
'name' => $this->t("The comment author's name. Uses {users}.name if the user is logged in, otherwise uses the value typed into the comment form."),
'mail' => $this->t("The comment author's email address from the comment form, if user is anonymous, and the 'Anonymous users may/must leave their contact information' setting is turned on."),
'homepage' => $this->t("The comment author's home page address from the comment form, if user is anonymous, and the 'Anonymous users may/must leave their contact information' setting is turned on."),
'language' => $this->t('The comment language.'),
'type' => $this->t("The {node}.type to which this comment is a reply."),
];
}
......
......@@ -20,7 +20,12 @@ class MigrateCommentTest extends MigrateDrupal6TestBase {
/**
* {@inheritdoc}
*/
public static $modules = ['comment', 'menu_ui'];
public static $modules = [
'comment',
'content_translation',
'language',
'menu_ui',
];
/**
* {@inheritdoc}
......@@ -31,6 +36,7 @@ protected function setUp() {
$this->installEntitySchema('node');
$this->installEntitySchema('comment');
$this->installSchema('comment', ['comment_entity_statistics']);
$this->installSchema('node', ['node_access']);
$this->installConfig(['comment']);
// The entity.node.canonical route must exist when the RDF hook is called.
......@@ -38,7 +44,10 @@ protected function setUp() {
$this->migrateContent();
$this->executeMigrations([
'language',
'd6_language_content_settings',
'd6_node',
'd6_node_translation',
'd6_comment_type',
'd6_comment_field',
'd6_comment_field_instance',
......@@ -84,6 +93,31 @@ public function testMigration() {
$node = $comment->getCommentedEntity();
$this->assertInstanceOf(NodeInterface::class, $node);
$this->assertSame('1', $node->id());
// Tests that the language of the comment is migrated from the node.
$comment = Comment::load(7);
$this->assertSame('Comment to John Smith - EN', $comment->subject->value);
$this->assertSame('This is an English comment.', $comment->comment_body->value);
$this->assertSame('21', $comment->getCommentedEntityId());
$this->assertSame('node', $comment->getCommentedEntityTypeId());
$this->assertSame('en', $comment->language()->getId());
$node = $comment->getCommentedEntity();
$this->assertInstanceOf(NodeInterface::class, $node);
$this->assertSame('21', $node->id());
// Tests that the comment language is correct and that the commented entity
// is correctly migrated when the comment was posted to a node translation.
$comment = Comment::load(8);
$this->assertSame('Comment to John Smith - FR', $comment->subject->value);
$this->assertSame('This is a French comment.', $comment->comment_body->value);
$this->assertSame('21', $comment->getCommentedEntityId());
$this->assertSame('node', $comment->getCommentedEntityTypeId());
$this->assertSame('fr', $comment->language()->getId());
$node = $comment->getCommentedEntity();
$this->assertInstanceOf(NodeInterface::class, $node);
$this->assertSame('21', $node->id());
}
}
......@@ -19,9 +19,11 @@ class MigrateCommentTest extends MigrateDrupal7TestBase {
*/
public static $modules = [
'comment',
'content_translation',
'datetime',
'filter',
'image',
'language',
'link',
'menu_ui',
'node',
......@@ -40,12 +42,16 @@ protected function setUp() {
$this->installEntitySchema('comment');
$this->installConfig(['comment', 'node']);
$this->installSchema('comment', ['comment_entity_statistics']);
$this->installSchema('node', ['node_access']);
$this->executeMigrations([
'language',
'd7_node_type',
'd7_language_content_settings',
'd7_user_role',
'd7_user',
'd7_node_type',
'd7_node',
'd7_node_translation',
'd7_comment_type',
'd7_comment_field',
'd7_comment_field_instance',
......@@ -73,6 +79,7 @@ public function testMigration() {
$this->assertSame('This is a comment', $comment->comment_body->value);
$this->assertSame('filtered_html', $comment->comment_body->format);
$this->assertSame('2001:db8:ffff:ffff:ffff:ffff:ffff:ffff', $comment->getHostname());
$this->assertSame('und', $comment->language()->getId());
$this->assertSame('1000000', $comment->field_integer->value);
$node = $comment->getCommentedEntity();
......@@ -85,6 +92,21 @@ public function testMigration() {
$this->assertInstanceOf(Comment::class, $comment);
$this->assertSame('TNG for the win!', $comment->getSubject());
$this->assertSame('TNG is better than DS9.', $comment->comment_body->value);
$this->assertSame('en', $comment->language()->getId());
// Tests that the commented entity is correctly migrated when the comment
// was posted to a node translation.
$comment = Comment::load(3);
$this->assertInstanceOf(Comment::class, $comment);
$this->assertSame('Comment to IS translation', $comment->getSubject());
$this->assertSame('This is a comment to an Icelandic translation.', $comment->comment_body->value);
$this->assertSame('2', $comment->getCommentedEntityId());
$this->assertSame('node', $comment->getCommentedEntityTypeId());
$this->assertSame('is', $comment->language()->getId());
$node = $comment->getCommentedEntity();
$this->assertInstanceOf(NodeInterface::class, $node);
$this->assertSame('2', $node->id());
}
}
......@@ -66,10 +66,12 @@ public function providerSource() {
[
'nid' => 2,
'type' => 'story',
'language' => 'en',
],
[
'nid' => 3,
'type' => 'page',
'language' => 'fr',
],
];
......@@ -91,6 +93,7 @@ public function providerSource() {
'homepage' => '',
'format' => 'testformat2',
'type' => 'page',
'language' => 'fr',
],
];
......
......@@ -65,10 +65,12 @@ public function providerSource() {
[
'nid' => 2,
'type' => 'story',
'language' => 'en',
],
[
'nid' => 3,
'type' => 'page',
'language' => 'fr',
],
];
......@@ -90,6 +92,7 @@ public function providerSource() {
'homepage' => '',
'format' => 'testformat1',
'type' => 'story',
'language' => 'en',
],
[
'cid' => 2,
......@@ -107,6 +110,7 @@ public function providerSource() {
'homepage' => '',
'format' => 'testformat2',
'type' => 'page',
'language' => 'fr',
],
];
......
......@@ -1990,6 +1990,38 @@
'mail' => '',
'homepage' => '',
))
->values(array(
'cid' => '7',
'pid' => '0',
'nid' => '21',
'uid' => '1',
'subject' => 'Comment to John Smith - EN',
'comment' => 'This is an English comment.',
'hostname' => '2001:14ba:13f8:300:d9d0:363c:9fe4:66e1',
'timestamp' => '1534014729',
'status' => '0',
'format' => '1',
'thread' => '01/',
'name' => 'root',
'mail' => '',
'homepage' => '',
))
->values(array(
'cid' => '8',
'pid' => '0',
'nid' => '22',
'uid' => '1',
'subject' => 'Comment to John Smith - FR',
'comment' => 'This is a French comment.',
'hostname' => '2001:14ba:13f8:300:d9d0:363c:9fe4:66e1',
'timestamp' => '1534014763',
'status' => '0',
'format' => '1',
'thread' => '01/',
'name' => 'root',
'mail' => '',
'homepage' => '',
))
->execute();
$connection->schema()->createTable('config', array(
......@@ -2168,6 +2200,18 @@
'delta' => '0',
'field_company_nid' => '15',
))
->values(array(
'vid' => '2002',
'nid' => '21',
'delta' => '0',
'field_company_nid' => NULL,
))
->values(array(
'vid' => '2003',
'nid' => '22',
'delta' => '0',
'field_company_nid' => NULL,
))
->values(array(
'vid' => '21',
'nid' => '18',
......@@ -3518,6 +3562,20 @@
'field_company_2_nid' => '15',
'field_company_3_nid' => '16',
))
->values(array(
'vid' => '2002',
'nid' => '21',
'field_commander_uid' => NULL,
'field_company_2_nid' => NULL,
'field_company_3_nid' => NULL,
))
->values(array(
'vid' => '2003',
'nid' => '22',
'field_commander_uid' => NULL,
'field_company_2_nid' => NULL,
'field_company_3_nid' => NULL,
))
->execute();
$connection->schema()->createTable('content_type_page', array(
......@@ -8666,6 +8724,16 @@
'nid' => '19',
'timestamp' => '1501955803',
))
->values(array(
'uid' => '1',
'nid' => '21',
'timestamp' => '1534014729',
))
->values(array(
'uid' => '1',
'nid' => '22',
'timestamp' => '1534014763',
))
->execute();
$connection->schema()->createTable('i18n_blocks', array(
......@@ -43733,6 +43801,40 @@
'tnid' => '12',
'translate' => '0',
))
->values(array(
'nid' => '21',
'vid' => '2002',
'type' => 'employee',
'language' => 'en',
'title' => 'John Smith - EN',
'uid' => '1',
'status' => '1',
'created' => '1534014650',
'changed' => '1534014650',
'comment' => '2',
'promote' => '1',
'moderate' => '0',
'sticky' => '0',
'tnid' => '21',
'translate' => '0',
))
->values(array(
'nid' => '22',
'vid' => '2003',
'type' => 'employee',
'language' => 'fr',
'title' => 'John Smith - FR',
'uid' => '1',
'status' => '1',
'created' => '1534014687',
'changed' => '1534014687',
'comment' => '2',
'promote' => '1',
'moderate' => '0',
'sticky' => '0',
'tnid' => '21',
'translate' => '0',
))
->execute();
$connection->schema()->createTable('node_access', array(
......@@ -43939,6 +44041,20 @@
'last_comment_uid' => '1',
'comment_count' => '3',
))
->values(array(
'nid' => '21',
'last_comment_timestamp' => '1534014729',
'last_comment_name' => '',
'last_comment_uid' => '1',
'comment_count' => '1',
))
->values(array(
'nid' => '22',
'last_comment_timestamp' => '1534014763',
'last_comment_name' => '',
'last_comment_uid' => '1',
'comment_count' => '1',
))
->execute();
$connection->schema()->createTable('node_counter', array(
......@@ -44074,6 +44190,18 @@
'daycount' => '4',
'timestamp' => '1501955803',
))
->values(array(
'nid' => '21',
'totalcount' => '3',
'daycount' => '3',
'timestamp' => '1534014729',
))
->values(array(
'nid' => '22',
'totalcount' => '3',
'daycount' => '3',
'timestamp' => '1534014763',
))
->execute();
$connection->schema()->createTable('node_revisions', array(
......@@ -44402,6 +44530,28 @@
'timestamp' => '1390095702',
'format' => '1',
))
->values(array(
'nid' => '21',
'vid' => '2002',
'uid' => '1',
'title' => 'John Smith - EN',
'body' => 'This is an English Bio text for employee John Smith. There is also a French translation to this node. Both language versions have comments.',
'teaser' => 'This is an English Bio text for employee John Smith. There is also a French translation to this node. Both language versions have comments.',
'log' => '',
'timestamp' => '1534014650',
'format' => '1',
))
->values(array(
'nid' => '22',
'vid' => '2003',
'uid' => '1',
'title' => 'John Smith - FR',
'body' => 'This is a French Bio text for employee John Smith. The original node is in English. Both language versions have comments.',
'teaser' => 'This is a French Bio text for employee John Smith. The original node is in English. Both language versions have comments.',
'log' => '',
'timestamp' => '1534014687',
'format' => '1',
))
->execute();
$connection->schema()->createTable('node_type', array(
......@@ -2566,6 +2566,22 @@
'homepage' => '',
'language' => 'en',
))
->values(array(
'cid' => '3',
'pid' => '0',
'nid' => '3',
'uid' => '1',
'subject' => 'Comment to IS translation',
'hostname' => '46.132.185.242',
'created' => '1533031490',
'changed' => '1533031490',
'status' => '1',
'thread' => '01/',
'name' => 'admin',
'mail' => '',
'homepage' => '',
'language' => 'is',
))
->execute();
$connection->schema()->createTable('contact', array(
......@@ -4883,6 +4899,17 @@
'comment_body_value' => 'TNG is better than DS9.',
'comment_body_format' => 'filtered_html',
))
->values(array(
'entity_type' => 'comment',
'bundle' => 'comment_node_article',
'deleted' => '0',
'entity_id' => '3',
'revision_id' => '3',
'language' => 'und',
'delta' => '0',
'comment_body_value' => 'This is a comment to an Icelandic translation.',
'comment_body_format' => 'filtered_html',
))
->execute();
$connection->schema()->createTable('field_data_description_field', array(
......@@ -8737,6 +8764,17 @@
'subject_field_value' => 'TNG for the win!',
'subject_field_format' => NULL,
))
->values(array(
'entity_type' => 'comment',
'bundle' => 'comment_node_article',
'deleted' => '0',
'entity_id' => '3',
'revision_id' => '3',
'language' => 'is',
'delta' => '0',
'subject_field_value' => 'Comment to IS translation',
'subject_field_format' => NULL,
))
->execute();
$connection->schema()->createTable('field_data_taxonomy_forums', array(
......@@ -9202,6 +9240,17 @@
'comment_body_value' => 'TNG is better than DS9.',
'comment_body_format' => 'filtered_html',
))
->values(array(
'entity_type' => 'comment',
'bundle' => 'comment_node_article',
'deleted' => '0',
'entity_id' => '3',
'revision_id' => '3',
'language' => 'und',
'delta' => '0',
'comment_body_value' => 'This is a comment to an Icelandic translation.',
'comment_body_format' => 'filtered_html',
))
->execute();
$connection->schema()->createTable('field_revision_description_field', array(
......@@ -13083,6 +13132,17 @@
'subject_field_value' => 'TNG for the win!',
'subject_field_format' => NULL,
))
->values(array(
'entity_type' => 'comment',
'bundle' => 'comment_node_article',
'deleted' => '0',
'entity_id' => '3',
'revision_id' => '3',
'language' => 'is',
'delta' => '0',
'subject_field_value' => 'Comment to IS translation',
'subject_field_format' => NULL,
))
->execute();
$connection->schema()->createTable('field_revision_taxonomy_forums', array(
......@@ -36570,11 +36630,11 @@
))
->values(array(
'nid' => '3',
'cid' => '0',
'last_comment_timestamp' => '1471428152',
'last_comment_name' => NULL,
'cid' => '3',
'last_comment_timestamp' => '1533031490',
'last_comment_name' => '',
'last_comment_uid' => '1',
'comment_count' => '0',
'comment_count' => '1',
))
->values(array(
'nid' => '4',
......@@ -60,7 +60,7 @@ protected function getEntityCounts() {
'block' => 35,
'block_content' => 2,
'block_content_type' => 1,
'comment' => 6,
'comment' => 8,
// The 'standard' profile provides the 'comment' comment type, and the
// migration creates 12 comment types, one per node type.
'comment_type' => 13,
......@@ -74,7 +74,7 @@ protected function getEntityCounts() {
'image_style' => 5,
'language_content_settings' => 3,
'migration' => 105,
'node' => 17,
'node' => 18,
// The 'book' module provides the 'book' node type, and the migration
// creates 12 node types.
'node_type' => 13,
......@@ -106,12 +106,12 @@ protected function getEntityCounts() {
protected function getEntityCountsIncremental() {
$counts = $this->getEntityCounts();
$counts['block_content'] = 3;
$counts['comment'] = 7;
$counts['comment'] = 9;
$counts['entity_view_display'] = 55;
$counts['entity_view_mode'] = 14;
$counts['file'] = 8;
$counts['menu_link_content'] = 11;
$counts['node'] = 18;
$counts['node'] = 19;
$counts['taxonomy_term'] = 9;
$counts['user'] = 8;
$counts['view'] = 16;
......
......@@ -207,7 +207,7 @@ public function testMigrateUpgradeExecute() {
}
$edits = $this->translatePostValues($edit);
$this->drupalPostForm(NULL, $edits, t('Review upgrade'));
$session->pageTextContains("Install migrate_drupal_multilingual to run migration 'd7_node_entity_translation:article'.");
$session->pageTextContains("Install migrate_drupal_multilingual to run migration 'd7_node_translation:article'.");
}
}
......@@ -60,7 +60,7 @@ protected function getEntityCounts() {
'block' => 25,
'block_content' => 1,
'block_content_type' => 1,
'comment' => 2,
'comment' => 3,
// The 'standard' profile provides the 'comment' comment type, and the
// migration creates 6 comment types, one per node type.
'comment_type' => 7,
......@@ -106,7 +106,7 @@ protected function getEntityCounts() {
protected function getEntityCountsIncremental() {
$counts = $this->getEntityCounts();
$counts['block_content'] = 2;
$counts['comment'] = 3;
$counts['comment'] = 4;
$counts['file'] = 4;
$counts['menu_link_content'] = 13;
$counts['node'] = 6;
......
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