diff --git a/core/modules/node/migrations/d7_node_entity_translation.yml b/core/modules/content_translation/migrations/d7_node_entity_translation.yml similarity index 80% rename from core/modules/node/migrations/d7_node_entity_translation.yml rename to core/modules/content_translation/migrations/d7_node_entity_translation.yml index 80c5c504201044ea71d7b576437c1123950c18ed..612c1f2f65641f4d061d3e8e17e2c7fc6ee4e655 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 bf91e17c1588381dec989219d2a89f15e598ce86..25f95386db701108717fdb7190bf3913f63fb8e4 100644 --- a/core/modules/migrate_drupal/tests/fixtures/drupal7.php +++ b/core/modules/migrate_drupal/tests/fixtures/drupal7.php @@ -3461,9 +3461,9 @@ '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 @@ '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 75cba448423ce24a6ac7d1470ccbc896d8ddc6d1..931a2b94311c02f892cac258c7e9a8504b9d5966 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 @@ public function prepareRow(Row $row) { // 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 f438b0054f0ab83f3ee9c33eb542cdb73f155a99..ce698161634cd5af8a8adc9407309c298d608c2b 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 @@ public function prepareRow(Row $row) { */ 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 da930ec6844edf014c931d2bbf9f6a4adcbdf906..4bbd6ef49c393f5ee724e28a007dfb6c053a62b7 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 @@ protected function setUp() { 'd7_field_instance', 'd7_node', 'd7_node_translation', + 'd7_entity_translation_settings', 'd7_node_entity_translation', ]); } @@ -181,14 +182,6 @@ public function testNode() { $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 @@ public function testNode() { $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 ef33a9624e011d2e82c8758d37d51e1616d25d71..79fedae640c68ed6ebe215dbed3a0afb682e83d7 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 @@ public function providerSource() { '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 @@ public function providerSource() { 'language' => 'es', 'source' => 'en', 'uid' => 1, - 'status' => 1, + 'status' => 0, 'translate' => 0, 'created' => 1531343528, 'changed' => 1531343528, @@ -280,12 +280,14 @@ public function providerSource() { // 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 @@ public function providerSource() { ], ], [ + '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 010b90dc03762258a6bdb94d6002a74cbacb4f83..3b75837a686230f0c4d73e9e35e219534c689624 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 @@ 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; }