onthologie -> thesaurus migration ok
This commit is contained in:
parent
fa418ebdee
commit
9b34ac0357
|
@ -22,6 +22,7 @@ process:
|
||||||
vid:
|
vid:
|
||||||
plugin: default_value
|
plugin: default_value
|
||||||
default_value: thesaurus
|
default_value: thesaurus
|
||||||
|
# langcode: language
|
||||||
name: name
|
name: name
|
||||||
'description/value': description
|
'description/value': description
|
||||||
'description/format': format
|
'description/format': format
|
||||||
|
@ -39,13 +40,12 @@ process:
|
||||||
plugin: default_value
|
plugin: default_value
|
||||||
default_value: 0
|
default_value: 0
|
||||||
source: '@parent_id'
|
source: '@parent_id'
|
||||||
forum_container: is_container
|
|
||||||
changed: timestamp
|
changed: timestamp
|
||||||
|
|
||||||
#synonyms
|
#synonyms
|
||||||
field_synonyms: synonyms
|
field_synonyms: synonyms_synonym
|
||||||
|
|
||||||
# used on advanced search
|
# used on advanced search
|
||||||
field_used_on_advanced_search: advanced_search
|
field_used_on_advanced_search: field_used_on_advanced_search
|
||||||
|
|
||||||
# TODO translation
|
# TODO translation
|
||||||
|
|
|
@ -0,0 +1,41 @@
|
||||||
|
id: d7_taxonomy_term_thesaurus_i18n
|
||||||
|
label: Taxonomy terms Thesaurus i18n
|
||||||
|
migration_group: d7_materio
|
||||||
|
audit: true
|
||||||
|
migration_tags:
|
||||||
|
- Drupal 7
|
||||||
|
- Content
|
||||||
|
- Materio
|
||||||
|
deriver: Drupal\taxonomy\Plugin\migrate\D7TaxonomyTermDeriver
|
||||||
|
|
||||||
|
source:
|
||||||
|
plugin: d7_taxonomy_term_thesaurus_i18n
|
||||||
|
bundle: onthologie
|
||||||
|
translations: true
|
||||||
|
|
||||||
|
destination:
|
||||||
|
plugin: entity: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:
|
||||||
|
plugin: migration
|
||||||
|
source: tid
|
||||||
|
migration: d7_taxonomy_term_thesaurus
|
||||||
|
vid:
|
||||||
|
plugin: default_value
|
||||||
|
default_value: thesaurus
|
||||||
|
langcode: language
|
||||||
|
|
||||||
|
name: name
|
||||||
|
|
||||||
|
'description/value': description
|
||||||
|
'description/format': format
|
||||||
|
|
||||||
|
field_synonyms: synonyms_synonym
|
||||||
|
|
||||||
|
migration_dependencies:
|
||||||
|
required:
|
||||||
|
- d7_taxonomy_term_thesaurus
|
|
@ -88,6 +88,9 @@ class D7TaxonomyTermShowroom extends FieldableEntity {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: tode node showroom
|
||||||
|
|
||||||
|
|
||||||
return parent::prepareRow($row);
|
return parent::prepareRow($row);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -21,8 +21,13 @@ class D7TaxonomyTermThesaurus extends FieldableEntity {
|
||||||
public function query() {
|
public function query() {
|
||||||
$query = $this->select('taxonomy_term_data', 'td')
|
$query = $this->select('taxonomy_term_data', 'td')
|
||||||
->fields('td')
|
->fields('td')
|
||||||
->distinct()
|
->condition('et.entity_type', 'taxonomy_term')
|
||||||
|
->condition('et.source', '')
|
||||||
->orderBy('tid');
|
->orderBy('tid');
|
||||||
|
|
||||||
|
$query->innerJoin('entity_translation', 'et', 'et.entity_id = td.tid');
|
||||||
|
$query->fields('et');
|
||||||
|
|
||||||
$query->leftJoin('taxonomy_vocabulary', 'tv', 'td.vid = tv.vid');
|
$query->leftJoin('taxonomy_vocabulary', 'tv', 'td.vid = tv.vid');
|
||||||
$query->addField('tv', 'machine_name');
|
$query->addField('tv', 'machine_name');
|
||||||
|
|
||||||
|
@ -48,6 +53,9 @@ class D7TaxonomyTermThesaurus extends FieldableEntity {
|
||||||
'format' => $this->t("Format of the term description."),
|
'format' => $this->t("Format of the term description."),
|
||||||
'synonyms' => $this->t("Term's Synonyms (field : synonyms_synonym)"),
|
'synonyms' => $this->t("Term's Synonyms (field : synonyms_synonym)"),
|
||||||
'displayed_on_advanced_search' => $this->t("field_used_on_advanced_search"),
|
'displayed_on_advanced_search' => $this->t("field_used_on_advanced_search"),
|
||||||
|
'revision_id' => $this->t('Revision ID'),
|
||||||
|
'language' => $this->t('Term translation language'),
|
||||||
|
'source' => $this->t('Term translation source language'),
|
||||||
];
|
];
|
||||||
return $fields;
|
return $fields;
|
||||||
}
|
}
|
||||||
|
@ -57,16 +65,20 @@ class D7TaxonomyTermThesaurus extends FieldableEntity {
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function prepareRow(Row $row) {
|
public function prepareRow(Row $row) {
|
||||||
print("\n\n".'-- prepareRow -- '.$row->getSourceProperty('tid')." -- ".$row->getSourceProperty('name')." -- ".$row->getSourceProperty('weight')."\n");
|
$language = $row->getSourceProperty('language');
|
||||||
|
drush_print('-- '.$language.' -- '.$row->getSourceProperty('tid')." -- ".$row->getSourceProperty('name')." -- ".$row->getSourceProperty('weight'));
|
||||||
|
|
||||||
|
$tid = $row->getSourceProperty('tid');
|
||||||
|
// vocabulary machine name
|
||||||
|
$machine_name = $row->getSourceProperty('machine_name');
|
||||||
|
$revid = $row->getSourceProperty('revision_id');
|
||||||
|
|
||||||
// Get Field API field values.
|
// Get Field API field values.
|
||||||
// foreach (array_keys($this->getFields('taxonomy_term', $row->getSourceProperty('machine_name'))) as $field) {
|
foreach ($this->getFields('taxonomy_term', $machine_name) as $field_name => $field) {
|
||||||
// $tid = $row->getSourceProperty('tid');
|
// Ensure we're using the right language if the entity is translatable.
|
||||||
// $row->setSourceProperty($field, $this->getFieldValues('taxonomy_term', $field, $tid));
|
$field_language = $field['translatable'] ? $language : NULL;
|
||||||
// print("field: ".$field."\n");
|
$row->setSourceProperty($field_name, $this->getFieldValues('taxonomy_term', $field_name, $tid, $revid, $field_language));
|
||||||
// print_r($this->getFieldValues('taxonomy_term', $field, $tid));
|
}
|
||||||
// print("-\n");
|
|
||||||
// }
|
|
||||||
|
|
||||||
// Find parents for this row.
|
// Find parents for this row.
|
||||||
$parents = $this->select('taxonomy_term_hierarchy', 'th')
|
$parents = $this->select('taxonomy_term_hierarchy', 'th')
|
||||||
|
@ -75,66 +87,16 @@ class D7TaxonomyTermThesaurus extends FieldableEntity {
|
||||||
->execute()
|
->execute()
|
||||||
->fetchCol();
|
->fetchCol();
|
||||||
$row->setSourceProperty('parent', $parents);
|
$row->setSourceProperty('parent', $parents);
|
||||||
// print_r($parents);
|
|
||||||
|
|
||||||
// get the english term name as defaut
|
// If the node title was replaced by a real field using the Drupal 7 Title
|
||||||
$query = $this->select('entity_translation', 'et')
|
// module, use the field value instead of the node title.
|
||||||
// ->fields('et', [
|
|
||||||
// 'entity_id',
|
|
||||||
// 'revision_id',
|
|
||||||
// 'language',
|
|
||||||
// 'source',
|
|
||||||
// 'uid',
|
|
||||||
// 'status',
|
|
||||||
// 'created',
|
|
||||||
// 'changed',
|
|
||||||
// ])
|
|
||||||
// ->distinct()
|
|
||||||
->condition('et.entity_type', 'taxonomy_term')
|
|
||||||
->condition('et.language', 'en')
|
|
||||||
->condition('rnf.language', 'en')
|
|
||||||
->condition('et.entity_id', $row->getSourceProperty('tid'));
|
|
||||||
$query->innerjoin('field_revision_name_field', 'rnf', 'rnf.revision_id = et.revision_id');
|
|
||||||
$query->fields('rnf', ['name_field_value']);
|
|
||||||
$name_field_en = $query->execute()->fetchField();
|
|
||||||
|
|
||||||
print($name_field_en);
|
|
||||||
|
|
||||||
if($name_field_en != NULL && $name_field_en != ""){
|
|
||||||
$row->setSourceProperty('name', $name_field_en);
|
|
||||||
}
|
|
||||||
|
|
||||||
// If the term name or term description were replaced by real fields using
|
|
||||||
// the Drupal 7 Title module, use the fields value instead of the term name
|
|
||||||
// or term description.
|
|
||||||
// if ($this->moduleExists('title')) {
|
|
||||||
// $name_field = $row->getSourceProperty('name_field');
|
|
||||||
// // print_r($name_field);
|
|
||||||
// if (isset($name_field[0]['value'])) {
|
|
||||||
// $row->setSourceProperty('name', $name_field[0]['value']);
|
|
||||||
// }
|
|
||||||
// $description_field = $row->getSourceProperty('description_field');
|
|
||||||
// if (isset($description_field[0]['value'])) {
|
|
||||||
// $row->setSourceProperty('description', $description_field[0]['value']);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
// Synonyms
|
|
||||||
if ($this->moduleExists('title')) {
|
if ($this->moduleExists('title')) {
|
||||||
$synonyms = $row->getSourceProperty('synonyms_synonym');
|
$name_field = $row->getSourceProperty('name_field');
|
||||||
// print_r($synonyms);
|
if (isset($name_field[0]['value'])) {
|
||||||
if(!empty($synonyms)){
|
$row->setSourceProperty('name', $name_field[0]['value']);
|
||||||
$row->setSourceProperty('synonyms', $synonyms);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// displayed_on_advanced_search
|
|
||||||
$advanced_search = $row->getSourceProperty('field_used_on_advanced_search');
|
|
||||||
// print_r($advanced_search);
|
|
||||||
if(!empty($advanced_search)){
|
|
||||||
$row->setSourceProperty('advanced_search', $advanced_search);
|
|
||||||
}
|
|
||||||
|
|
||||||
return parent::prepareRow($row);
|
return parent::prepareRow($row);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,99 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Drupal\materio_migrate\Plugin\migrate\source;
|
||||||
|
|
||||||
|
use Drupal\migrate\Row;
|
||||||
|
use Drupal\migrate_drupal\Plugin\migrate\source\d7\FieldableEntity;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Taxonomy term source from database.
|
||||||
|
*
|
||||||
|
* @MigrateSource(
|
||||||
|
* id = "d7_taxonomy_term_thesaurus_i18n",
|
||||||
|
* source_module = "taxonomy"
|
||||||
|
* )
|
||||||
|
*/
|
||||||
|
class D7TaxonomyTermThesaurusI18n extends FieldableEntity {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public function query() {
|
||||||
|
$query = $this->select('taxonomy_term_data', 'td')
|
||||||
|
->fields('td')
|
||||||
|
->condition('et.entity_type', 'taxonomy_term')
|
||||||
|
->condition('et.source', '', '<>')
|
||||||
|
->orderBy('tid');
|
||||||
|
|
||||||
|
$query->innerJoin('entity_translation', 'et', 'et.entity_id = td.tid');
|
||||||
|
$query->fields('et');
|
||||||
|
$query->leftJoin('taxonomy_vocabulary', 'tv', 'tv.vid = td.vid');
|
||||||
|
$query->fields('tv', ['machine_name']);
|
||||||
|
|
||||||
|
if (isset($this->configuration['bundle'])) {
|
||||||
|
$query->condition('tv.machine_name', (array) $this->configuration['bundle'], 'IN');
|
||||||
|
}
|
||||||
|
return $query;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public function fields() {
|
||||||
|
$fields = [
|
||||||
|
'tid' => $this->t('The term ID.'),
|
||||||
|
'vid' => $this->t('Existing term VID'),
|
||||||
|
'machine_name' => $this->t('Vocabulary machine name'),
|
||||||
|
'name' => $this->t('The name of the term.'),
|
||||||
|
'revision_id' => $this->t('Revision ID'),
|
||||||
|
'language' => $this->t('Term translation language'),
|
||||||
|
'source' => $this->t('Term translation source language'),
|
||||||
|
'description' => $this->t('The term description.'),
|
||||||
|
'weight' => $this->t('Weight'),
|
||||||
|
'parent' => $this->t("The Drupal term IDs of the term's parents."),
|
||||||
|
'format' => $this->t("Format of the term description."),
|
||||||
|
];
|
||||||
|
return $fields;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public function prepareRow(Row $row) {
|
||||||
|
$language = $row->getSourceProperty('language');
|
||||||
|
drush_print('-- '. $language .' -- '.$row->getSourceProperty('tid')." -- ".$row->getSourceProperty('name')." -- ".$row->getSourceProperty('weight'));
|
||||||
|
|
||||||
|
$tid = $row->getSourceProperty('tid');
|
||||||
|
// vocabulary machine name
|
||||||
|
$machine_name = $row->getSourceProperty('machine_name');
|
||||||
|
$revid = $row->getSourceProperty('revision_id');
|
||||||
|
|
||||||
|
// Get Field API field values.
|
||||||
|
foreach ($this->getFields('taxonomy_term', $machine_name) as $field_name => $field) {
|
||||||
|
// Ensure we're using the right language if the entity is translatable.
|
||||||
|
$field_language = $field['translatable'] ? $language : NULL;
|
||||||
|
$row->setSourceProperty($field_name, $this->getFieldValues('taxonomy_term', $field_name, $tid, $revid, $field_language));
|
||||||
|
}
|
||||||
|
|
||||||
|
// If the node title was replaced by a real field using the Drupal 7 Title
|
||||||
|
// module, use the field value instead of the node title.
|
||||||
|
if ($this->moduleExists('title')) {
|
||||||
|
$name_field = $row->getSourceProperty('name_field');
|
||||||
|
if (isset($name_field[0]['value'])) {
|
||||||
|
$row->setSourceProperty('name', $name_field[0]['value']);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return parent::prepareRow($row);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public function getIds() {
|
||||||
|
$ids['tid']['type'] = 'integer';
|
||||||
|
return $ids;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue