Commit 955ffc8c authored by Gábor Hojtsy's avatar Gábor Hojtsy

Issue #2859297 by quietone, masipila, jhodgdon, Gábor Hojtsy, heddn: Migrate...

Issue #2859297 by quietone, masipila, jhodgdon, Gábor Hojtsy, heddn: Migrate taxonomy term references for D6 Node translations
parent c210fadd
id: d6_term_node_translation
label: Term/node translation relationships
migration_tags:
- Drupal 6
- Content
- Multilingual
deriver: Drupal\taxonomy\Plugin\migrate\D6TermNodeDeriver
source:
plugin: d6_term_node
process:
dest_nid:
-
plugin: migration_lookup
migration: d6_node_translation
source: nid
-
plugin: skip_on_empty
method: row
nid:
-
plugin: extract
index: [0]
source: '@dest_nid'
-
plugin: skip_on_empty
method: row
langcode:
-
plugin: extract
index: [1]
source: '@dest_nid'
-
plugin: skip_on_empty
method: row
type: type
# The actual field name is dynamic and will be added by the builder.
destination:
plugin: entity:node
translations: true
migration_dependencies:
required:
- d6_vocabulary_entity_display
- d6_vocabulary_entity_form_display
- d6_node
- d6_node_translation
......@@ -46,6 +46,7 @@ function migrate_drupal_migration_plugins_alter(&$definitions) {
],
];
$vocabulary_migration = \Drupal::service('plugin.manager.migration')->createStubMigration($vocabulary_migration_definition);
$translation_active = \Drupal::service('module_handler')->moduleExists('config_translation');
try {
$source_plugin = $vocabulary_migration->getSourcePlugin();
......@@ -57,7 +58,13 @@ function migrate_drupal_migration_plugins_alter(&$definitions) {
foreach ($source_plugin as $row) {
$executable->processRow($row, $process);
$source_vid = $row->getSourceProperty('vid');
$plugin_ids = ['d6_term_node:' . $source_vid, 'd6_term_node_revision:' . $source_vid];
$plugin_ids = [
'd6_term_node:' . $source_vid,
'd6_term_node_revision:' . $source_vid,
];
if ($translation_active) {
$plugin_ids[] = 'd6_term_node_translation:' . $source_vid;
}
foreach ($plugin_ids as $plugin_id) {
// Match the field name derivation in d6_vocabulary_field.yml.
$field_name = substr('field_' . $row->getDestinationProperty('vid'), 0, 32);
......
......@@ -8711,6 +8711,16 @@
'nid',
'timestamp',
))
->values(array(
'uid' => '1',
'nid' => '1',
'timestamp' => '1549874910',
))
->values(array(
'uid' => '1',
'nid' => '2',
'timestamp' => '1549874910',
))
->values(array(
'uid' => '1',
'nid' => '3',
......@@ -27771,6 +27781,14 @@
'plural' => '0',
'i18n_status' => '0',
))
->values(array(
'lid' => '1672',
'translation' => 'fr - Type',
'language' => 'fr',
'plid' => '0',
'plural' => '0',
'i18n_status' => '0',
))
->values(array(
'lid' => '1678',
'translation' => 'fr - I really, really, really love migrating ',
......@@ -27779,6 +27797,38 @@
'plural' => '0',
'i18n_status' => '0',
))
->values(array(
'lid' => '1690',
'translation' => 'Noir',
'language' => 'fr',
'plid' => '0',
'plural' => '0',
'i18n_status' => '0',
))
->values(array(
'lid' => '1692',
'translation' => 'fr - Talos IV',
'language' => 'fr',
'plid' => '0',
'plural' => '0',
'i18n_status' => '0',
))
->values(array(
'lid' => '1694',
'translation' => 'fr - The home of Captain Christopher Pike.',
'language' => 'fr',
'plid' => '0',
'plural' => '0',
'i18n_status' => '0',
))
->values(array(
'lid' => '1696',
'translation' => "fr - 10\r\nfr - 20\r\nfr - 50\r\nfr - 100\r\nfr - 1000",
'language' => 'fr',
'plid' => '0',
'plural' => '0',
'i18n_status' => '0',
))
->values(array(
'lid' => '66',
'translation' => 'zu - CCK - Aucune Intégration aux Vues',
......@@ -27907,14 +27957,6 @@
'plural' => '0',
'i18n_status' => '0',
))
->values(array(
'lid' => '1690',
'translation' => 'Noir',
'language' => 'fr',
'plid' => '0',
'plural' => '0',
'i18n_status' => '0',
))
->values(array(
'lid' => '1691',
'translation' => 'Mhlophe',
......@@ -27923,22 +27965,6 @@
'plural' => '0',
'i18n_status' => '0',
))
->values(array(
'lid' => '1672',
'translation' => 'fr - Type',
'language' => 'fr',
'plid' => '0',
'plural' => '0',
'i18n_status' => '0',
))
->values(array(
'lid' => '1692',
'translation' => 'fr - Talos IV',
'language' => 'fr',
'plid' => '0',
'plural' => '0',
'i18n_status' => '0',
))
->values(array(
'lid' => '1693',
'translation' => 'zu - Vulcan',
......@@ -27955,22 +27981,6 @@
'plural' => '0',
'i18n_status' => '0',
))
->values(array(
'lid' => '1694',
'translation' => 'fr - The home of Captain Christopher Pike.',
'language' => 'fr',
'plid' => '0',
'plural' => '0',
'i18n_status' => '0',
))
->values(array(
'lid' => '1696',
'translation' => "fr - 10\r\nfr - 20\r\nfr - 50\r\nfr - 100\r\nfr - 1000",
'language' => 'fr',
'plid' => '0',
'plural' => '0',
'i18n_status' => '0',
))
->execute();
$connection->schema()->createTable('menu_custom', array(
'fields' => array(
......@@ -48070,6 +48080,16 @@
'vid' => '2001',
'tid' => '4',
))
->values(array(
'nid' => '21',
'vid' => '2002',
'tid' => '4',
))
->values(array(
'nid' => '18',
'vid' => '21',
'tid' => '5',
))
->values(array(
'nid' => '1',
'vid' => '2001',
......@@ -48080,6 +48100,26 @@
'vid' => '22',
'tid' => '8',
))
->values(array(
'nid' => '22',
'vid' => '2003',
'tid' => '9',
))
->values(array(
'nid' => '22',
'vid' => '2003',
'tid' => '14',
))
->values(array(
'nid' => '18',
'vid' => '21',
'tid' => '15',
))
->values(array(
'nid' => '21',
'vid' => '2002',
'tid' => '15',
))
->execute();
$connection->schema()->createTable('term_relation', array(
'fields' => array(
......@@ -50192,7 +50232,7 @@
'description' => 'description of vocabulary 3 (i=2)',
'help' => '',
'relations' => '1',
'hierarchy' => '2',
'hierarchy' => '0',
'multiple' => '1',
'required' => '0',
'tags' => '0',
......@@ -50220,7 +50260,7 @@
'description' => 'description of vocabulary name much longer than thirty two characters',
'help' => '',
'relations' => '1',
'hierarchy' => '3',
'hierarchy' => '0',
'multiple' => '1',
'required' => '0',
'tags' => '0',
......@@ -50289,6 +50329,14 @@
'vid' => '4',
'type' => 'article',
))
->values(array(
'vid' => '3',
'type' => 'employee',
))
->values(array(
'vid' => '5',
'type' => 'employee',
))
->values(array(
'vid' => '7',
'type' => 'forum',
......@@ -68,7 +68,7 @@ protected function getEntityCounts() {
'contact_message' => 0,
'configurable_language' => 5,
'editor' => 2,
'field_config' => 93,
'field_config' => 95,
'field_storage_config' => 66,
'file' => 7,
'filter_format' => 7,
......
......@@ -63,7 +63,7 @@ process:
default_value: 0
map:
0: false
1: false
1: true
2: false
3: true
destination:
......
......@@ -2,6 +2,7 @@
namespace Drupal\taxonomy\Plugin\migrate\source\d6;
use Drupal\migrate\Row;
use Drupal\migrate_drupal\Plugin\migrate\source\DrupalSqlBase;
/**
......@@ -19,11 +20,12 @@ class VocabularyTranslation extends DrupalSqlBase {
*/
public function query() {
$query = $this->select('vocabulary', 'v')
->fields('v', ['vid', 'name', 'description'])
->fields('v')
->fields('i18n', ['lid', 'type', 'property', 'objectid'])
->fields('lt', ['lid', 'translation'])
->condition('i18n.type', 'vocabulary');
$query->addField('lt', 'language', 'language');
->condition('i18n.type', 'vocabulary')
->isNotNull('lt.language');
$query->addField('lt', 'language', 'lt.language');
// The i18n_strings table has two columns containing the object ID, objectid
// and objectindex. The objectid column is a text field. Therefore, for the
// join to work in PostgreSQL, use the objectindex field as this is numeric
......@@ -31,6 +33,7 @@ public function query() {
$query->join('i18n_strings', 'i18n', 'v.vid = i18n.objectindex');
$query->leftJoin('locales_target', 'lt', 'lt.lid = i18n.lid');
$a = $query->execute()->fetchAll();
return $query;
}
......@@ -46,11 +49,23 @@ public function fields() {
];
}
/**
* {@inheritdoc}
*/
public function prepareRow(Row $row) {
// For ease of reading the migration use 'language' as the property name for
// the language.
$language = $row->getSourceProperty('ltlanguage');
$row->setSourceProperty('language', $language);
}
/**
* {@inheritdoc}
*/
public function getIds() {
$ids['vid']['type'] = 'integer';
$ids['language']['type'] = 'string';
$ids['language']['alias'] = 'lt';
return $ids;
}
......
......@@ -38,6 +38,8 @@ protected function setUp() {
*/
public function testTaxonomyVocabularyTranslation() {
$language_manager = \Drupal::service('language_manager');
$config = $language_manager->getLanguageConfigOverride('zu', 'taxonomy.vocabulary.vocabulary_1_i_0_');
$this->assertSame('zu - vocabulary 1 (i=0)', $config->get('name'));
$config = $language_manager->getLanguageConfigOverride('fr', 'taxonomy.vocabulary.vocabulary_1_i_0_');
$this->assertSame('fr - vocabulary 1 (i=0)', $config->get('name'));
$config = $language_manager->getLanguageConfigOverride('fr', 'taxonomy.vocabulary.vocabulary_2_i_1_');
......
<?php
namespace Drupal\Tests\taxonomy\Kernel\Migrate\d6;
use Drupal\Tests\migrate_drupal\Kernel\d6\MigrateDrupal6TestBase;
use Drupal\node\Entity\Node;
/**
* Upgrade taxonomy term node associations.
*
* @group migrate_drupal_6
*/
class MigrateTermNodeTranslationTest extends MigrateDrupal6TestBase {
/**
* {@inheritdoc}
*/
public static $modules = [
'config_translation',
'content_translation',
'language',
'menu_ui',
'migrate_drupal_multilingual',
'taxonomy',
];
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$this->installEntitySchema('node');
$this->installConfig(['node']);
$this->installSchema('node', ['node_access']);
$this->installSchema('system', ['sequences']);
$this->executeMigration('d6_node_settings');
$this->migrateUsers(FALSE);
$this->migrateFields();
$this->migrateTaxonomy();
$this->migrateContent(['translations']);
// This is a base plugin id and we want to run all derivatives.
$this->executeMigrations([
'd6_term_node',
'd6_term_node_translation',
]);
}
/**
* Tests the Drupal 6 term-node association to Drupal 8 migration.
*/
public function testTermNode() {
$this->container->get('entity.manager')
->getStorage('node')
->resetCache([18, 21]);
// Test with translated content type employee. Vocabulary
// field_vocabulary_name_much_longe is a localized vocabulary and
// field_vocabulary_3_i_2_ is a per language vocabulary.
// An untranslated node.
$node = Node::load(18);
// A localized vocabulary.
$this->assertSame('15', $node->field_vocabulary_name_much_longe[0]->target_id);
// Per language vocabulary.
$this->assertSame('5', $node->field_vocabulary_3_i_2_[0]->target_id);
// A translated node.
// The English node.
$node = Node::load(21);
$this->assertSame('15', $node->field_vocabulary_name_much_longe[0]->target_id);
$this->assertSame('4', $node->field_vocabulary_3_i_2_[0]->target_id);
// The French translation of the English node.
$translation = $node->getTranslation('fr');
$this->assertSame('14', $translation->field_vocabulary_name_much_longe[0]->target_id);
$this->assertSame('9', $translation->field_vocabulary_3_i_2_[0]->target_id);
}
}
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