diff --git a/core/modules/migrate_drupal/tests/fixtures/drupal7.php b/core/modules/migrate_drupal/tests/fixtures/drupal7.php index 620393449895c17250f798cae57d2419ea4ecdca..00945e01f0b815b77db8c6cd0362d3608c82b3a5 100644 --- a/core/modules/migrate_drupal/tests/fixtures/drupal7.php +++ b/core/modules/migrate_drupal/tests/fixtures/drupal7.php @@ -19707,6 +19707,26 @@ 'objectindex' => '0', 'format' => '', )) +->values(array( + 'lid' => '797', + 'textgroup' => 'taxonomy', + 'context' => 'term:25:name', + 'objectid' => '25', + 'type' => 'term', + 'property' => 'name', + 'objectindex' => '25', + 'format' => '', +)) +->values(array( + 'lid' => '798', + 'textgroup' => 'taxonomy', + 'context' => 'term:25:description', + 'objectid' => '25', + 'type' => 'term', + 'property' => 'description', + 'objectindex' => '25', + 'format' => '', +)) ->execute(); $connection->schema()->createTable('i18n_translation_set', array( 'fields' => array( @@ -21315,6 +21335,22 @@ 'plural' => '0', 'i18n_status' => '0', )) +->values(array( + 'lid' => '797', + 'translation' => 'fr - Emissary', + 'language' => 'fr', + 'plid' => '0', + 'plural' => '0', + 'i18n_status' => '0', +)) +->values(array( + 'lid' => '798', + 'translation' => 'fr - Pilot episode', + 'language' => 'fr', + 'plid' => '0', + 'plural' => '0', + 'i18n_status' => '0', +)) ->execute(); $connection->schema()->createTable('menu_custom', array( 'fields' => array( @@ -56789,6 +56825,16 @@ 'language' => 'fr', 'i18n_tsid' => '0', )) +->values(array( + 'tid' => '25', + 'vid' => '8', + 'name' => 'Emissary', + 'description' => 'Pilot episode', + 'format' => 'filtered_html', + 'weight' => '0', + 'language' => 'und', + 'i18n_tsid' => '0', +)) ->execute(); $connection->schema()->createTable('taxonomy_term_hierarchy', array( 'fields' => array( @@ -56915,6 +56961,10 @@ 'tid' => '8', 'parent' => '6', )) +->values(array( + 'tid' => '25', + 'parent' => '0', +)) ->execute(); $connection->schema()->createTable('taxonomy_vocabulary', array( 'fields' => array( @@ -57069,6 +57119,17 @@ 'language' => 'fr', 'i18n_mode' => '2', )) +->values(array( + 'vid' => '8', + 'name' => 'VocabLocalized2', + 'machine_name' => 'vocablocalized2', + 'description' => '', + 'hierarchy' => '0', + 'module' => 'taxonomy', + 'weight' => '0', + 'language' => 'und', + 'i18n_mode' => '1', +)) ->execute(); $connection->schema()->createTable('tracker_node', array( 'fields' => array( diff --git a/core/modules/migrate_drupal_ui/tests/src/Functional/d7/Upgrade7Test.php b/core/modules/migrate_drupal_ui/tests/src/Functional/d7/Upgrade7Test.php index b8010c6614b150cccd2e2477aec72ab6cb112164..b1f0d84d0ac9768a23ac12e76536b0b451051c7e 100644 --- a/core/modules/migrate_drupal_ui/tests/src/Functional/d7/Upgrade7Test.php +++ b/core/modules/migrate_drupal_ui/tests/src/Functional/d7/Upgrade7Test.php @@ -90,7 +90,7 @@ protected function getEntityCounts() { 'file' => 3, 'filter_format' => 7, 'image_style' => 7, - 'language_content_settings' => 21, + 'language_content_settings' => 22, 'node' => 7, 'node_type' => 7, 'rdf_mapping' => 8, @@ -99,8 +99,8 @@ protected function getEntityCounts() { 'shortcut_set' => 2, 'action' => 19, 'menu' => 7, - 'taxonomy_term' => 24, - 'taxonomy_vocabulary' => 7, + 'taxonomy_term' => 25, + 'taxonomy_vocabulary' => 8, 'path_alias' => 8, 'tour' => 6, 'user' => 4, @@ -126,7 +126,7 @@ protected function getEntityCountsIncremental() { $counts['file'] = 4; $counts['menu_link_content'] = 13; $counts['node'] = 8; - $counts['taxonomy_term'] = 25; + $counts['taxonomy_term'] = 26; $counts['user'] = 5; return $counts; } diff --git a/core/modules/taxonomy/src/Plugin/migrate/source/d7/TermLocalizedTranslation.php b/core/modules/taxonomy/src/Plugin/migrate/source/d7/TermLocalizedTranslation.php index f61f384b6953d55ced8d5ef1753d3494cd4de217..970e1b85c68a0bfa31873b82125fcee0f294502d 100644 --- a/core/modules/taxonomy/src/Plugin/migrate/source/d7/TermLocalizedTranslation.php +++ b/core/modules/taxonomy/src/Plugin/migrate/source/d7/TermLocalizedTranslation.php @@ -50,38 +50,22 @@ public function query() { * {@inheritdoc} */ public function prepareRow(Row $row) { + parent::prepareRow($row); + + // Override language with ltlanguage. $language = $row->getSourceProperty('ltlanguage'); - $tid = $row->getSourceProperty('tid'); + $row->setSourceProperty('language', $language); - // If this row has been migrated it is a duplicate then skip it. - if ($this->idMap->lookupDestinationIds(['tid' => $tid, 'language' => $language])) { - return FALSE; - } + // Set the i18n string table for use in I18nQueryTrait. + $this->i18nStringTable = 'i18n_string'; // Save the translation for the property already in the row. $property_in_row = $row->getSourceProperty('property'); - $row->setSourceProperty($property_in_row . '_translated', $row->getSourceProperty('translation')); // Get the translation for the property not already in the row and save it // in the row. $property_not_in_row = ($property_in_row == 'name') ? 'description' : 'name'; - - // Get the translation, if one exists, for the property not already in the - // row. - $query = $this->select('i18n_string', 'i18n') - ->fields('i18n', ['lid']) - ->condition('i18n.property', $property_not_in_row); - $query->leftJoin('locales_target', 'lt', 'i18n.lid = lt.lid'); - $query->condition('lt.language', $language); - $query->addField('lt', 'translation'); - $results = $query->execute()->fetchAssoc(); - if (!$results) { - $row->setSourceProperty($property_not_in_row . '_translated', NULL); - } - else { - $row->setSourceProperty($property_not_in_row . '_translated', $results['translation']); - } - parent::prepareRow($row); + return $this->getPropertyNotInRowTranslation($row, $property_not_in_row, 'tid', $this->idMap); } /** diff --git a/core/modules/taxonomy/tests/src/Kernel/Migrate/d7/MigrateTaxonomyTermTest.php b/core/modules/taxonomy/tests/src/Kernel/Migrate/d7/MigrateTaxonomyTermTest.php index de22f1db94d8eecb49f56e78638831d28fcbe238..0855ba09575013d255368680af3b77dc522e22bb 100644 --- a/core/modules/taxonomy/tests/src/Kernel/Migrate/d7/MigrateTaxonomyTermTest.php +++ b/core/modules/taxonomy/tests/src/Kernel/Migrate/d7/MigrateTaxonomyTermTest.php @@ -126,7 +126,7 @@ public function testTaxonomyTerms() { // Reset the forums tree data so this new term is included in the tree. unset($this->treeData['forums']); - $this->assertEntity(25, 'en', 'Forum Container', 'forums', '', '', 0, [], NULL, NULL, 1); + $this->assertEntity(26, 'en', 'Forum Container', 'forums', '', '', 0, [], NULL, NULL, 1); // Test taxonomy term language translations. $this->assertEntity(19, 'en', 'Jupiter Station', 'vocablocalized', 'Holographic research.', 'filtered_html', 0, [], NULL, NULL, 1); @@ -139,6 +139,7 @@ public function testTaxonomyTerms() { // Localized. $this->assertEntity(19, 'en', 'Jupiter Station', 'vocablocalized', 'Holographic research.', 'filtered_html', '0', []); $this->assertEntity(20, 'en', 'DS9', 'vocablocalized', 'Terok Nor', 'filtered_html', '0', []); + $this->assertEntity(25, 'en', 'Emissary', 'vocablocalized2', 'Pilot episode', 'filtered_html', '0', []); /** @var \Drupal\taxonomy\TermInterface $entity */ $entity = Term::load(20); diff --git a/core/modules/taxonomy/tests/src/Kernel/Migrate/d7/MigrateTermLocalizedTranslationTest.php b/core/modules/taxonomy/tests/src/Kernel/Migrate/d7/MigrateTermLocalizedTranslationTest.php index 05122fdb7b1c860b19c0c6414d3f4980e2c22c2f..5c011bf93680478354295b682dd3a34377c7ce27 100644 --- a/core/modules/taxonomy/tests/src/Kernel/Migrate/d7/MigrateTermLocalizedTranslationTest.php +++ b/core/modules/taxonomy/tests/src/Kernel/Migrate/d7/MigrateTermLocalizedTranslationTest.php @@ -112,6 +112,7 @@ protected function assertHierarchy($vid, $tid, array $parent_ids) { public function testTranslatedLocalizedTaxonomyTerms() { $this->assertEntity(19, 'en', 'Jupiter Station', 'vocablocalized', 'Holographic research.', 'filtered_html', '0', []); $this->assertEntity(20, 'en', 'DS9', 'vocablocalized', 'Terok Nor', 'filtered_html', '0', []); + $this->assertEntity(25, 'en', 'Emissary', 'vocablocalized2', 'Pilot episode', 'filtered_html', '0', []); /** @var \Drupal\taxonomy\TermInterface $entity */ $entity = Term::load(19); @@ -128,6 +129,13 @@ public function testTranslatedLocalizedTaxonomyTerms() { $this->assertSame('fr - DS9 (localized)', $translation->label()); $this->assertSame('fr - Terok Nor (localized)', $translation->getDescription()); $this->assertFALSE($entity->hasTranslation('is')); + + $entity = Term::load(25); + $this->assertFalse($entity->hasTranslation('is')); + $this->assertTrue($entity->hasTranslation('fr')); + $translation = $entity->getTranslation('fr'); + $this->assertSame('fr - Emissary', $translation->label()); + $this->assertSame('fr - Pilot episode', $translation->getDescription()); } } diff --git a/core/modules/taxonomy/tests/src/Kernel/Plugin/migrate/source/d7/TermLocalizedTranslationTest.php b/core/modules/taxonomy/tests/src/Kernel/Plugin/migrate/source/d7/TermLocalizedTranslationTest.php index 7d798a202f0063ddfde334f0a29af95e75fd40fe..f04788b9daa8f56e06250d88878c4dd534ea835d 100644 --- a/core/modules/taxonomy/tests/src/Kernel/Plugin/migrate/source/d7/TermLocalizedTranslationTest.php +++ b/core/modules/taxonomy/tests/src/Kernel/Plugin/migrate/source/d7/TermLocalizedTranslationTest.php @@ -100,7 +100,7 @@ public function providerSource() { 'description' => 'description value 1 (description_field)', 'weight' => 0, 'is_container' => '', - 'language' => 'en', + 'language' => 'fr', 'i18n_tsid' => '0', 'machine_name' => 'tags', 'tdlanguage' => 'und', @@ -108,6 +108,8 @@ public function providerSource() { 'property' => 'name', 'ltlanguage' => 'fr', 'translation' => 'fr - name value 1', + 'name_translated' => 'fr - name value 1', + 'description_translated' => 'fr - description value 1', ], [ 'tid' => 1, @@ -116,7 +118,7 @@ public function providerSource() { 'description' => 'description value 1 (description_field)', 'weight' => 0, 'is_container' => '', - 'language' => 'en', + 'language' => 'fr', 'i18n_tsid' => '0', 'machine_name' => 'tags', 'tdlanguage' => 'und', @@ -124,7 +126,54 @@ public function providerSource() { 'property' => 'description', 'ltlanguage' => 'fr', 'translation' => 'fr - description value 1', + 'name_translated' => 'fr - name value 1', + 'description_translated' => 'fr - description value 1', ], + ]; + + $tests[0]['expected_count'] = NULL; + // Get translations for the tags bundle. + $tests[0]['configuration']['bundle'] = ['tags']; + + // The source data. + $tests[1] = $tests[0]; + array_push($tests[1]['source_data']['i18n_string'], + [ + 'lid' => 10, + 'objectid' => 5, + 'type' => 'term', + 'property' => 'name', + 'objectindex' => '5', + 'format' => 0, + ], + [ + 'lid' => 11, + 'objectid' => 5, + 'type' => 'term', + 'property' => 'description', + 'objectindex' => '5', + 'format' => 0, + ]); + array_push($tests[1]['source_data']['locales_target'], + [ + 'lid' => 10, + 'language' => 'fr', + 'translation' => 'fr - name value 5', + 'plid' => 0, + 'plural' => 0, + 'i18n_status' => 0, + ], + [ + 'lid' => 11, + 'language' => 'fr', + 'translation' => 'fr - description value 5', + 'plid' => 0, + 'plural' => 0, + 'i18n_status' => 0, + ]); + + // The expected results. + array_push($tests[1]['expected_data'], [ 'tid' => 3, 'vid' => 6, @@ -132,7 +181,7 @@ public function providerSource() { 'description' => 'description value 3', 'weight' => 0, 'is_container' => '', - 'language' => 'en', + 'language' => 'zu', 'i18n_tsid' => '0', 'machine_name' => 'categories', 'tdlanguage' => 'und', @@ -141,11 +190,46 @@ public function providerSource() { 'ltlanguage' => 'zu', 'translation' => 'zu - name value 3', ], - ]; + [ + 'tid' => 5, + 'vid' => 6, + 'name' => 'name value 5', + 'description' => 'description value 5', + 'weight' => 1, + 'is_container' => '1', + 'language' => 'fr', + 'i18n_tsid' => '0', + 'machine_name' => 'categories', + 'tdlanguage' => 'und', + 'lid' => '10', + 'property' => 'name', + 'ltlanguage' => 'fr', + 'translation' => 'fr - name value 5', + 'name_translated' => 'fr - name value 5', + 'description_translated' => 'fr - description value 5', + ], + [ + 'tid' => 5, + 'vid' => 6, + 'name' => 'name value 5', + 'description' => 'description value 5', + 'weight' => 1, + 'is_container' => '1', + 'language' => 'fr', + 'i18n_tsid' => '0', + 'machine_name' => 'categories', + 'tdlanguage' => 'und', + 'lid' => '11', + 'property' => 'description', + 'ltlanguage' => 'fr', + 'translation' => 'fr - description value 5', + 'name_translated' => 'fr - name value 5', + 'description_translated' => 'fr - description value 5', + ]); - $tests[0]['expected_count'] = NULL; + $tests[1]['expected_count'] = NULL; // Empty configuration will return terms for all vocabularies. - $tests[0]['configuration'] = []; + $tests[1]['configuration'] = []; return $tests; }