Commit a001cd8f authored by Gábor Hojtsy's avatar Gábor Hojtsy

Issue #2784371 by Jo Fitzgerald, quietone, phenaproxima, Gábor Hojtsy,...

Issue #2784371 by Jo Fitzgerald, quietone, phenaproxima, Gábor Hojtsy, mikeryan, jhodgdon: Migrate D6 i18n taxonomy terms
parent 1421285e
......@@ -45796,28 +45796,28 @@
->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 @@
'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(
......@@ -45890,6 +45899,10 @@
'tid' => '4',
'parent' => '0',
))
->values(array(
'tid' => '7',
'parent' => '0',
))
->values(array(
'tid' => '3',
'parent' => '2',
......@@ -45950,6 +45963,11 @@
'vid' => '1',
'tid' => '1',
))
->values(array(
'nid' => '1',
'vid' => '1',
'tid' => '2',
))
->values(array(
'nid' => '2',
'vid' => '3',
......@@ -47462,6 +47480,10 @@
'name' => 'i18nstrings_allowed_formats',
'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 @@
'tags' => '1',
'module' => 'taxonomy',
'weight' => '5',
'language' => '',
'language' => 'fr',
))
->values(array(
'vid' => '3',
......@@ -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',
......
......@@ -59,7 +59,7 @@ protected function getEntityCounts() {
'shortcut_set' => 1,
'action' => 22,
'menu' => 8,
'taxonomy_term' => 6,
'taxonomy_term' => 7,
'taxonomy_vocabulary' => 6,
'tour' => 4,
'user' => 7,
......
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
......@@ -45,6 +45,10 @@ public function fields() {
'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;
}
......
......@@ -36,18 +36,21 @@ public function testTaxonomyTerms() {
'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 @@ public function testTaxonomyTerms() {
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]) {
......
<?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', []);
}
}
<?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;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment