summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGabor Hojtsy2017-05-30 15:52:16 +0200
committerGabor Hojtsy2017-05-30 15:52:16 +0200
commita001cd8fd644ef9d621df7785e82d7169e912b82 (patch)
treef1867cc47359eacc2604ba7099acd37fc2a7a16b
parent1421285e92e8ade0aa0b4c4d7f5e481a974467c6 (diff)
Issue #2784371 by Jo Fitzgerald, quietone, phenaproxima, Gábor Hojtsy, mikeryan, jhodgdon: Migrate D6 i18n taxonomy terms
-rw-r--r--core/modules/migrate_drupal/tests/fixtures/drupal6.php42
-rw-r--r--core/modules/migrate_drupal_ui/src/Form/MigrateUpgradeForm.php4
-rw-r--r--core/modules/migrate_drupal_ui/src/Tests/d6/MigrateUpgrade6Test.php2
-rw-r--r--core/modules/taxonomy/migration_templates/d6_taxonomy_term_translation.yml39
-rw-r--r--core/modules/taxonomy/src/Plugin/migrate/source/d6/Term.php4
-rw-r--r--core/modules/taxonomy/tests/src/Kernel/Migrate/d6/MigrateTaxonomyTermTest.php8
-rw-r--r--core/modules/taxonomy/tests/src/Kernel/Migrate/d6/MigrateTaxonomyTermTranslationTest.php124
-rw-r--r--core/modules/taxonomy/tests/src/Kernel/Plugin/migrate/source/d6/TermTranslationTest.php206
8 files changed, 416 insertions, 13 deletions
diff --git a/core/modules/migrate_drupal/tests/fixtures/drupal6.php b/core/modules/migrate_drupal/tests/fixtures/drupal6.php
index 4b8b3dc..3148e49 100644
--- a/core/modules/migrate_drupal/tests/fixtures/drupal6.php
+++ b/core/modules/migrate_drupal/tests/fixtures/drupal6.php
@@ -45796,28 +45796,28 @@ $connection->insert('term_data')
->values(array(
'tid' => '1',
'vid' => '1',
- 'name' => 'term 1 of vocabulary 1',
- 'description' => 'description of term 1 of vocabulary 1',
+ 'name' => 'zu - term 1 of vocabulary 1',
+ 'description' => 'zu - description of term 1 of vocabulary 1',
'weight' => '0',
- 'language' => '',
+ 'language' => 'zu',
'trid' => '0',
))
->values(array(
'tid' => '2',
'vid' => '2',
- 'name' => 'term 2 of vocabulary 2',
- 'description' => 'description of term 2 of vocabulary 2',
+ 'name' => 'fr - term 2 of vocabulary 2',
+ 'description' => 'fr - description of term 2 of vocabulary 2',
'weight' => '3',
- 'language' => '',
+ 'language' => 'fr',
'trid' => '0',
))
->values(array(
'tid' => '3',
'vid' => '2',
- 'name' => 'term 3 of vocabulary 2',
- 'description' => 'description of term 3 of vocabulary 2',
+ 'name' => 'fr - term 3 of vocabulary 2',
+ 'description' => 'fr - description of term 3 of vocabulary 2',
'weight' => '4',
- 'language' => '',
+ 'language' => 'fr',
'trid' => '0',
))
->values(array(
@@ -45847,6 +45847,15 @@ $connection->insert('term_data')
'language' => '',
'trid' => '0',
))
+->values(array(
+ 'tid' => '7',
+ 'vid' => '1',
+ 'name' => 'fr - term 2 of vocabulary 1',
+ 'description' => 'fr - desc of term 2 vocab 1',
+ 'weight' => '0',
+ 'language' => 'fr',
+ 'trid' => '0',
+))
->execute();
$connection->schema()->createTable('term_hierarchy', array(
@@ -45891,6 +45900,10 @@ $connection->insert('term_hierarchy')
'parent' => '0',
))
->values(array(
+ 'tid' => '7',
+ 'parent' => '0',
+))
+->values(array(
'tid' => '3',
'parent' => '2',
))
@@ -45951,6 +45964,11 @@ $connection->insert('term_node')
'tid' => '1',
))
->values(array(
+ 'nid' => '1',
+ 'vid' => '1',
+ 'tid' => '2',
+))
+->values(array(
'nid' => '2',
'vid' => '3',
'tid' => '2',
@@ -47463,6 +47481,10 @@ $connection->insert('variable')
'value' => 'a:2:{i:0;i:1;i:1;i:2;}',
))
->values(array(
+ 'name' => 'i18ntaxonomy_vocabulary',
+ 'value' => 'a:2:{i:1;s:1:"3";i:2;s:1:"2";}',
+))
+->values(array(
'name' => 'i18n_lock_node_article',
'value' => 'i:1;',
))
@@ -47990,7 +48012,7 @@ $connection->insert('vocabulary')
'tags' => '1',
'module' => 'taxonomy',
'weight' => '5',
- 'language' => '',
+ 'language' => 'fr',
))
->values(array(
'vid' => '3',
diff --git a/core/modules/migrate_drupal_ui/src/Form/MigrateUpgradeForm.php b/core/modules/migrate_drupal_ui/src/Form/MigrateUpgradeForm.php
index aacc6f0..d64a0d6 100644
--- a/core/modules/migrate_drupal_ui/src/Form/MigrateUpgradeForm.php
+++ b/core/modules/migrate_drupal_ui/src/Form/MigrateUpgradeForm.php
@@ -530,6 +530,10 @@ class MigrateUpgradeForm extends ConfirmFormBase {
'source_module' => 'taxonomy',
'destination_module' => 'taxonomy',
],
+ 'd6_taxonomy_term_translation' => [
+ 'source_module' => 'i18n',
+ 'destination_module' => 'taxonomy',
+ ],
'd6_taxonomy_vocabulary' => [
'source_module' => 'taxonomy',
'destination_module' => 'taxonomy',
diff --git a/core/modules/migrate_drupal_ui/src/Tests/d6/MigrateUpgrade6Test.php b/core/modules/migrate_drupal_ui/src/Tests/d6/MigrateUpgrade6Test.php
index 077df12..b2ef041 100644
--- a/core/modules/migrate_drupal_ui/src/Tests/d6/MigrateUpgrade6Test.php
+++ b/core/modules/migrate_drupal_ui/src/Tests/d6/MigrateUpgrade6Test.php
@@ -59,7 +59,7 @@ class MigrateUpgrade6Test extends MigrateUpgradeTestBase {
'shortcut_set' => 1,
'action' => 22,
'menu' => 8,
- 'taxonomy_term' => 6,
+ 'taxonomy_term' => 7,
'taxonomy_vocabulary' => 6,
'tour' => 4,
'user' => 7,
diff --git a/core/modules/taxonomy/migration_templates/d6_taxonomy_term_translation.yml b/core/modules/taxonomy/migration_templates/d6_taxonomy_term_translation.yml
new file mode 100644
index 0000000..11af8cd
--- /dev/null
+++ b/core/modules/taxonomy/migration_templates/d6_taxonomy_term_translation.yml
@@ -0,0 +1,39 @@
+id: d6_taxonomy_term_translation
+label: Taxonomy terms
+migration_tags:
+ - Drupal 6
+source:
+ plugin: d6_taxonomy_term
+ translations: true
+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 --git a/core/modules/taxonomy/src/Plugin/migrate/source/d6/Term.php b/core/modules/taxonomy/src/Plugin/migrate/source/d6/Term.php
index b8a603d..9170cd8 100644
--- a/core/modules/taxonomy/src/Plugin/migrate/source/d6/Term.php
+++ b/core/modules/taxonomy/src/Plugin/migrate/source/d6/Term.php
@@ -45,6 +45,10 @@ class Term extends DrupalSqlBase {
'weight' => $this->t('Weight'),
'parent' => $this->t("The Drupal term IDs of the term's parents."),
];
+ if (isset($this->configuration['translations'])) {
+ $fields['language'] = $this->t('The term language.');
+ $fields['trid'] = $this->t('Translation ID.');
+ }
return $fields;
}
diff --git a/core/modules/taxonomy/tests/src/Kernel/Migrate/d6/MigrateTaxonomyTermTest.php b/core/modules/taxonomy/tests/src/Kernel/Migrate/d6/MigrateTaxonomyTermTest.php
index 1252833..12b9a9c 100644
--- a/core/modules/taxonomy/tests/src/Kernel/Migrate/d6/MigrateTaxonomyTermTest.php
+++ b/core/modules/taxonomy/tests/src/Kernel/Migrate/d6/MigrateTaxonomyTermTest.php
@@ -36,18 +36,21 @@ class MigrateTaxonomyTermTest extends MigrateDrupal6TestBase {
'vid' => 'vocabulary_1_i_0_',
'weight' => 0,
'parent' => [0],
+ 'language' => 'zu',
],
'2' => [
'source_vid' => 2,
'vid' => 'vocabulary_2_i_1_',
'weight' => 3,
'parent' => [0],
+ 'language' => 'fr',
],
'3' => [
'source_vid' => 2,
'vid' => 'vocabulary_2_i_1_',
'weight' => 4,
'parent' => [2],
+ 'language' => 'fr',
],
'4' => [
'source_vid' => 3,
@@ -83,8 +86,9 @@ class MigrateTaxonomyTermTest extends MigrateDrupal6TestBase {
foreach ($expected_results as $tid => $values) {
/** @var Term $term */
$term = $terms[$tid];
- $this->assertIdentical("term {$tid} of vocabulary {$values['source_vid']}", $term->name->value);
- $this->assertIdentical("description of term {$tid} of vocabulary {$values['source_vid']}", $term->description->value);
+ $language = isset($values['language']) ? $values['language'] . ' - ' : '';
+ $this->assertSame("{$language}term {$tid} of vocabulary {$values['source_vid']}", $term->name->value);
+ $this->assertSame("{$language}description of term {$tid} of vocabulary {$values['source_vid']}", $term->description->value);
$this->assertIdentical($values['vid'], $term->vid->target_id);
$this->assertIdentical((string) $values['weight'], $term->weight->value);
if ($values['parent'] === [0]) {
diff --git a/core/modules/taxonomy/tests/src/Kernel/Migrate/d6/MigrateTaxonomyTermTranslationTest.php b/core/modules/taxonomy/tests/src/Kernel/Migrate/d6/MigrateTaxonomyTermTranslationTest.php
new file mode 100644
index 0000000..d21ad1e
--- /dev/null
+++ b/core/modules/taxonomy/tests/src/Kernel/Migrate/d6/MigrateTaxonomyTermTranslationTest.php
@@ -0,0 +1,124 @@
+<?php
+
+namespace Drupal\Tests\taxonomy\Kernel\Migrate\d6;
+
+use Drupal\taxonomy\Entity\Term;
+use Drupal\Tests\migrate_drupal\Kernel\d6\MigrateDrupal6TestBase;
+use Drupal\taxonomy\TermInterface;
+
+/**
+ * Test migration of translated taxonomy terms.
+ *
+ * @group migrate_drupal_6
+ */
+class MigrateTaxonomyTermTranslationTest extends MigrateDrupal6TestBase {
+
+ /**
+ * {@inheritdoc}
+ */
+ public static $modules = [
+ 'language',
+ 'menu_ui',
+ 'node',
+ 'taxonomy',
+ ];
+
+ /**
+ * The cached taxonomy tree items, keyed by vid and tid.
+ *
+ * @var array
+ */
+ protected $treeData = [];
+
+ /**
+ * {@inheritdoc}
+ */
+ protected function setUp() {
+ parent::setUp();
+ $this->installEntitySchema('taxonomy_term');
+ $this->installConfig(static::$modules);
+ $this->executeMigrations([
+ 'd6_node_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->assertInstanceOf(TermInterface::class, $entity);
+ $this->assertSame($expected_language, $entity->language()->getId());
+ $this->assertSame($expected_label, $entity->label());
+ $this->assertSame($expected_vid, $entity->getVocabularyId());
+ $this->assertSame($expected_description, $entity->getDescription());
+ $this->assertSame($expected_format, $entity->getFormat());
+ $this->assertSame($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 testTranslatedTaxonomyTerms() {
+ $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', []);
+ }
+
+}
diff --git a/core/modules/taxonomy/tests/src/Kernel/Plugin/migrate/source/d6/TermTranslationTest.php b/core/modules/taxonomy/tests/src/Kernel/Plugin/migrate/source/d6/TermTranslationTest.php
new file mode 100644
index 0000000..af69e30
--- /dev/null
+++ b/core/modules/taxonomy/tests/src/Kernel/Plugin/migrate/source/d6/TermTranslationTest.php
@@ -0,0 +1,206 @@
+<?php
+
+namespace Drupal\Tests\taxonomy\Kernel\Plugin\migrate\source\d6;
+
+use Drupal\Tests\migrate\Kernel\MigrateSqlSourceTestBase;
+
+/**
+ * Tests taxonomy term source plugin.
+ *
+ * @covers \Drupal\taxonomy\Plugin\migrate\source\d6\Term
+ * @group taxonomy
+ */
+class TermTranslationTest extends MigrateSqlSourceTestBase {
+
+ /**
+ * {@inheritdoc}
+ */
+ public static $modules = ['taxonomy', 'migrate_drupal'];
+
+ /**
+ * {@inheritdoc}
+ */
+ public function providerSource() {
+ $tests = [];
+
+ // The source data.
+ $tests[0]['source_data']['term_data'] = [
+ [
+ 'tid' => 1,
+ 'vid' => 5,
+ 'name' => 'name value 1',
+ 'description' => 'description value 1',
+ 'weight' => 0,
+ 'language' => NULL,
+ 'trid' => 0,
+ ],
+ [
+ 'tid' => 2,
+ 'vid' => 6,
+ 'name' => 'name value 2',
+ 'description' => 'description value 2',
+ 'weight' => 0,
+ 'language' => NULL,
+ 'trid' => 0,
+ ],
+ [
+ 'tid' => 3,
+ 'vid' => 6,
+ 'name' => 'name value 3',
+ 'description' => 'description value 3',
+ 'weight' => 0,
+ 'language' => NULL,
+ 'trid' => 0,
+ ],
+ [
+ 'tid' => 4,
+ 'vid' => 5,
+ 'name' => 'name value 4',
+ 'description' => 'description value 4',
+ 'weight' => 1,
+ 'language' => NULL,
+ 'trid' => 0,
+ ],
+ [
+ 'tid' => 5,
+ 'vid' => 6,
+ 'name' => 'name value 5',
+ 'description' => 'description value 5',
+ 'weight' => 1,
+ 'language' => NULL,
+ 'trid' => 0,
+ ],
+ [
+ 'tid' => 6,
+ 'vid' => 6,
+ 'name' => 'name value 6',
+ 'description' => 'description value 6',
+ 'weight' => 0,
+ 'language' => NULL,
+ 'trid' => 0,
+ ],
+ [
+ 'tid' => 10,
+ 'vid' => 6,
+ 'name' => 'zu - name value 2',
+ 'description' => 'zu - description value 2',
+ 'weight' => 0,
+ 'language' => 'zu',
+ 'trid' => 0,
+ ],
+ ];
+ $tests[0]['source_data']['term_hierarchy'] = [
+ [
+ 'tid' => 1,
+ 'parent' => 0,
+ ],
+ [
+ 'tid' => 2,
+ 'parent' => 0,
+ ],
+ [
+ 'tid' => 3,
+ 'parent' => 0,
+ ],
+ [
+ 'tid' => 4,
+ 'parent' => 1,
+ ],
+ [
+ 'tid' => 5,
+ 'parent' => 2,
+ ],
+ [
+ 'tid' => 6,
+ 'parent' => 3,
+ ],
+ [
+ 'tid' => 6,
+ 'parent' => 2,
+ ],
+ [
+ 'tid' => 10,
+ 'parent' => 0,
+ ],
+ ];
+
+ // The expected results.
+ $tests[0]['expected_data'] = [
+ [
+ 'tid' => 1,
+ 'vid' => 5,
+ 'name' => 'name value 1',
+ 'description' => 'description value 1',
+ 'weight' => 0,
+ 'parent' => [0],
+ 'language' => NULL,
+ 'trid' => 0,
+ ],
+ [
+ 'tid' => 10,
+ 'vid' => 6,
+ 'name' => 'zu - name value 2',
+ 'description' => 'zu - description value 2',
+ 'weight' => 0,
+ 'parent' => [0],
+ 'language' => 'zu',
+ 'trid' => 0,
+ ],
+ [
+ 'tid' => 2,
+ 'vid' => 6,
+ 'name' => 'name value 2',
+ 'description' => 'description value 2',
+ 'weight' => 0,
+ 'parent' => [0],
+ 'language' => NULL,
+ 'trid' => 0,
+ ],
+ [
+ 'tid' => 3,
+ 'vid' => 6,
+ 'name' => 'name value 3',
+ 'description' => 'description value 3',
+ 'weight' => 0,
+ 'parent' => [0],
+ 'language' => NULL,
+ 'trid' => 0,
+ ],
+ [
+ 'tid' => 4,
+ 'vid' => 5,
+ 'name' => 'name value 4',
+ 'description' => 'description value 4',
+ 'weight' => 1,
+ 'parent' => [1],
+ 'language' => NULL,
+ 'trid' => 0,
+ ],
+ [
+ 'tid' => 5,
+ 'vid' => 6,
+ 'name' => 'name value 5',
+ 'description' => 'description value 5',
+ 'weight' => 1,
+ 'parent' => [2],
+ 'language' => NULL,
+ 'trid' => 0,
+ ],
+ [
+ 'tid' => 6,
+ 'vid' => 6,
+ 'name' => 'name value 6',
+ 'description' => 'description value 6',
+ 'weight' => 0,
+ 'parent' => [3, 2],
+ 'language' => NULL,
+ 'trid' => 0,
+ ],
+ ];
+
+ $tests[0]['expected_count'] = NULL;
+
+ return $tests;
+ }
+
+}