popsu_migrate: D7NodeActu ok
This commit is contained in:
@@ -0,0 +1,121 @@
|
||||
id: d7_node_actu
|
||||
label: Node actu
|
||||
migration_group: popsu
|
||||
audit: true
|
||||
migration_tags:
|
||||
- Drupal 7
|
||||
- Content
|
||||
- Popsu
|
||||
|
||||
source:
|
||||
plugin: d7_node_actu
|
||||
batch_size: 500
|
||||
# high_water_property:
|
||||
# name: changed
|
||||
# alias: n
|
||||
|
||||
destination:
|
||||
plugin: entity:node
|
||||
|
||||
process:
|
||||
# nid: nid
|
||||
type:
|
||||
plugin: default_value
|
||||
default_value: actualite
|
||||
created: created
|
||||
changed: changed
|
||||
|
||||
uid:
|
||||
plugin: default_value
|
||||
default_value: 34
|
||||
|
||||
title: title
|
||||
|
||||
field_sous_titre: field_popsu_actu_soustitre
|
||||
|
||||
promote:
|
||||
plugin: default_value
|
||||
default_value: 0
|
||||
source: field_popsu_actu_enhome
|
||||
|
||||
# https://understanddrupal.com/articles/migrating-dates-drupal
|
||||
# 'field_date/value':
|
||||
# plugin: format_date
|
||||
# source: field_popsu_actu_date
|
||||
# from_format: 'Y-m-j H:i:s'
|
||||
# to_format: 'Y-m-d\TH:i:s'
|
||||
# 'field_date/end_value':
|
||||
# plugin: format_date
|
||||
# source: field_popsu_actu_date_fin
|
||||
# from_format: 'Y-m-j H:i:s'
|
||||
# to_format: 'Y-m-d\TH:i:s'
|
||||
|
||||
field_dates_actu:
|
||||
-
|
||||
plugin: skip_on_empty
|
||||
method: process
|
||||
source: field_date
|
||||
-
|
||||
plugin: sub_process
|
||||
# source: field_date
|
||||
process:
|
||||
value:
|
||||
# format_date was not working, converting date to timestamp on prepare_row
|
||||
plugin: format_date
|
||||
from_format: 'Y-m-d H:i:s'
|
||||
to_format: 'Y-m-d\TH:i:s'
|
||||
# \TH:i:s
|
||||
source: value
|
||||
end_value:
|
||||
plugin: format_date
|
||||
from_format: 'Y-m-d H:i:s'
|
||||
to_format: 'Y-m-d\TH:i:s'
|
||||
source: end
|
||||
# duration: duration
|
||||
timezone:
|
||||
plugin: default_value
|
||||
default_value: ""
|
||||
# settings:
|
||||
# validate_format: false
|
||||
|
||||
body:
|
||||
plugin: sub_process
|
||||
source: field_popsu_actu_body
|
||||
process:
|
||||
value: value
|
||||
summary: summary
|
||||
format:
|
||||
plugin: default_value
|
||||
default_value: wysiwyg
|
||||
|
||||
field_fichier:
|
||||
plugin: sub_process
|
||||
source: field_popsu_actu_attachment
|
||||
process:
|
||||
target_id:
|
||||
plugin: migration_lookup
|
||||
migration: d7_allpublicfiles
|
||||
source: fid
|
||||
no_stub: true
|
||||
display: display
|
||||
description: description
|
||||
|
||||
field_image:
|
||||
plugin: sub_process
|
||||
source: field_popsu_actu_image
|
||||
process:
|
||||
target_id:
|
||||
plugin: migration_lookup
|
||||
migration: d7_allpublicfiles
|
||||
source: fid
|
||||
no_stub: true
|
||||
alt: alt
|
||||
title: title
|
||||
|
||||
|
||||
|
||||
field_memo: field_memo
|
||||
|
||||
migration_dependencies:
|
||||
required:
|
||||
- d7_allpublicfiles
|
@@ -107,5 +107,3 @@ process:
|
||||
migration_dependencies:
|
||||
required:
|
||||
- d7_allpublicfiles
|
||||
- d7_users
|
||||
- d7_taxonomy_term_type_theme
|
||||
|
@@ -0,0 +1,187 @@
|
||||
<?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_actu",
|
||||
* source_module = "node"
|
||||
* )
|
||||
*/
|
||||
class D7NodeActu 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', 'DESC');
|
||||
|
||||
$query->addField('n', 'uid', 'node_uid');
|
||||
$query->addField('nr', 'uid', 'revision_uid');
|
||||
$query->innerJoin('node', 'n', static::JOIN);
|
||||
|
||||
$query->condition('n.type', ['popsu_actu'], '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);
|
||||
}
|
||||
|
||||
$field_date = array();
|
||||
if ($date_start = $row->getSourceProperty('field_popsu_actu_date')) {
|
||||
// Drush::output()->writeln(dump($date_start));
|
||||
// $field_date['value'] = strtotime(substr($date_start[0]['value'], 0, 10));
|
||||
$field_date['value'] = $date_start[0]['value'];
|
||||
}
|
||||
if ($date_end = $row->getSourceProperty('field_popsu_actu_date_fin')) {
|
||||
// Drush::output()->writeln(dump($date_end));
|
||||
$field_date['end'] = $date_end[0]['value'];
|
||||
}
|
||||
if (!empty($field_date)) {
|
||||
// $field_date['duration'] = $field_date['end'] - $field_date['value'];
|
||||
// Drush::output()->writeln(dump($field_date));
|
||||
$row->setSourceProperty('field_date', array($field_date));
|
||||
}
|
||||
|
||||
|
||||
// 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