summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGábor Hojtsy2018-11-01 21:30:12 (GMT)
committerGábor Hojtsy2018-11-01 21:30:52 (GMT)
commitf7978e86d13b0c6d6b1766ec4f1762fb2ce0e0c9 (patch)
treeb2d537c7d30c1e2768e41fe11047b126848fbe50
parent09021c59266925f534df587b59f7c6b5eaf2a883 (diff)
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
(cherry picked from commit b4ece22a63aaedcb4e684a612890c121352cd783)
-rw-r--r--core/modules/content_translation/migrations/d7_node_entity_translation.yml (renamed from core/modules/node/migrations/d7_node_entity_translation.yml)4
-rw-r--r--core/modules/migrate_drupal/tests/fixtures/drupal7.php6
-rw-r--r--core/modules/node/src/Plugin/migrate/source/d7/Node.php3
-rw-r--r--core/modules/node/src/Plugin/migrate/source/d7/NodeEntityTranslation.php29
-rw-r--r--core/modules/node/tests/src/Kernel/Migrate/d7/MigrateNodeTest.php47
-rw-r--r--core/modules/node/tests/src/Kernel/Plugin/migrate/source/d7/NodeEntityTranslationTest.php14
-rw-r--r--core/modules/node/tests/src/Kernel/Plugin/migrate/source/d7/NodeTest.php163
7 files changed, 231 insertions, 35 deletions
diff --git a/core/modules/node/migrations/d7_node_entity_translation.yml b/core/modules/content_translation/migrations/d7_node_entity_translation.yml
index 80c5c50..612c1f2 100644
--- a/core/modules/node/migrations/d7_node_entity_translation.yml
+++ b/core/modules/content_translation/migrations/d7_node_entity_translation.yml
@@ -23,10 +23,14 @@ process:
revision_log: log
revision_timestamp: timestamp
content_translation_source: source
+ # Boolean indicating whether this translation needs to be updated.
+ content_translation_outdated: translate
destination:
plugin: entity:node
translations: true
destination_module: content_translation
migration_dependencies:
required:
+ - language
+ - d7_entity_translation_settings
- d7_node
diff --git a/core/modules/migrate_drupal/tests/fixtures/drupal7.php b/core/modules/migrate_drupal/tests/fixtures/drupal7.php
index bf91e17..25f9538 100644
--- a/core/modules/migrate_drupal/tests/fixtures/drupal7.php
+++ b/core/modules/migrate_drupal/tests/fixtures/drupal7.php
@@ -3461,9 +3461,9 @@ $connection->insert('entity_translation')
'revision_id' => '1',
'language' => 'fr',
'source' => 'en',
- 'uid' => '1',
+ 'uid' => '2',
'status' => '1',
- 'translate' => '0',
+ 'translate' => '1',
'created' => '1529615802',
'changed' => '1529615802',
))
@@ -3474,7 +3474,7 @@ $connection->insert('entity_translation')
'language' => 'is',
'source' => 'en',
'uid' => '1',
- 'status' => '1',
+ 'status' => '0',
'translate' => '0',
'created' => '1529615813',
'changed' => '1529615813',
diff --git a/core/modules/node/src/Plugin/migrate/source/d7/Node.php b/core/modules/node/src/Plugin/migrate/source/d7/Node.php
index 75cba44..931a2b9 100644
--- a/core/modules/node/src/Plugin/migrate/source/d7/Node.php
+++ b/core/modules/node/src/Plugin/migrate/source/d7/Node.php
@@ -113,7 +113,8 @@ class Node extends FieldableEntity {
// The translations will be migrated by the d7_node_entity_translation
// migration.
$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.
foreach ($this->getFields('node', $type) as $field_name => $field) {
diff --git a/core/modules/node/src/Plugin/migrate/source/d7/NodeEntityTranslation.php b/core/modules/node/src/Plugin/migrate/source/d7/NodeEntityTranslation.php
index f438b00..ce69816 100644
--- a/core/modules/node/src/Plugin/migrate/source/d7/NodeEntityTranslation.php
+++ b/core/modules/node/src/Plugin/migrate/source/d7/NodeEntityTranslation.php
@@ -20,16 +20,7 @@ class NodeEntityTranslation extends FieldableEntity {
*/
public function query() {
$query = $this->select('entity_translation', 'et')
- ->fields('et', [
- 'entity_id',
- 'revision_id',
- 'language',
- 'source',
- 'uid',
- 'status',
- 'created',
- 'changed',
- ])
+ ->fields('et')
->fields('n', [
'title',
'type',
@@ -88,14 +79,16 @@ class NodeEntityTranslation extends FieldableEntity {
*/
public function fields() {
return [
- 'entity_id' => $this->t('Entity ID'),
- 'revision_id' => $this->t('Revision ID'),
- 'language' => $this->t('Node translation language'),
- 'source' => $this->t('Node translation source language'),
- 'uid' => $this->t('Node translation authored by (uid)'),
- 'status' => $this->t('Published'),
- 'created' => $this->t('Created timestamp'),
- 'changed' => $this->t('Modified timestamp'),
+ 'entity_type' => $this->t('The entity type this translation relates to'),
+ 'entity_id' => $this->t('The entity ID this translation relates to'),
+ 'revision_id' => $this->t('The entity revision ID this translation relates to'),
+ 'language' => $this->t('The target language for this translation.'),
+ 'source' => $this->t('The source language from which this translation was created.'),
+ 'uid' => $this->t('The author of this translation.'),
+ 'status' => $this->t('Boolean indicating whether the translation is published (visible to non-administrators).'),
+ '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'),
'type' => $this->t('Node type'),
'promote' => $this->t('Promoted to front page'),
diff --git a/core/modules/node/tests/src/Kernel/Migrate/d7/MigrateNodeTest.php b/core/modules/node/tests/src/Kernel/Migrate/d7/MigrateNodeTest.php
index da930ec..4bbd6ef 100644
--- a/core/modules/node/tests/src/Kernel/Migrate/d7/MigrateNodeTest.php
+++ b/core/modules/node/tests/src/Kernel/Migrate/d7/MigrateNodeTest.php
@@ -70,6 +70,7 @@ class MigrateNodeTest extends MigrateDrupal7TestBase {
'd7_field_instance',
'd7_node',
'd7_node_translation',
+ 'd7_entity_translation_settings',
'd7_node_entity_translation',
]);
}
@@ -181,14 +182,6 @@ class MigrateNodeTest extends MigrateDrupal7TestBase {
$this->assertEquals(CommentItemInterface::OPEN, $node->comment_node_test_content_type->status);
$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);
$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);
@@ -228,4 +221,42 @@ class MigrateNodeTest extends MigrateDrupal7TestBase {
$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());
+ }
+
}
diff --git a/core/modules/node/tests/src/Kernel/Plugin/migrate/source/d7/NodeEntityTranslationTest.php b/core/modules/node/tests/src/Kernel/Plugin/migrate/source/d7/NodeEntityTranslationTest.php
index ef33a96..79fedae 100644
--- a/core/modules/node/tests/src/Kernel/Plugin/migrate/source/d7/NodeEntityTranslationTest.php
+++ b/core/modules/node/tests/src/Kernel/Plugin/migrate/source/d7/NodeEntityTranslationTest.php
@@ -44,9 +44,9 @@ class NodeEntityTranslationTest extends MigrateSqlSourceTestBase {
'revision_id' => 2,
'language' => 'fr',
'source' => 'en',
- 'uid' => 1,
+ 'uid' => 2,
'status' => 1,
- 'translate' => 0,
+ 'translate' => 1,
'created' => 1531343508,
'changed' => 1531343508,
],
@@ -57,7 +57,7 @@ class NodeEntityTranslationTest extends MigrateSqlSourceTestBase {
'language' => 'es',
'source' => 'en',
'uid' => 1,
- 'status' => 1,
+ 'status' => 0,
'translate' => 0,
'created' => 1531343528,
'changed' => 1531343528,
@@ -280,12 +280,14 @@ class NodeEntityTranslationTest extends MigrateSqlSourceTestBase {
// The expected results.
$tests[0]['expected_data'] = [
[
+ 'entity_type' => 'node',
'entity_id' => 2,
'revision_id' => 2,
'language' => 'fr',
'source' => 'en',
- 'uid' => 1,
+ 'uid' => 2,
'status' => 1,
+ 'translate' => 1,
'created' => 1531343508,
'changed' => 1531343508,
'type' => 'page',
@@ -304,12 +306,14 @@ class NodeEntityTranslationTest extends MigrateSqlSourceTestBase {
],
],
[
+ 'entity_type' => 'node',
'entity_id' => 2,
'revision_id' => 2,
'language' => 'es',
'source' => 'en',
'uid' => 1,
- 'status' => 1,
+ 'status' => 0,
+ 'translate' => 0,
'created' => 1531343528,
'changed' => 1531343528,
'type' => 'page',
diff --git a/core/modules/node/tests/src/Kernel/Plugin/migrate/source/d7/NodeTest.php b/core/modules/node/tests/src/Kernel/Plugin/migrate/source/d7/NodeTest.php
index 010b90d..3b75837 100644
--- a/core/modules/node/tests/src/Kernel/Plugin/migrate/source/d7/NodeTest.php
+++ b/core/modules/node/tests/src/Kernel/Plugin/migrate/source/d7/NodeTest.php
@@ -422,6 +422,169 @@ class NodeTest extends MigrateSqlSourceTestBase {
],
];
+ // 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;
}