popsu_migrate: Created D7NodeProjet, D7NodeTheme themes et projets liés ok

This commit is contained in:
2021-04-19 14:09:42 +02:00
parent b178377b1d
commit 14b6df455a
14 changed files with 873 additions and 8 deletions

View File

@@ -0,0 +1,45 @@
id: d7_node_projet
label: Node Projet
migration_group: popsu
audit: true
migration_tags:
- Drupal 7
- Content
- Popsu
source:
plugin: d7_node_projet
batch_size: 500
high_water_property:
name: changed
alias: n
destination:
plugin: entity:node
process:
# nid: nid
type:
plugin: default_value
default_value: projet
created: created
changed: changed
uid:
plugin: default_value
default_value: 34
title: title
# field_programme:
# plugin: migration_lookup
# migration: d7_node_programme
# source: programme
# no_stub: true
migration_dependencies:
required:
- d7_allpublicfiles
- d7_users
- d7_taxonomy_term_type_theme

View File

@@ -56,8 +56,22 @@ process:
source: field_popsu_themtrans_type
no_stub: true
field_themes_lies:
plugin: sub_process
source: field_themes_lies
process:
target_id:
plugin: migration_lookup
migration:
- d7_node_projet
- d7_node_theme
source: nid
# stub_id is not working :(
stub_id: d7_node_projet
migration_dependencies:
required:
- d7_allpublicfiles
- d7_users
- d7_taxonomy_term_type_theme
- d7_node_projet

View File

@@ -0,0 +1,160 @@
<?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\popsu_migrate\Plugin\migrate\source\D7Programme;
/**
* Drupal 7 node source from database.
*
* @MigrateSource(
* id = "d7_node_projet",
* source_module = "node"
* )
*/
class D7NodeProjet 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('changed');
$query->addField('n', 'uid', 'node_uid');
$query->addField('nr', 'uid', 'revision_uid');
$query->innerJoin('node', 'n', static::JOIN);
$query->condition('n.type', ['popsu_ville', 'popsu_ville_europe', 'popsu_projet'], '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 . '- - - - ');
// 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;
// }
}
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;
}
}

View File

@@ -160,11 +160,32 @@ class D7NodeTheme extends FieldableEntity {
$row->setSourceProperty('programme', $prog[0]['nid']);
}
# Images
if ($field_images) {
// Drush::output()->writeln(dump($field_images));
$row->setSourceProperty('images', $field_images);
}
# Themes liés
// merge the two ppossible field source
$field_themes_lies = array();
if ($field_popsu_themloc_lies = $row->getSourceProperty('field_popsu_themloc_lies')) {
// Drush::output()->writeln(dump($field_popsu_themloc_lies));
foreach ($field_popsu_themloc_lies as $key => $value) {
$field_themes_lies[] = $value;
}
}
if ($field_popsu_themloc_comparatif = $row->getSourceProperty('field_popsu_themloc_comparatif')) {
// Drush::output()->writeln(dump($field_popsu_themloc_comparatif));
foreach ($field_popsu_themloc_comparatif as $key => $value) {
$field_themes_lies[] = $value;
}
}
if (!empty($field_themes_lies)) {
Drush::output()->writeln(dump($field_themes_lies));
$row->setSourceProperty('field_themes_lies', $field_themes_lies);
}
return parent::prepareRow($row);
}