Skip to content
Snippets Groups Projects
Commit b4ece22a authored by Gábor Hojtsy's avatar Gábor Hojtsy
Browse files

Issue #2989627 by maxocub, quietone, masipila, phenaproxima, Gábor Hojtsy:...

Issue #2989627 by maxocub, quietone, masipila, phenaproxima, Gábor Hojtsy: d7_node_entity_translation migration is in the wrong module and is missing some mappings
parent 7e120d9b
No related branches found
No related tags found
No related merge requests found
...@@ -23,10 +23,14 @@ process: ...@@ -23,10 +23,14 @@ process:
revision_log: log revision_log: log
revision_timestamp: timestamp revision_timestamp: timestamp
content_translation_source: source content_translation_source: source
# Boolean indicating whether this translation needs to be updated.
content_translation_outdated: translate
destination: destination:
plugin: entity:node plugin: entity:node
translations: true translations: true
destination_module: content_translation destination_module: content_translation
migration_dependencies: migration_dependencies:
required: required:
- language
- d7_entity_translation_settings
- d7_node - d7_node
...@@ -3461,9 +3461,9 @@ ...@@ -3461,9 +3461,9 @@
'revision_id' => '1', 'revision_id' => '1',
'language' => 'fr', 'language' => 'fr',
'source' => 'en', 'source' => 'en',
'uid' => '1', 'uid' => '2',
'status' => '1', 'status' => '1',
'translate' => '0', 'translate' => '1',
'created' => '1529615802', 'created' => '1529615802',
'changed' => '1529615802', 'changed' => '1529615802',
)) ))
...@@ -3474,7 +3474,7 @@ ...@@ -3474,7 +3474,7 @@
'language' => 'is', 'language' => 'is',
'source' => 'en', 'source' => 'en',
'uid' => '1', 'uid' => '1',
'status' => '1', 'status' => '0',
'translate' => '0', 'translate' => '0',
'created' => '1529615813', 'created' => '1529615813',
'changed' => '1529615813', 'changed' => '1529615813',
...@@ -113,7 +113,8 @@ public function prepareRow(Row $row) { ...@@ -113,7 +113,8 @@ public function prepareRow(Row $row) {
// The translations will be migrated by the d7_node_entity_translation // The translations will be migrated by the d7_node_entity_translation
// migration. // migration.
$entity_translatable = $this->isEntityTranslatable('node') && (int) $this->variableGet('language_content_type_' . $type, 0) === 4; $entity_translatable = $this->isEntityTranslatable('node') && (int) $this->variableGet('language_content_type_' . $type, 0) === 4;
$language = $entity_translatable ? $this->getEntityTranslationSourceLanguage('node', $nid) : $row->getSourceProperty('language'); $source_language = $this->getEntityTranslationSourceLanguage('node', $nid);
$language = $entity_translatable && $source_language ? $source_language : $row->getSourceProperty('language');
// Get Field API field values. // Get Field API field values.
foreach ($this->getFields('node', $type) as $field_name => $field) { foreach ($this->getFields('node', $type) as $field_name => $field) {
......
...@@ -20,16 +20,7 @@ class NodeEntityTranslation extends FieldableEntity { ...@@ -20,16 +20,7 @@ class NodeEntityTranslation extends FieldableEntity {
*/ */
public function query() { public function query() {
$query = $this->select('entity_translation', 'et') $query = $this->select('entity_translation', 'et')
->fields('et', [ ->fields('et')
'entity_id',
'revision_id',
'language',
'source',
'uid',
'status',
'created',
'changed',
])
->fields('n', [ ->fields('n', [
'title', 'title',
'type', 'type',
...@@ -88,14 +79,16 @@ public function prepareRow(Row $row) { ...@@ -88,14 +79,16 @@ public function prepareRow(Row $row) {
*/ */
public function fields() { public function fields() {
return [ return [
'entity_id' => $this->t('Entity ID'), 'entity_type' => $this->t('The entity type this translation relates to'),
'revision_id' => $this->t('Revision ID'), 'entity_id' => $this->t('The entity ID this translation relates to'),
'language' => $this->t('Node translation language'), 'revision_id' => $this->t('The entity revision ID this translation relates to'),
'source' => $this->t('Node translation source language'), 'language' => $this->t('The target language for this translation.'),
'uid' => $this->t('Node translation authored by (uid)'), 'source' => $this->t('The source language from which this translation was created.'),
'status' => $this->t('Published'), 'uid' => $this->t('The author of this translation.'),
'created' => $this->t('Created timestamp'), 'status' => $this->t('Boolean indicating whether the translation is published (visible to non-administrators).'),
'changed' => $this->t('Modified timestamp'), 'translate' => $this->t('A boolean indicating whether this translation needs to be updated.'),
'created' => $this->t('The Unix timestamp when the translation was created.'),
'changed' => $this->t('The Unix timestamp when the translation was most recently saved.'),
'title' => $this->t('Node title'), 'title' => $this->t('Node title'),
'type' => $this->t('Node type'), 'type' => $this->t('Node type'),
'promote' => $this->t('Promoted to front page'), 'promote' => $this->t('Promoted to front page'),
......
...@@ -70,6 +70,7 @@ protected function setUp() { ...@@ -70,6 +70,7 @@ protected function setUp() {
'd7_field_instance', 'd7_field_instance',
'd7_node', 'd7_node',
'd7_node_translation', 'd7_node_translation',
'd7_entity_translation_settings',
'd7_node_entity_translation', 'd7_node_entity_translation',
]); ]);
} }
...@@ -181,14 +182,6 @@ public function testNode() { ...@@ -181,14 +182,6 @@ public function testNode() {
$this->assertEquals(CommentItemInterface::OPEN, $node->comment_node_test_content_type->status); $this->assertEquals(CommentItemInterface::OPEN, $node->comment_node_test_content_type->status);
$this->assertEquals('3.1416', $node->field_float_list[0]->value); $this->assertEquals('3.1416', $node->field_float_list[0]->value);
// Test that fields translated with Entity Translation are migrated.
$node_fr = $node->getTranslation('fr');
$this->assertEquals('A French Node', $node_fr->getTitle());
$this->assertEquals('6', $node_fr->field_integer->value);
$node_is = $node->getTranslation('is');
$this->assertEquals('An Icelandic Node', $node_is->getTitle());
$this->assertEquals('7', $node_is->field_integer->value);
$node = Node::load(2); $node = Node::load(2);
$this->assertEquals('en', $node->langcode->value); $this->assertEquals('en', $node->langcode->value);
$this->assertEquals("...is that it's the absolute best show ever. Trust me, I would know.", $node->body->value); $this->assertEquals("...is that it's the absolute best show ever. Trust me, I would know.", $node->body->value);
...@@ -228,4 +221,42 @@ public function testNode() { ...@@ -228,4 +221,42 @@ public function testNode() {
$this->assertEquals(CommentItemInterface::OPEN, $node->comment_forum->status); $this->assertEquals(CommentItemInterface::OPEN, $node->comment_forum->status);
} }
/**
* Test node entity translations migration from Drupal 7 to 8.
*/
public function testNodeEntityTranslations() {
$manager = $this->container->get('content_translation.manager');
// Get the node and its translations.
$node = Node::load(1);
$node_fr = $node->getTranslation('fr');
$node_is = $node->getTranslation('is');
// Test that fields translated with Entity Translation are migrated.
$this->assertSame('An English Node', $node->getTitle());
$this->assertSame('A French Node', $node_fr->getTitle());
$this->assertSame('An Icelandic Node', $node_is->getTitle());
$this->assertSame('5', $node->field_integer->value);
$this->assertSame('6', $node_fr->field_integer->value);
$this->assertSame('7', $node_is->field_integer->value);
// Test that the French translation metadata is correctly migrated.
$metadata_fr = $manager->getTranslationMetadata($node_fr);
$this->assertSame('en', $metadata_fr->getSource());
$this->assertTrue($metadata_fr->isOutdated());
$this->assertSame('2', $node_fr->getOwnerId());
$this->assertSame('1529615802', $node_fr->getCreatedTime());
$this->assertSame('1529615802', $node_fr->getChangedTime());
$this->assertTrue($node_fr->isPublished());
// Test that the Icelandic translation metadata is correctly migrated.
$metadata_is = $manager->getTranslationMetadata($node_is);
$this->assertSame('en', $metadata_is->getSource());
$this->assertFalse($metadata_is->isOutdated());
$this->assertSame('1', $node_is->getOwnerId());
$this->assertSame('1529615813', $node_is->getCreatedTime());
$this->assertSame('1529615813', $node_is->getChangedTime());
$this->assertFalse($node_is->isPublished());
}
} }
...@@ -44,9 +44,9 @@ public function providerSource() { ...@@ -44,9 +44,9 @@ public function providerSource() {
'revision_id' => 2, 'revision_id' => 2,
'language' => 'fr', 'language' => 'fr',
'source' => 'en', 'source' => 'en',
'uid' => 1, 'uid' => 2,
'status' => 1, 'status' => 1,
'translate' => 0, 'translate' => 1,
'created' => 1531343508, 'created' => 1531343508,
'changed' => 1531343508, 'changed' => 1531343508,
], ],
...@@ -57,7 +57,7 @@ public function providerSource() { ...@@ -57,7 +57,7 @@ public function providerSource() {
'language' => 'es', 'language' => 'es',
'source' => 'en', 'source' => 'en',
'uid' => 1, 'uid' => 1,
'status' => 1, 'status' => 0,
'translate' => 0, 'translate' => 0,
'created' => 1531343528, 'created' => 1531343528,
'changed' => 1531343528, 'changed' => 1531343528,
...@@ -280,12 +280,14 @@ public function providerSource() { ...@@ -280,12 +280,14 @@ public function providerSource() {
// The expected results. // The expected results.
$tests[0]['expected_data'] = [ $tests[0]['expected_data'] = [
[ [
'entity_type' => 'node',
'entity_id' => 2, 'entity_id' => 2,
'revision_id' => 2, 'revision_id' => 2,
'language' => 'fr', 'language' => 'fr',
'source' => 'en', 'source' => 'en',
'uid' => 1, 'uid' => 2,
'status' => 1, 'status' => 1,
'translate' => 1,
'created' => 1531343508, 'created' => 1531343508,
'changed' => 1531343508, 'changed' => 1531343508,
'type' => 'page', 'type' => 'page',
...@@ -304,12 +306,14 @@ public function providerSource() { ...@@ -304,12 +306,14 @@ public function providerSource() {
], ],
], ],
[ [
'entity_type' => 'node',
'entity_id' => 2, 'entity_id' => 2,
'revision_id' => 2, 'revision_id' => 2,
'language' => 'es', 'language' => 'es',
'source' => 'en', 'source' => 'en',
'uid' => 1, 'uid' => 1,
'status' => 1, 'status' => 0,
'translate' => 0,
'created' => 1531343528, 'created' => 1531343528,
'changed' => 1531343528, 'changed' => 1531343528,
'type' => 'page', 'type' => 'page',
......
...@@ -422,6 +422,169 @@ public function providerSource() { ...@@ -422,6 +422,169 @@ public function providerSource() {
], ],
]; ];
// The source data with a correct 'entity_translation' table.
$tests[1]['source_data']['entity_translation'] = [
[
'entity_type' => 'node',
'entity_id' => 1,
'revision_id' => 1,
'language' => 'en',
'source' => '',
'uid' => 1,
'status' => 1,
'translate' => 0,
'created' => 1279051598,
'changed' => 1279051598,
],
[
'entity_type' => 'node',
'entity_id' => 1,
'revision_id' => 1,
'language' => 'fr',
'source' => 'en',
'uid' => 1,
'status' => 1,
'translate' => 0,
'created' => 1279051598,
'changed' => 1279051598,
],
];
$tests[1]['source_data']['field_config'] = [
[
'id' => '1',
'translatable' => '1',
],
];
$tests[1]['source_data']['field_config_instance'] = [
[
'id' => '1',
'field_id' => '1',
'field_name' => 'body',
'entity_type' => 'node',
'bundle' => 'page',
'data' => 'a:0:{}',
'deleted' => '0',
],
];
$tests[1]['source_data']['field_revision_body'] = [
[
'entity_type' => 'node',
'bundle' => 'page',
'deleted' => '0',
'entity_id' => '1',
'revision_id' => '1',
'language' => 'en',
'delta' => '0',
'body_value' => 'English body',
'body_summary' => '',
'body_format' => 'filtered_html',
],
[
'entity_type' => 'node',
'bundle' => 'page',
'deleted' => '0',
'entity_id' => '1',
'revision_id' => '1',
'language' => 'fr',
'delta' => '0',
'body_value' => 'French body',
'body_summary' => '',
'body_format' => 'filtered_html',
],
];
$tests[1]['source_data']['node'] = [
[
'nid' => 1,
'vid' => 1,
'type' => 'page',
'language' => 'en',
'title' => 'Node Title',
'uid' => 1,
'status' => 1,
'created' => 1279051598,
'changed' => 1279051598,
'comment' => 2,
'promote' => 1,
'sticky' => 0,
'tnid' => 0,
'translate' => 0,
],
];
$tests[1]['source_data']['node_revision'] = [
[
'nid' => 1,
'vid' => 1,
'uid' => 1,
'title' => 'Node Title',
'log' => '',
'timestamp' => 1279051598,
'status' => 1,
'comment' => 2,
'promote' => 1,
'sticky' => 0,
],
];
$tests[1]['source_data']['variable'] = [
[
'name' => 'entity_translation_entity_types',
'value' => 'a:4:{s:7:"comment";i:0;s:4:"node";s:4:"node";s:13:"taxonomy_term";i:0;s:4:"user";i:0;}',
],
[
'name' => 'language_content_type_page',
'value' => 's:1:"4";',
],
];
// The expected results with a correct 'entity_translation' table.
// entity_translation table.
$tests[1]['expected_data'] = [
[
'nid' => 1,
'vid' => 1,
'type' => 'page',
'language' => 'en',
'title' => 'Node Title',
'node_uid' => 1,
'revision_uid' => 1,
'status' => 1,
'created' => 1279051598,
'changed' => 1279051598,
'comment' => 2,
'promote' => 1,
'sticky' => 0,
'tnid' => 1,
'translate' => 0,
'log' => '',
'timestamp' => 1279051598,
'body' => [
[
'value' => 'English body',
'summary' => '',
'format' => 'filtered_html',
],
],
],
];
// Repeat the previous test with an incorrect 'entity_translation' table
// where the row with the empty 'source' property is missing.
$tests[2]['source_data'] = $tests[1]['source_data'];
$tests[2]['source_data']['entity_translation'] = [
[
'entity_type' => 'node',
'entity_id' => 1,
'revision_id' => 1,
'language' => 'fr',
'source' => 'en',
'uid' => 1,
'status' => 1,
'translate' => 0,
'created' => 1279051598,
'changed' => 1279051598,
],
];
$tests[2]['expected_data'] = $tests[1]['expected_data'];
return $tests; return $tests;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment