From 3b58e3e1035cc17858daea25c96c9047b21b1c19 Mon Sep 17 00:00:00 2001 From: bach Date: Tue, 20 Apr 2021 21:06:45 +0200 Subject: [PATCH] popsu_migrate: D7TaxotermTypedoc ok --- ...us.migration.d7_taxonomy_term_type_doc.yml | 42 ++++++++ .../migrate/source/D7TaxotermTypeDoc.php | 95 +++++++++++++++++++ 2 files changed, 137 insertions(+) create mode 100644 web/modules/custom/popsu_migrate/config/install/migrate_plus.migration.d7_taxonomy_term_type_doc.yml create mode 100644 web/modules/custom/popsu_migrate/src/Plugin/migrate/source/D7TaxotermTypeDoc.php diff --git a/web/modules/custom/popsu_migrate/config/install/migrate_plus.migration.d7_taxonomy_term_type_doc.yml b/web/modules/custom/popsu_migrate/config/install/migrate_plus.migration.d7_taxonomy_term_type_doc.yml new file mode 100644 index 00000000..3a6a0f24 --- /dev/null +++ b/web/modules/custom/popsu_migrate/config/install/migrate_plus.migration.d7_taxonomy_term_type_doc.yml @@ -0,0 +1,42 @@ +id: d7_taxonomy_term_type_doc +label: Taxonomy terms Type de Document +migration_group: popsu +audit: true +migration_tags: + - Drupal 7 + - Content + - Popsu +deriver: Drupal\taxonomy\Plugin\migrate\D7TaxonomyTermDeriver + +source: + plugin: d7_taxoterm_typedoc + bundle: popsu_documents_type + +destination: + plugin: entity:taxonomy_term + +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: default_value + default_value: types_de_document + name: name + 'description/value': description + 'description/format': format + weight: weight + # Only attempt to stub real (non-zero) parents. + parent_id: + - + plugin: skip_on_empty + method: process + source: parent + - + plugin: migration_lookup + migration: d7_taxonomy_term_type_doc + parent: + plugin: default_value + default_value: 0 + source: '@parent_id' + changed: timestamp diff --git a/web/modules/custom/popsu_migrate/src/Plugin/migrate/source/D7TaxotermTypeDoc.php b/web/modules/custom/popsu_migrate/src/Plugin/migrate/source/D7TaxotermTypeDoc.php new file mode 100644 index 00000000..381ce7b3 --- /dev/null +++ b/web/modules/custom/popsu_migrate/src/Plugin/migrate/source/D7TaxotermTypeDoc.php @@ -0,0 +1,95 @@ +select('taxonomy_term_data', 'td') + ->fields('td') + ->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"), + 'revision_id' => $this->t('Revision ID'), + 'language' => $this->t('Term translation language'), + 'source' => $this->t('Term translation source language'), + ]; + return $fields; + } + + + /** + * {@inheritdoc} + */ + public function prepareRow(Row $row) { + $language = $row->getSourceProperty('language'); + // drush_print('-- '.$language."\t".$row->getSourceProperty('tid')."\t".$row->getSourceProperty('name')); + + $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) { + $row->setSourceProperty($field_name, $this->getFieldValues('taxonomy_term', $field_name, $tid, $revid, NULL)); + } + + // 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); + + return parent::prepareRow($row); + } + + /** + * {@inheritdoc} + */ + public function getIds() { + $ids['tid']['type'] = 'integer'; + return $ids; + } + +}