created plugins for migration
thesaurus is importing well for default language (en)
This commit is contained in:
parent
374c688f36
commit
878d6f510c
|
@ -1,35 +0,0 @@
|
|||
id: d7_taxonomy_vocabulary_company
|
||||
label: Taxonomy vocabularies Company
|
||||
migration_group: d7_materio
|
||||
migration_tags:
|
||||
- Drupal 7
|
||||
- Configuration
|
||||
- Materio
|
||||
|
||||
source:
|
||||
plugin: d7_taxonomy_vocabulary
|
||||
bundle: company
|
||||
|
||||
destination:
|
||||
plugin: entity:taxonomy_vocabulary
|
||||
|
||||
process:
|
||||
vid:
|
||||
-
|
||||
plugin: make_unique_entity_field
|
||||
source: machine_name
|
||||
entity_type: taxonomy_vocabulary
|
||||
field: vid
|
||||
length: 32
|
||||
migrated: true
|
||||
-
|
||||
# This plugin checks if the vocabulary being migrated is the one used by
|
||||
# Forum. If so, we use the machine name that Forum expects. Otherwise, we
|
||||
# leave it unchanged.
|
||||
plugin: forum_vocabulary
|
||||
machine_name: forums
|
||||
label: name
|
||||
name: name
|
||||
description: description
|
||||
hierarchy: hierarchy
|
||||
weight: weight
|
|
@ -1,35 +0,0 @@
|
|||
id: d7_taxonomy_vocabulary_showroom
|
||||
label: Taxonomy vocabularies Showroom
|
||||
migration_group: d7_materio
|
||||
migration_tags:
|
||||
- Drupal 7
|
||||
- Configuration
|
||||
- Materio
|
||||
|
||||
source:
|
||||
plugin: d7_taxonomy_vocabulary
|
||||
bundle: showroom
|
||||
|
||||
destination:
|
||||
plugin: entity:taxonomy_vocabulary
|
||||
|
||||
process:
|
||||
vid:
|
||||
-
|
||||
plugin: make_unique_entity_field
|
||||
source: machine_name
|
||||
entity_type: taxonomy_vocabulary
|
||||
field: vid
|
||||
length: 32
|
||||
migrated: true
|
||||
-
|
||||
# This plugin checks if the vocabulary being migrated is the one used by
|
||||
# Forum. If so, we use the machine name that Forum expects. Otherwise, we
|
||||
# leave it unchanged.
|
||||
plugin: forum_vocabulary
|
||||
machine_name: forums
|
||||
label: name
|
||||
name: name
|
||||
description: description
|
||||
hierarchy: hierarchy
|
||||
weight: weight
|
|
@ -1,35 +0,0 @@
|
|||
id: d7_taxonomy_vocabulary_tags
|
||||
label: Taxonomy vocabularies Tags
|
||||
migration_group: d7_materio
|
||||
migration_tags:
|
||||
- Drupal 7
|
||||
- Configuration
|
||||
- Materio
|
||||
|
||||
source:
|
||||
plugin: d7_taxonomy_vocabulary
|
||||
bundle: tag_libres
|
||||
|
||||
destination:
|
||||
plugin: entity:taxonomy_vocabulary
|
||||
|
||||
process:
|
||||
vid:
|
||||
-
|
||||
plugin: make_unique_entity_field
|
||||
source: machine_name
|
||||
entity_type: taxonomy_vocabulary
|
||||
field: vid
|
||||
length: 32
|
||||
migrated: true
|
||||
-
|
||||
# This plugin checks if the vocabulary being migrated is the one used by
|
||||
# Forum. If so, we use the machine name that Forum expects. Otherwise, we
|
||||
# leave it unchanged.
|
||||
plugin: forum_vocabulary
|
||||
machine_name: forums
|
||||
label: name
|
||||
name: name
|
||||
description: description
|
||||
hierarchy: hierarchy
|
||||
weight: weight
|
|
@ -1,35 +0,0 @@
|
|||
id: d7_taxonomy_vocabulary_thesaurus
|
||||
label: Taxonomy vocabularies Thesaurus
|
||||
migration_group: d7_materio
|
||||
migration_tags:
|
||||
- Drupal 7
|
||||
- Configuration
|
||||
- Materio
|
||||
|
||||
source:
|
||||
plugin: d7_taxonomy_vocabulary
|
||||
bundle: onthologie
|
||||
|
||||
destination:
|
||||
plugin: entity:taxonomy_vocabulary
|
||||
|
||||
process:
|
||||
vid:
|
||||
-
|
||||
plugin: make_unique_entity_field
|
||||
source: machine_name
|
||||
entity_type: taxonomy_vocabulary
|
||||
field: vid
|
||||
length: 32
|
||||
migrated: true
|
||||
-
|
||||
# This plugin checks if the vocabulary being migrated is the one used by
|
||||
# Forum. If so, we use the machine name that Forum expects. Otherwise, we
|
||||
# leave it unchanged.
|
||||
plugin: forum_vocabulary
|
||||
machine_name: forums
|
||||
label: name
|
||||
name: name
|
||||
description: description
|
||||
hierarchy: hierarchy
|
||||
weight: weight
|
|
@ -38,3 +38,22 @@ process:
|
|||
revision_log: log
|
||||
revision_timestamp: timestamp
|
||||
content_translation_source: source
|
||||
|
||||
# TODO: mémo (field_memo)
|
||||
# TODO: nature (field_nature_titre)
|
||||
# TODO: description (field_description)
|
||||
# TODO: thesaurus (field_onthologie)
|
||||
# TODO: tags (field_tags_libres)
|
||||
# TODO: images (field_materiau_image)
|
||||
# TODO: videos (field_video_filter)
|
||||
# TODO: manufacturer (field_company_fab)
|
||||
# TODO: distributor (field_company_distrib)
|
||||
# TODO: fichiers (field_attachments)
|
||||
# TODO: materiaux liés (field_materiau_ref)
|
||||
# TODO: breves liées (field_breve_ref)
|
||||
# TODO: samples (field_location)
|
||||
# TODO: famille (field_famille)
|
||||
# TODO: identifiant (field_identifiant)
|
||||
# TODO: reference materio (field_reference_materio) COMPUTED
|
||||
# TODO: workflow
|
||||
# TODO: translations
|
||||
|
|
|
@ -9,27 +9,19 @@ migration_tags:
|
|||
deriver: Drupal\taxonomy\Plugin\migrate\D7TaxonomyTermDeriver
|
||||
|
||||
source:
|
||||
plugin: d7_taxonomy_term
|
||||
plugin: d7_taxonomy_term_company
|
||||
bundle: company
|
||||
|
||||
destination:
|
||||
plugin: entity:taxonomy_term
|
||||
bundle: company
|
||||
|
||||
# migration_dependencies:
|
||||
# required:
|
||||
# - d7_taxonomy_vocabulary_company
|
||||
# optional:
|
||||
# - d7_field_instance
|
||||
|
||||
process:
|
||||
# If you are using this file to build a custom migration consider removing
|
||||
# the tid field to allow incremental migrations.
|
||||
tid: tid
|
||||
# tid: tid
|
||||
vid:
|
||||
plugin: migration_lookup
|
||||
migration: d7_taxonomy_vocabulary_company
|
||||
source: vid
|
||||
plugin: default_value
|
||||
default_value: company
|
||||
name: name
|
||||
'description/value': description
|
||||
'description/format': format
|
||||
|
@ -49,3 +41,5 @@ process:
|
|||
source: '@parent_id'
|
||||
forum_container: is_container
|
||||
changed: timestamp
|
||||
|
||||
# TODO: tode node company
|
||||
|
|
|
@ -9,27 +9,19 @@ migration_tags:
|
|||
deriver: Drupal\taxonomy\Plugin\migrate\D7TaxonomyTermDeriver
|
||||
|
||||
source:
|
||||
plugin: d7_taxonomy_term
|
||||
plugin: d7_taxonomy_term_showroom
|
||||
bundle: showroom
|
||||
|
||||
destination:
|
||||
plugin: entity:taxonomy_term
|
||||
bundle: showroom
|
||||
|
||||
# migration_dependencies:
|
||||
# required:
|
||||
# - d7_taxonomy_vocabulary_showroom
|
||||
# optional:
|
||||
# - d7_field_instance
|
||||
|
||||
process:
|
||||
# If you are using this file to build a custom migration consider removing
|
||||
# the tid field to allow incremental migrations.
|
||||
tid: tid
|
||||
# tid: tid
|
||||
vid:
|
||||
plugin: migration_lookup
|
||||
migration: d7_taxonomy_vocabulary_showroom
|
||||
source: vid
|
||||
plugin: default_value
|
||||
default_value: showroom
|
||||
name: name
|
||||
'description/value': description
|
||||
'description/format': format
|
||||
|
@ -49,3 +41,5 @@ process:
|
|||
source: '@parent_id'
|
||||
forum_container: is_container
|
||||
changed: timestamp
|
||||
|
||||
# TODO: tode node showroom
|
||||
|
|
|
@ -9,27 +9,19 @@ migration_tags:
|
|||
deriver: Drupal\taxonomy\Plugin\migrate\D7TaxonomyTermDeriver
|
||||
|
||||
source:
|
||||
plugin: d7_taxonomy_term
|
||||
plugin: d7_taxonomy_term_tags
|
||||
bundle: tag_libres
|
||||
|
||||
destination:
|
||||
plugin: entity:taxonomy_term
|
||||
bundle: tags
|
||||
|
||||
# migration_dependencies:
|
||||
# required:
|
||||
# - d7_taxonomy_vocabulary_tags
|
||||
# optional:
|
||||
# - d7_field_instance
|
||||
|
||||
process:
|
||||
# If you are using this file to build a custom migration consider removing
|
||||
# the tid field to allow incremental migrations.
|
||||
# tid: tid
|
||||
vid:
|
||||
plugin: migration_lookup
|
||||
migration: d7_taxonomy_vocabulary_tags
|
||||
source: vid
|
||||
plugin: default_value
|
||||
default_value: tags
|
||||
name: name
|
||||
'description/value': description
|
||||
'description/format': format
|
||||
|
@ -49,3 +41,8 @@ process:
|
|||
source: '@parent_id'
|
||||
forum_container: is_container
|
||||
changed: timestamp
|
||||
|
||||
#synonyms
|
||||
field_synonyms: synonyms
|
||||
|
||||
# TODO translation
|
||||
|
|
|
@ -9,27 +9,19 @@ migration_tags:
|
|||
deriver: Drupal\taxonomy\Plugin\migrate\D7TaxonomyTermDeriver
|
||||
|
||||
source:
|
||||
plugin: d7_taxonomy_term
|
||||
plugin: d7_taxonomy_term_thesaurus
|
||||
bundle: onthologie
|
||||
|
||||
destination:
|
||||
plugin: entity:taxonomy_term
|
||||
bundle: thesaurus
|
||||
|
||||
# migration_dependencies:
|
||||
# required:
|
||||
# - d7_taxonomy_vocabulary_thesaurus
|
||||
# optional:
|
||||
# - d7_field_instance
|
||||
|
||||
process:
|
||||
# If you are using this file to build a custom migration consider removing
|
||||
# the tid field to allow incremental migrations.
|
||||
tid: tid
|
||||
# tid: tid
|
||||
vid:
|
||||
plugin: migration_lookup
|
||||
migration: d7_taxonomy_vocabulary_thesaurus
|
||||
source: vid
|
||||
plugin: default_value
|
||||
default_value: thesaurus
|
||||
name: name
|
||||
'description/value': description
|
||||
'description/format': format
|
||||
|
@ -49,3 +41,11 @@ process:
|
|||
source: '@parent_id'
|
||||
forum_container: is_container
|
||||
changed: timestamp
|
||||
|
||||
#synonyms
|
||||
field_synonyms: synonyms
|
||||
|
||||
# used on advanced search
|
||||
field_used_on_advanced_search: advanced_search
|
||||
|
||||
# TODO translation
|
||||
|
|
|
@ -4,23 +4,19 @@ description: Defines custom migration for materio (from d7 to d8).
|
|||
core: 8.x
|
||||
package: Materio
|
||||
dependencies:
|
||||
- config_devel
|
||||
- drupal:migrate
|
||||
- drupal:migrate_drupal
|
||||
- drupal:migrate_drupal_multilingual
|
||||
# - drupal:field_group_migrate
|
||||
- migrate_plus:migrate_plus
|
||||
- migrate_tools:migrate_tools
|
||||
- config_devel
|
||||
# - drupal:field_group_migrate
|
||||
|
||||
config_devel:
|
||||
install:
|
||||
- migrate_plus.migration_group.d7_materio
|
||||
# - migrate_plus.migration.d7_taxonomy_vocabulary_tags
|
||||
- migrate_plus.migration.d7_taxonomy_term_tags
|
||||
# - migrate_plus.migration.d7_taxonomy_vocabulary_thesaurus
|
||||
- migrate_plus.migration.d7_taxonomy_term_thesaurus
|
||||
# - migrate_plus.migration.d7_taxonomy_vocabulary_showroom
|
||||
- migrate_plus.migration.d7_taxonomy_term_tags
|
||||
- migrate_plus.migration.d7_taxonomy_term_showroom
|
||||
# - migrate_plus.migration.d7_taxonomy_vocabulary_company
|
||||
- migrate_plus.migration.d7_taxonomy_term_company
|
||||
- migrate_plus.migration.d7_node_entity_translation_materiau
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
[debugging-migrations](https://www.drupal.org/docs/8/api/migrate-api/debugging-migrations)
|
||||
|
||||
https://www.drupaleasy.com/blogs/ultimike/2016/04/drupal-6-drupal-81x-custom-content-migration
|
||||
|
||||
https://thinkshout.com/blog/2017/05/skipping-a-version-migrating-from-drupal-6-to-drupal-8-with-drupal-migrate/
|
||||
|
@ -27,3 +29,7 @@ https://evolvingweb.ca/blog/drupal-8-migration-migrating-taxonomy-term-reference
|
|||
[Migrating Drupal 7 redirects to Drupal 8](http://activelamp.com/blog/drupal/migrating-drupal-8-redirects/)
|
||||
|
||||
[How to refresh new migrations in Drupal 8 migration module?](https://drupal.stackexchange.com/questions/191435/how-to-refresh-new-migrations-in-drupal-8-migration-module)
|
||||
|
||||
[Drupal 8 Migrations: Taxonomy and Nodes](https://www.phase2technology.com/blog/drupal-8-migrations)
|
||||
|
||||
[Migrating Content Translated with "Content Translation" from Drupal 7 to Drupal 8](https://evolvingweb.ca/blog/migrating-content-translated-content-translation-drupal-7-drupal-8)
|
||||
|
|
|
@ -0,0 +1,104 @@
|
|||
<?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_company",
|
||||
* source_module = "taxonomy"
|
||||
* )
|
||||
*/
|
||||
class D7TaxonomyTermCompany extends FieldableEntity {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function query() {
|
||||
$query = $this->select('taxonomy_term_data', 'td')
|
||||
->fields('td')
|
||||
->distinct()
|
||||
->orderBy('tid');
|
||||
$query->leftJoin('taxonomy_vocabulary', 'tv', 'td.vid = tv.vid');
|
||||
$query->addField('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.'),
|
||||
'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) {
|
||||
print("\n".'-- prepareRow -- '.$row->getSourceProperty('tid')." -- ".$row->getSourceProperty('name')."\n");
|
||||
|
||||
// Get Field API field values.
|
||||
foreach (array_keys($this->getFields('taxonomy_term', $row->getSourceProperty('machine_name'))) as $field) {
|
||||
$tid = $row->getSourceProperty('tid');
|
||||
$row->setSourceProperty($field, $this->getFieldValues('taxonomy_term', $field, $tid));
|
||||
}
|
||||
|
||||
// Find parents for this row.
|
||||
$parents = $this->select('taxonomy_term_hierarchy', 'th')
|
||||
->fields('th', ['parent', 'tid'])
|
||||
->condition('tid', $row->getSourceProperty('tid'))
|
||||
->execute()
|
||||
->fetchCol();
|
||||
$row->setSourceProperty('parent', $parents);
|
||||
// print_r($parents);
|
||||
|
||||
// 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.
|
||||
// TODO: translations
|
||||
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']);
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: tode node company
|
||||
|
||||
return parent::prepareRow($row);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getIds() {
|
||||
$ids['tid']['type'] = 'integer';
|
||||
return $ids;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,102 @@
|
|||
<?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_showroom",
|
||||
* source_module = "taxonomy"
|
||||
* )
|
||||
*/
|
||||
class D7TaxonomyTermShowroom extends FieldableEntity {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function query() {
|
||||
$query = $this->select('taxonomy_term_data', 'td')
|
||||
->fields('td')
|
||||
->distinct()
|
||||
->orderBy('tid');
|
||||
$query->leftJoin('taxonomy_vocabulary', 'tv', 'td.vid = tv.vid');
|
||||
$query->addField('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.'),
|
||||
'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) {
|
||||
print("\n".'-- prepareRow -- '.$row->getSourceProperty('tid')." -- ".$row->getSourceProperty('name')."\n");
|
||||
|
||||
// Get Field API field values.
|
||||
foreach (array_keys($this->getFields('taxonomy_term', $row->getSourceProperty('machine_name'))) as $field) {
|
||||
$tid = $row->getSourceProperty('tid');
|
||||
$row->setSourceProperty($field, $this->getFieldValues('taxonomy_term', $field, $tid));
|
||||
}
|
||||
|
||||
// Find parents for this row.
|
||||
$parents = $this->select('taxonomy_term_hierarchy', 'th')
|
||||
->fields('th', ['parent', 'tid'])
|
||||
->condition('tid', $row->getSourceProperty('tid'))
|
||||
->execute()
|
||||
->fetchCol();
|
||||
$row->setSourceProperty('parent', $parents);
|
||||
// print_r($parents);
|
||||
|
||||
// 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.
|
||||
// TODO: translations
|
||||
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']);
|
||||
}
|
||||
}
|
||||
|
||||
return parent::prepareRow($row);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getIds() {
|
||||
$ids['tid']['type'] = 'integer';
|
||||
return $ids;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,112 @@
|
|||
<?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_tags",
|
||||
* source_module = "taxonomy"
|
||||
* )
|
||||
*/
|
||||
class D7TaxonomyTermTags extends FieldableEntity {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function query() {
|
||||
$query = $this->select('taxonomy_term_data', 'td')
|
||||
->fields('td')
|
||||
->distinct()
|
||||
->orderBy('tid');
|
||||
$query->leftJoin('taxonomy_vocabulary', 'tv', 'td.vid = tv.vid');
|
||||
$query->addField('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.'),
|
||||
'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."),
|
||||
'synonyms' => $this->t("Term's Synonyms (field : synonyms_synonym)"),
|
||||
];
|
||||
return $fields;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function prepareRow(Row $row) {
|
||||
print("\n\n".'-- prepareRow -- '.$row->getSourceProperty('tid')." -- ".$row->getSourceProperty('name')."\n");
|
||||
|
||||
// Get Field API field values.
|
||||
foreach (array_keys($this->getFields('taxonomy_term', $row->getSourceProperty('machine_name'))) as $field) {
|
||||
$tid = $row->getSourceProperty('tid');
|
||||
$row->setSourceProperty($field, $this->getFieldValues('taxonomy_term', $field, $tid));
|
||||
}
|
||||
|
||||
// Find parents for this row.
|
||||
$parents = $this->select('taxonomy_term_hierarchy', 'th')
|
||||
->fields('th', ['parent', 'tid'])
|
||||
->condition('tid', $row->getSourceProperty('tid'))
|
||||
->execute()
|
||||
->fetchCol();
|
||||
$row->setSourceProperty('parent', $parents);
|
||||
// print_r($parents);
|
||||
|
||||
// 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.
|
||||
// TODO: translations
|
||||
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')) {
|
||||
$synonyms = $row->getSourceProperty('synonyms_synonym');
|
||||
// print_r($synonyms);
|
||||
if(!empty($synonyms)){
|
||||
$row->setSourceProperty('synonyms', $synonyms);
|
||||
}
|
||||
}
|
||||
|
||||
return parent::prepareRow($row);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getIds() {
|
||||
$ids['tid']['type'] = 'integer';
|
||||
return $ids;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,149 @@
|
|||
<?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",
|
||||
* source_module = "taxonomy"
|
||||
* )
|
||||
*/
|
||||
class D7TaxonomyTermThesaurus extends FieldableEntity {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function query() {
|
||||
$query = $this->select('taxonomy_term_data', 'td')
|
||||
->fields('td')
|
||||
->distinct()
|
||||
->orderBy('tid');
|
||||
$query->leftJoin('taxonomy_vocabulary', 'tv', 'td.vid = tv.vid');
|
||||
$query->addField('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.'),
|
||||
'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."),
|
||||
'synonyms' => $this->t("Term's Synonyms (field : synonyms_synonym)"),
|
||||
'displayed_on_advanced_search' => $this->t("field_used_on_advanced_search"),
|
||||
];
|
||||
return $fields;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function prepareRow(Row $row) {
|
||||
print("\n\n".'-- prepareRow -- '.$row->getSourceProperty('tid')." -- ".$row->getSourceProperty('name')." -- ".$row->getSourceProperty('weight')."\n");
|
||||
|
||||
// Get Field API field values.
|
||||
// foreach (array_keys($this->getFields('taxonomy_term', $row->getSourceProperty('machine_name'))) as $field) {
|
||||
// $tid = $row->getSourceProperty('tid');
|
||||
// $row->setSourceProperty($field, $this->getFieldValues('taxonomy_term', $field, $tid));
|
||||
// print("field: ".$field."\n");
|
||||
// print_r($this->getFieldValues('taxonomy_term', $field, $tid));
|
||||
// print("-\n");
|
||||
// }
|
||||
|
||||
// Find parents for this row.
|
||||
$parents = $this->select('taxonomy_term_hierarchy', 'th')
|
||||
->fields('th', ['parent', 'tid'])
|
||||
->condition('tid', $row->getSourceProperty('tid'))
|
||||
->execute()
|
||||
->fetchCol();
|
||||
$row->setSourceProperty('parent', $parents);
|
||||
// print_r($parents);
|
||||
|
||||
// get the english term name as defaut
|
||||
$query = $this->select('entity_translation', 'et')
|
||||
// ->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')) {
|
||||
$synonyms = $row->getSourceProperty('synonyms_synonym');
|
||||
// print_r($synonyms);
|
||||
if(!empty($synonyms)){
|
||||
$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);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getIds() {
|
||||
$ids['tid']['type'] = 'integer';
|
||||
return $ids;
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue