popsu_migrate: D7NodeEvemenent title, programme ok
This commit is contained in:
@@ -0,0 +1,131 @@
|
||||
id: d7_node_evenement
|
||||
label: Node evenement
|
||||
migration_group: popsu
|
||||
audit: true
|
||||
migration_tags:
|
||||
- Drupal 7
|
||||
- Content
|
||||
- Popsu
|
||||
|
||||
source:
|
||||
plugin: d7_node_evenement
|
||||
batch_size: 500
|
||||
# high_water_property:
|
||||
# name: changed
|
||||
# alias: n
|
||||
|
||||
destination:
|
||||
plugin: entity:node
|
||||
|
||||
process:
|
||||
# nid: nid
|
||||
type:
|
||||
plugin: default_value
|
||||
default_value: evenement
|
||||
created: created
|
||||
changed: changed
|
||||
|
||||
uid:
|
||||
plugin: default_value
|
||||
default_value: 34
|
||||
|
||||
title: title
|
||||
|
||||
field_programme:
|
||||
plugin: sub_process
|
||||
source: field_programme
|
||||
process:
|
||||
target_id:
|
||||
plugin: migration_lookup
|
||||
migration: d7_node_programme
|
||||
source: nid
|
||||
no_stub: true
|
||||
|
||||
# field_theme:
|
||||
# plugin: migration_lookup
|
||||
# migration: d7_node_theme
|
||||
# source: field_theme
|
||||
# no_stub: true
|
||||
#
|
||||
# field_projet:
|
||||
# plugin: migration_lookup
|
||||
# migration: d7_node_projet
|
||||
# source: field_projet
|
||||
# no_stub: true
|
||||
#
|
||||
# field_poid: field_poids
|
||||
#
|
||||
# field_type_de_ressource:
|
||||
# plugin: migration_lookup
|
||||
# migration: d7_taxonomy_term_type_doc
|
||||
# source: field_popsu_doc_type
|
||||
# no_stub: true
|
||||
#
|
||||
# field_sous_titre:
|
||||
# plugin: sub_process
|
||||
# source: field_popsu_publication_soustitr
|
||||
# process:
|
||||
# value: value
|
||||
# # summary: summary
|
||||
# # format:
|
||||
# # plugin: default_value
|
||||
# # default_value: wysiwyg
|
||||
#
|
||||
# field_edition:
|
||||
# plugin: sub_process
|
||||
# source: field_popsu_doc_source
|
||||
# process:
|
||||
# value: value
|
||||
# summary: summary
|
||||
# format:
|
||||
# plugin: default_value
|
||||
# default_value: wysiwyg
|
||||
#
|
||||
# body:
|
||||
# plugin: sub_process
|
||||
# source: body
|
||||
# process:
|
||||
# value: value
|
||||
# summary: summary
|
||||
# format:
|
||||
# plugin: default_value
|
||||
# default_value: wysiwyg
|
||||
#
|
||||
#
|
||||
# field_image:
|
||||
# plugin: sub_process
|
||||
# source: field_popsu_publication_cover
|
||||
# process:
|
||||
# target_id:
|
||||
# plugin: migration_lookup
|
||||
# migration: d7_allpublicfiles
|
||||
# source: fid
|
||||
# no_stub: true
|
||||
# alt: alt
|
||||
# title: title
|
||||
#
|
||||
# field_fichier:
|
||||
# plugin: sub_process
|
||||
# source: field_popsu_doc_files
|
||||
# process:
|
||||
# target_id:
|
||||
# plugin: migration_lookup
|
||||
# migration: d7_allpublicfiles
|
||||
# source: fid
|
||||
# no_stub: true
|
||||
# display: display
|
||||
# description: description
|
||||
#
|
||||
# field_ressources_liees:
|
||||
# plugin: migration_lookup
|
||||
# migration: d7_node_ressource
|
||||
# source: field_projet
|
||||
# no_stub: true
|
||||
|
||||
field_memo: field_memo
|
||||
|
||||
migration_dependencies:
|
||||
required:
|
||||
- d7_allpublicfiles
|
||||
- d7_users
|
||||
- d7_taxonomy_term_type_theme
|
@@ -0,0 +1,254 @@
|
||||
<?php
|
||||
namespace Drupal\popsu_migrate\Plugin\migrate\source;
|
||||
|
||||
use Drupal\Core\Extension\ModuleHandlerInterface;
|
||||
use Drupal\migrate\Row;
|
||||
use Drupal\migrate_drupal\Plugin\migrate\source\d7\FieldableEntity;
|
||||
use Drupal\Core\Database\Query\SelectInterface;
|
||||
use Drupal\Core\Entity\EntityTypeManagerInterface;
|
||||
use Drupal\Core\Extension\ModuleHandler;
|
||||
use Drupal\Core\State\StateInterface;
|
||||
use Drupal\migrate\Plugin\MigrationInterface;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
use Drupal\Core\Logger\LoggerChannelFactoryInterface;
|
||||
use Drush\Drush;
|
||||
use Drupal\paragraphs\Entity\Paragraph;
|
||||
|
||||
// use Drupal\popsu_migrate\Plugin\migrate\source\D7Programme;
|
||||
|
||||
/**
|
||||
* Drupal 7 node source from database.
|
||||
*
|
||||
* @MigrateSource(
|
||||
* id = "d7_node_evenement",
|
||||
* source_module = "node"
|
||||
* )
|
||||
*/
|
||||
class D7NodeEvenement extends FieldableEntity {
|
||||
/**
|
||||
* The module handler.
|
||||
*
|
||||
* @var \Drupal\Core\Extension\ModuleHandlerInterface
|
||||
*/
|
||||
protected $moduleHandler;
|
||||
|
||||
/**
|
||||
* The logger channel.
|
||||
*
|
||||
* @var \Drupal\Core\Logger\LoggerChannelInterface
|
||||
*/
|
||||
protected $logger;
|
||||
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function __construct(array $configuration, $plugin_id, $plugin_definition, MigrationInterface $migration, StateInterface $state, EntityTypeManagerInterface $entity_manager, ModuleHandlerInterface $module_handler,LoggerChannelFactoryInterface $loggerFactory) {
|
||||
parent::__construct($configuration, $plugin_id, $plugin_definition, $migration, $state, $entity_manager);
|
||||
$this->moduleHandler = $module_handler;
|
||||
$this->logger = $loggerFactory->get('popsu_migration');
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition, MigrationInterface $migration = NULL) {
|
||||
return new static(
|
||||
$configuration,
|
||||
$plugin_id,
|
||||
$plugin_definition,
|
||||
$migration,
|
||||
$container->get('state'),
|
||||
$container->get('entity_type.manager'),
|
||||
$container->get('module_handler'),
|
||||
$container->get('logger.factory')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* The join options between the node and the node_revisions table.
|
||||
*/
|
||||
const JOIN = 'n.vid = nr.vid';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function query() {
|
||||
// Select node in its last revision.
|
||||
$query = $this->select('node_revision', 'nr')
|
||||
->fields('n', [
|
||||
'nid',
|
||||
'type',
|
||||
'uid',
|
||||
'language',
|
||||
'status',
|
||||
'created',
|
||||
'changed',
|
||||
])
|
||||
->fields('nr', [
|
||||
'vid',
|
||||
'title',
|
||||
'log',
|
||||
'timestamp',
|
||||
])
|
||||
->orderBy('type', 'ASC');
|
||||
|
||||
$query->addField('n', 'uid', 'node_uid');
|
||||
$query->addField('nr', 'uid', 'revision_uid');
|
||||
$query->innerJoin('node', 'n', static::JOIN);
|
||||
|
||||
$query->condition('n.type', ['evenement', 'popsu_colloque'], 'IN');
|
||||
|
||||
return $query;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function prepareRow(Row $row) {
|
||||
$nid = $row->getSourceProperty('nid');
|
||||
$vid = $row->getSourceProperty('vid');
|
||||
$type = $row->getSourceProperty('type');
|
||||
$title = $row->getSourceProperty('title');
|
||||
Drush::output()->writeln('- - - - ' . $title . ' ('.$nid.')'. ' ['.$type.']' . '- - - - ');
|
||||
|
||||
$memo = '';
|
||||
$memo .= "#migration : old nid = ".$nid."\n";
|
||||
$memo .= "#migration : old content type = ".$type."\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_publication_body':
|
||||
case 'field_popsu_doc_body':
|
||||
$row->setSourceProperty("body", $field_values);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if ($type === "popsu_colloque") {
|
||||
// programme
|
||||
$field_programme = $row->getSourceProperty('field_popsu_colloque_popsu');
|
||||
|
||||
} else { // evenement
|
||||
$field_popsu_doc_parent = $row->getSourceProperty('field_popsu_doc_parent');
|
||||
// get the node_type of doc_parent
|
||||
$node = $this->select('node', 'n')
|
||||
->fields('n', ['nid','vid','type'])
|
||||
->condition('n.nid', $field_popsu_doc_parent[0]['nid'])
|
||||
->execute()->fetchAll()[0];
|
||||
// foreach ($this->getFields('node', $node['type']) as $field_name => $field) {
|
||||
// $field_values = $this->getFieldValues('node', $field_name, $node['nid'], $node['vid'], NULL);
|
||||
// $node[$field_name] = $field_values;
|
||||
// }
|
||||
switch ($node['type']) {
|
||||
// programme
|
||||
case 'popsu_special': // NO ITEM
|
||||
case 'popsu_page': //NO ITEM
|
||||
Drush::output()->writeln(dump($node));
|
||||
break;
|
||||
// // projet
|
||||
// // case 'popsu_page_neutral': // no ref in migration
|
||||
// // case 'popsu_projet_europe': // merged with popsu_ville_europe
|
||||
// case 'popsu_ville_europe':
|
||||
// case 'popsu_ville':
|
||||
// case 'popsu_projet':
|
||||
// // Drush::output()->writeln(dump($node));
|
||||
// $node['target_id'] = $node['nid'];
|
||||
// $row->setSourceProperty('field_projet', $node);
|
||||
// break;
|
||||
// // Theme
|
||||
// case 'popsu_theme_europe':
|
||||
// case 'popsu_theme_trans':
|
||||
// case 'popsu_theme_local':
|
||||
// $node['target_id'] = $node['nid'];
|
||||
// $field_theme = $node;
|
||||
// break;
|
||||
// // publication
|
||||
// case 'popsu_publication':
|
||||
// $node['target_id'] = $node['nid'];
|
||||
// $row->setSourceProperty('field_ressources_liees', $node);
|
||||
// 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 (popsu)
|
||||
$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();
|
||||
|
||||
// Drush::output()->writeln(dump($prog));
|
||||
$row->setSourceProperty('field_programme', array(array('nid'=>$prog[0]['nid'])));
|
||||
}
|
||||
|
||||
if (!empty($field_theme)) {
|
||||
// Drush::output()->writeln(dump($field_theme));
|
||||
$row->setSourceProperty('field_theme', $field_theme);
|
||||
}
|
||||
|
||||
// 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);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function fields() {
|
||||
$fields = [
|
||||
'nid' => $this->t('Node ID'),
|
||||
'type' => $this->t('Type'),
|
||||
'title' => $this->t('Title'),
|
||||
'node_uid' => $this->t('Node authored by (uid)'),
|
||||
'revision_uid' => $this->t('Revision authored by (uid)'),
|
||||
'created' => $this->t('Created timestamp'),
|
||||
'changed' => $this->t('Modified timestamp'),
|
||||
'status' => $this->t('Published'),
|
||||
'promote' => $this->t('Promoted to front page'),
|
||||
'sticky' => $this->t('Sticky at top of lists'),
|
||||
'revision' => $this->t('Create new revision'),
|
||||
'language' => $this->t('Language (fr, en, ...)'),
|
||||
'tnid' => $this->t('The translation set id for this node'),
|
||||
'timestamp' => $this->t('The timestamp the latest revision of this node was created.'),
|
||||
];
|
||||
return $fields;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getIds() {
|
||||
$ids['nid']['type'] = 'integer';
|
||||
$ids['nid']['alias'] = 'n';
|
||||
return $ids;
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user