diff -u b/core/modules/migrate_drupal_ui/src/Form/MigrateUpgradeForm.php b/core/modules/migrate_drupal_ui/src/Form/MigrateUpgradeForm.php --- b/core/modules/migrate_drupal_ui/src/Form/MigrateUpgradeForm.php +++ b/core/modules/migrate_drupal_ui/src/Form/MigrateUpgradeForm.php @@ -522,7 +522,7 @@ 'source_module' => 'taxonomy', 'destination_module' => 'taxonomy', ], - 'd6_i18n_taxonomy_term' => [ + 'd6_taxonomy_term_translation' => [ 'source_module' => 'i18n', 'destination_module' => 'taxonomy', ], reverted: --- b/core/modules/taxonomy/migration_templates/d6_i18n_taxonomy_term.yml +++ /dev/null @@ -1,38 +0,0 @@ -id: d6_i18n_taxonomy_term -label: Taxonomy terms -migration_tags: - - Drupal 6 -source: - plugin: d6_i18n_taxonomy_term -process: - # If you are using this file to build a custom migration consider removing - # the tid field to allow incremental migrations. - tid: tid - langcode: language - vid: - plugin: migration - migration: d6_taxonomy_vocabulary - source: vid - name: name - description: description - weight: weight - # Only attempt to stub real (non-zero) parents. - parent_id: - - - plugin: skip_on_empty - method: process - source: parent - - - plugin: migration - migration: d6_taxonomy_term - parent: - plugin: default_value - default_value: 0 - source: '@parent_id' - changed: timestamp -destination: - plugin: entity:taxonomy_term -migration_dependencies: - required: - - d6_taxonomy_vocabulary - - d6_taxonomy_term diff -u b/core/modules/taxonomy/src/Plugin/migrate/source/d6/I18nTerm.php b/core/modules/taxonomy/src/Plugin/migrate/source/d6/I18nTerm.php --- b/core/modules/taxonomy/src/Plugin/migrate/source/d6/I18nTerm.php +++ b/core/modules/taxonomy/src/Plugin/migrate/source/d6/I18nTerm.php @@ -2,9 +2,6 @@ namespace Drupal\taxonomy\Plugin\migrate\source\d6; -use Drupal\migrate\Row; -use Drupal\migrate_drupal\Plugin\migrate\source\DrupalSqlBase; - /** * Taxonomy term source from database. * @@ -17,59 +14,14 @@ */ -class I18nTerm extends DrupalSqlBase { - - /** - * {@inheritdoc} - */ - public function query() { - $query = $this->select('term_data', 'td') - ->fields('td') - ->distinct() - ->orderBy('td.tid'); - - if (isset($this->configuration['bundle'])) { - $query->condition('td.vid', [$this->configuration['bundle']], 'IN'); - } - return $query; - } +class I18nTerm extends Term { /** * {@inheritdoc} */ public function fields() { - $fields = [ - 'tid' => $this->t('The term ID.'), - 'vid' => $this->t('Existing term VID'), - 'name' => $this->t('The name of the term.'), - 'description' => $this->t('The term description.'), - 'weight' => $this->t('Weight'), - 'parent' => $this->t("The Drupal term IDs of the term's parents."), - 'language' => $this->t('The term language.'), - 'trid' => $this->t('Not sure yet.'), - ]; + $fields = parent::fields(); + $fields['language'] = $this->t('The term language.'); + $fields['trid'] = $this->t('Not sure yet.'); return $fields; } - /** - * {@inheritdoc} - */ - public function prepareRow(Row $row) { - // Find parents for this row. - $parents = $this->select('term_hierarchy', 'th') - ->fields('th', ['parent', 'tid']) - ->condition('tid', $row->getSourceProperty('tid')) - ->execute() - ->fetchCol(); - $row->setSourceProperty('parent', $parents); - - return parent::prepareRow($row); - } - - /** - * {@inheritdoc} - */ - public function getIds() { - $ids['tid']['type'] = 'integer'; - return $ids; - } - } reverted: --- b/core/modules/taxonomy/tests/src/Kernel/Migrate/d6/MigrateI18nTaxonomyTermTest.php +++ /dev/null @@ -1,129 +0,0 @@ -installEntitySchema('taxonomy_term'); - $this->installConfig(static::$modules); - - $this->executeMigrations([ - 'd6_node_type', - 'd6_comment_type', - 'd6_field', - 'd6_taxonomy_vocabulary', - 'd6_field_instance', - 'd6_taxonomy_term', - 'd6_i18n_taxonomy_term', - ]); - } - - /** - * Validate a migrated term contains the expected values. - * - * @param int $id - * Entity ID to load and check. - * @param string $expected_language - * The language code for this term. - * @param string $expected_label - * The label the migrated entity should have. - * @param string $expected_vid - * The parent vocabulary the migrated entity should have. - * @param string $expected_description - * The description the migrated entity should have. - * @param string $expected_format - * The format the migrated entity should have. - * @param int $expected_weight - * The weight the migrated entity should have. - * @param array $expected_parents - * The parent terms the migrated entity should have. - * @param int $expected_field_integer_value - * The value the migrated entity field should have. - * @param int $expected_term_reference_tid - * The term reference id the migrated entity field should have. - */ - protected function assertEntity($id, $expected_language, $expected_label, $expected_vid, $expected_description = '', $expected_format = NULL, $expected_weight = 0, $expected_parents = [], $expected_field_integer_value = NULL, $expected_term_reference_tid = NULL) { - /** @var \Drupal\taxonomy\TermInterface $entity */ - $entity = Term::load($id); - $this->assertTrue($entity instanceof TermInterface); - $this->assertSame($expected_language, $entity->language()->getId()); - $this->assertSame($expected_label, $entity->label()); - $this->assertSame($expected_vid, $entity->getVocabularyId()); - $this->assertEquals($expected_description, $entity->getDescription()); - $this->assertEquals($expected_format, $entity->getFormat()); - $this->assertEquals($expected_weight, $entity->getWeight()); - $this->assertHierarchy($expected_vid, $id, $expected_parents); - } - - /** - * Assert that a term is present in the tree storage, with the right parents. - * - * @param string $vid - * Vocabulary ID. - * @param int $tid - * ID of the term to check. - * @param array $parent_ids - * The expected parent term IDs. - */ - protected function assertHierarchy($vid, $tid, array $parent_ids) { - if (!isset($this->treeData[$vid])) { - $tree = \Drupal::entityTypeManager()->getStorage('taxonomy_term')->loadTree($vid); - $this->treeData[$vid] = []; - foreach ($tree as $item) { - $this->treeData[$vid][$item->tid] = $item; - } - } - - $this->assertArrayHasKey($tid, $this->treeData[$vid], "Term $tid exists in taxonomy tree"); - $term = $this->treeData[$vid][$tid]; - $this->assertEquals($parent_ids, array_filter($term->parents), "Term $tid has correct parents in taxonomy tree"); - } - - /** - * Tests the Drupal 6 i18n taxonomy term to Drupal 8 migration. - */ - public function testI18nTaxonomyTerms() { - $this->assertEntity(1, 'zu', 'zu - term 1 of vocabulary 1', 'vocabulary_1_i_0_', 'zu - description of term 1 of vocabulary 1', NULL, 0, []); - $this->assertEntity(2, 'fr', 'fr - term 2 of vocabulary 2', 'vocabulary_2_i_1_', 'fr - description of term 2 of vocabulary 2', NULL, 3, []); - $this->assertEntity(3, 'fr', 'fr - term 3 of vocabulary 2', 'vocabulary_2_i_1_', 'fr - description of term 3 of vocabulary 2', NULL, 4, ['2']); - $this->assertEntity(4, 'en', 'term 4 of vocabulary 3', 'vocabulary_3_i_2_', 'description of term 4 of vocabulary 3', NULL, 6, []); - $this->assertEntity(5, 'en', 'term 5 of vocabulary 3', 'vocabulary_3_i_2_', 'description of term 5 of vocabulary 3', NULL, 7, ['4']); - $this->assertEntity(6, 'en', 'term 6 of vocabulary 3', 'vocabulary_3_i_2_', 'description of term 6 of vocabulary 3', NULL, 8, ['4', '5']); - $this->assertEntity(7, 'fr', 'fr - term 2 of vocabulary 1', 'vocabulary_1_i_0_', 'fr - desc of term 2 vocab 1', NULL, 0, []); - } - -} only in patch2: unchanged: --- /dev/null +++ b/core/modules/taxonomy/migration_templates/d6_taxonomy_term_translation.yml @@ -0,0 +1,38 @@ +id: d6_taxonomy_term_translation +label: Taxonomy terms +migration_tags: + - Drupal 6 +source: + plugin: d6_i18n_taxonomy_term +process: + # If you are using this file to build a custom migration consider removing + # the tid field to allow incremental migrations. + tid: tid + langcode: language + vid: + plugin: migration + migration: d6_taxonomy_vocabulary + source: vid + name: name + description: description + weight: weight + # Only attempt to stub real (non-zero) parents. + parent_id: + - + plugin: skip_on_empty + method: process + source: parent + - + plugin: migration + migration: d6_taxonomy_term + parent: + plugin: default_value + default_value: 0 + source: '@parent_id' + changed: timestamp +destination: + plugin: entity:taxonomy_term +migration_dependencies: + required: + - d6_taxonomy_vocabulary + - d6_taxonomy_term only in patch2: unchanged: --- /dev/null +++ b/core/modules/taxonomy/tests/src/Kernel/Migrate/d6/MigrateTaxonomyTermTranslationTest.php @@ -0,0 +1,129 @@ +installEntitySchema('taxonomy_term'); + $this->installConfig(static::$modules); + + $this->executeMigrations([ + 'd6_node_type', + 'd6_comment_type', + 'd6_field', + 'd6_taxonomy_vocabulary', + 'd6_field_instance', + 'd6_taxonomy_term', + 'd6_taxonomy_term_translation', + ]); + } + + /** + * Validate a migrated term contains the expected values. + * + * @param int $id + * Entity ID to load and check. + * @param string $expected_language + * The language code for this term. + * @param string $expected_label + * The label the migrated entity should have. + * @param string $expected_vid + * The parent vocabulary the migrated entity should have. + * @param string $expected_description + * The description the migrated entity should have. + * @param string $expected_format + * The format the migrated entity should have. + * @param int $expected_weight + * The weight the migrated entity should have. + * @param array $expected_parents + * The parent terms the migrated entity should have. + * @param int $expected_field_integer_value + * The value the migrated entity field should have. + * @param int $expected_term_reference_tid + * The term reference id the migrated entity field should have. + */ + protected function assertEntity($id, $expected_language, $expected_label, $expected_vid, $expected_description = '', $expected_format = NULL, $expected_weight = 0, $expected_parents = [], $expected_field_integer_value = NULL, $expected_term_reference_tid = NULL) { + /** @var \Drupal\taxonomy\TermInterface $entity */ + $entity = Term::load($id); + $this->assertTrue($entity instanceof TermInterface); + $this->assertSame($expected_language, $entity->language()->getId()); + $this->assertSame($expected_label, $entity->label()); + $this->assertSame($expected_vid, $entity->getVocabularyId()); + $this->assertEquals($expected_description, $entity->getDescription()); + $this->assertEquals($expected_format, $entity->getFormat()); + $this->assertEquals($expected_weight, $entity->getWeight()); + $this->assertHierarchy($expected_vid, $id, $expected_parents); + } + + /** + * Assert that a term is present in the tree storage, with the right parents. + * + * @param string $vid + * Vocabulary ID. + * @param int $tid + * ID of the term to check. + * @param array $parent_ids + * The expected parent term IDs. + */ + protected function assertHierarchy($vid, $tid, array $parent_ids) { + if (!isset($this->treeData[$vid])) { + $tree = \Drupal::entityTypeManager()->getStorage('taxonomy_term')->loadTree($vid); + $this->treeData[$vid] = []; + foreach ($tree as $item) { + $this->treeData[$vid][$item->tid] = $item; + } + } + + $this->assertArrayHasKey($tid, $this->treeData[$vid], "Term $tid exists in taxonomy tree"); + $term = $this->treeData[$vid][$tid]; + $this->assertEquals($parent_ids, array_filter($term->parents), "Term $tid has correct parents in taxonomy tree"); + } + + /** + * Tests the Drupal 6 i18n taxonomy term to Drupal 8 migration. + */ + public function testI18nTaxonomyTerms() { + $this->assertEntity(1, 'zu', 'zu - term 1 of vocabulary 1', 'vocabulary_1_i_0_', 'zu - description of term 1 of vocabulary 1', NULL, 0, []); + $this->assertEntity(2, 'fr', 'fr - term 2 of vocabulary 2', 'vocabulary_2_i_1_', 'fr - description of term 2 of vocabulary 2', NULL, 3, []); + $this->assertEntity(3, 'fr', 'fr - term 3 of vocabulary 2', 'vocabulary_2_i_1_', 'fr - description of term 3 of vocabulary 2', NULL, 4, ['2']); + $this->assertEntity(4, 'en', 'term 4 of vocabulary 3', 'vocabulary_3_i_2_', 'description of term 4 of vocabulary 3', NULL, 6, []); + $this->assertEntity(5, 'en', 'term 5 of vocabulary 3', 'vocabulary_3_i_2_', 'description of term 5 of vocabulary 3', NULL, 7, ['4']); + $this->assertEntity(6, 'en', 'term 6 of vocabulary 3', 'vocabulary_3_i_2_', 'description of term 6 of vocabulary 3', NULL, 8, ['4', '5']); + $this->assertEntity(7, 'fr', 'fr - term 2 of vocabulary 1', 'vocabulary_1_i_0_', 'fr - desc of term 2 vocab 1', NULL, 0, []); + } + +}