created plugins for migration
thesaurus is importing well for default language (en)
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user