popsu_migrate: D7TaxoTermVille ok, D7NodeProjet links, ville, programme ok, memo

This commit is contained in:
2021-04-19 22:59:33 +02:00
parent 2432b388c1
commit 2d890bae99
19 changed files with 1393 additions and 25 deletions

View File

@@ -10,9 +10,9 @@ migration_tags:
source:
plugin: d7_node_projet
batch_size: 500
high_water_property:
name: changed
alias: n
# high_water_property:
# name: changed
# alias: n
destination:
plugin: entity:node
@@ -31,11 +31,51 @@ process:
title: title
# field_programme:
# plugin: migration_lookup
# migration: d7_node_programme
# source: programme
# no_stub: true
field_ville:
plugin: migration_lookup
migration: d7_taxonomy_term_ville
source: ville
no_stub: true
field_programme:
plugin: sub_process
source: field_programme
process:
target_id:
plugin: migration_lookup
migration: d7_node_programme
source: nid
no_stub: true
field_comparatifs_associes:
plugin: sub_process
source: field_comparatifs_associes
process:
target_id:
plugin: migration_lookup
migration: d7_node_theme
source: nid
field_themes_lies:
plugin: sub_process
source: field_themes_lies
process:
target_id:
plugin: migration_lookup
migration: d7_node_theme
source: nid
field_projets_lies:
plugin: sub_process
source: field_projets_lies
process:
target_id:
plugin: migration_lookup
migration: d7_node_projet
source: nid
field_memo: field_memo
migration_dependencies:

View File

@@ -0,0 +1,29 @@
id: d7_taxonomy_term_ville
label: Taxonomy terms Villes
migration_group: popsu
audit: true
migration_tags:
- Drupal 7
- Content
- Popsu
deriver: Drupal\taxonomy\Plugin\migrate\D7TaxonomyTermDeriver
source:
plugin: d7_taxoterm_ville
bundle: popsu_villes
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: villes
name: name
'description/value': description
'description/format': format
weight: weight
changed: timestamp

View File

@@ -109,17 +109,146 @@ class D7NodeProjet extends FieldableEntity {
$vid = $row->getSourceProperty('vid');
$type = $row->getSourceProperty('type');
$title = $row->getSourceProperty('title');
Drush::output()->writeln('- - - - ' . $title . '- - - - ');
Drush::output()->writeln('- - - - ' . $title . ' ('.$nid.')' . '- - - - ');
$memo = '';
$memo .= "#migration : old nid = ".$nid."\n";
// Get Field API field values.
foreach ($this->getFields('node', $type) as $field_name => $field) {
$field_values = $this->getFieldValues('node', $field_name, $nid, $vid, NULL);
$row->setSourceProperty($field_name, $field_values);
// switch ($field_name) {
// case 'field_popsu_themloc_popsu':
// $field_programme = $field_values;
// break;
// }
switch ($field_name) {
// ville
case 'field_popsu_ville_ville':
$ville = $field_values;
break;
case 'field_popsu_villeur_ville':
$ville = $field_values;
break;
case 'field_popsu_projet_ville':
$ville = $field_values;
break;
// programme
case 'field_popsu_ville_popsu':
$field_programme = $field_values;
break;
case 'field_popsu_villeur_popsu':
$field_programme = $field_values;
break;
case 'field_popsu_projet_popsu':
$field_programme = $field_values;
break;
}
}
if ($field_programme) {
// Drush::output()->writeln(dump($field_programme));
$tid = $field_programme[0]['tid'];
// get the node (popsu_special) from the tid for migration_lookup
$query = $this->select('node_revision', 'nr')
->fields('n', ['nid','type'])
->fields('nr', ['vid'])
->orderBy('changed');
$query->innerJoin('node', 'n', static::JOIN);
$query->condition('n.type', 'popsu_special');
// field_popsu_special_typetaxo
// filter to get the right special type (colloques, publication, etc)
$query->leftJoin('field_revision_field_popsu_special_typetaxo', 'ff', 'ff.revision_id = n.vid');
$query->fields('ff', ['field_popsu_special_typetaxo_tid']);
$query->condition('ff.field_popsu_special_typetaxo_tid', 31);
// field_popsu_special_popsu
// filter to get right popsu (popsu 1, popsu europe, etc)
$query->leftJoin('field_revision_field_popsu_special_popsu', 'sp', 'sp.revision_id = n.vid');
$query->fields('sp', ['field_popsu_special_popsu_tid']);
$query->condition('sp.field_popsu_special_popsu_tid', $tid);
$prog = $query->execute()->fetchAll();
$row->setSourceProperty('field_programme', array(array('nid'=>$prog[0]['nid'])));
} else {
Drush::output()->writeln('NO PROGRAMME');
$memo .= "#migration : NO PROGRAMME\n";
}
if ($field_popsu_projet_comparatif = $row->getSourceProperty('field_popsu_projet_comparatif')) {
// Drush::output()->writeln(dump($field_comparatifs_associes));
$row->setSourceProperty('field_comparatifs_associes', $field_popsu_projet_comparatif);
}
$field_themes_lies = array();
$field_projets_lies = array();
if ($field_popsu_projet_lies = $row->getSourceProperty('field_popsu_projet_lies')) {
// Drush::output()->writeln(dump($field_popsu_projet_lies));
foreach ($field_popsu_projet_lies as $key => $value) {
// check if theme
$q = $this->select('node', 'n')
->fields('n', ['nid','type'])
->condition('n.nid', $value['nid'])
->condition('n.type', ['popsu_theme_local', 'popsu_projet'], 'IN');
$res = $q->execute()->fetchAll();
if (!empty($res)) {
// Drush::output()->writeln(dump($res));
switch ($res[0]['type']) {
case 'popsu_theme_local':
$field_themes_lies[] = $value;
break;
case 'popsu_projet':
$field_projets_lies[] = $value;
break;
}
}
}
}
if (!empty($field_projets_lies)) {
// Drush::output()->writeln(dump($field_themes_lies));
$row->setSourceProperty('field_projets_lies', $field_projets_lies);
}
// get the popsu_projet_europe nodes for popsu_ville_europe
// we need themes and imags
if ($type === 'popsu_ville_europe') {
$query = $this->select('node_revision', 'nr')
->fields('n', ['nid','type'])
->fields('nr', ['vid'])
->orderBy('changed');
$query->innerJoin('node', 'n', static::JOIN);
$query->condition('n.type', 'popsu_projet_europe');
// field_popsu_projeteur_ville
// filter to get the right node
$query->leftJoin('field_data_field_popsu_projeteur_ville', 'v', 'v.revision_id = n.vid');
$query->fields('v', ['field_popsu_projeteur_ville_tid']);
$query->condition('v.field_popsu_projeteur_ville_tid', $ville[0]['tid']);
$popsu_projet_europe = $query->execute()->fetchAll();
foreach ($popsu_projet_europe as $key => $value) {
// Get Field API field values.
foreach ($this->getFields('node', 'popsu_projet_europe') as $field_name => $field) {
$popsu_projet_europe[$key][$field_name] = $this->getFieldValues('node', $field_name, $value['nid'], $value['vid'], NULL);
}
// get the themes
if (!empty($popsu_projet_europe[$key]['field_popsu_projeteur_theme'])) {
foreach ($popsu_projet_europe[$key]['field_popsu_projeteur_theme'] as $theme) {
$field_themes_lies[] = $theme;
}
}
// TODO: get the images
}
// Drush::output()->writeln(dump($popsu_projet_europe));
}
if (!empty($field_themes_lies)) {
// Drush::output()->writeln(dump($field_themes_lies));
$row->setSourceProperty('field_themes_lies', $field_themes_lies);
}
// record migration errors in field_memo
if(isset($memo)){
$field_memo = array(
array(
'value' => $memo
)
);
$row->setSourceProperty('field_memo', $field_memo);
}
return parent::prepareRow($row);

View File

@@ -0,0 +1,87 @@
<?php
namespace Drupal\popsu_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_taxoterm_ville",
* source_module = "taxonomy"
* )
*/
class D7TaxotermVille extends FieldableEntity {
/**
* {@inheritdoc}
*/
public function query() {
$query = $this->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));
}
return parent::prepareRow($row);
}
/**
* {@inheritdoc}
*/
public function getIds() {
$ids['tid']['type'] = 'integer';
return $ids;
}
}