migration breve, migration materiau:linked_breve; module pagerer, cshs, views_ef_fieldset
This commit is contained in:
@@ -0,0 +1,85 @@
|
||||
id: d7_node_breve
|
||||
label: Node Breve
|
||||
migration_group: d7_materio
|
||||
audit: true
|
||||
migration_tags:
|
||||
- Drupal 7
|
||||
- Content
|
||||
- Materio
|
||||
deriver: Drupal\taxonomy\Plugin\migrate\D7TaxonomyTermDeriver
|
||||
|
||||
source:
|
||||
plugin: d7_node_breve
|
||||
node_type: breve
|
||||
|
||||
destination:
|
||||
plugin: entity:node
|
||||
|
||||
|
||||
process:
|
||||
# nid: nid
|
||||
type:
|
||||
plugin: default_value
|
||||
default_value: breve
|
||||
title: title
|
||||
field_migration:
|
||||
plugin: default_value
|
||||
default_value: 'migration_imported'
|
||||
body:
|
||||
plugin: iterator
|
||||
source: field_description
|
||||
process:
|
||||
value: value
|
||||
format:
|
||||
plugin: default_value
|
||||
default_value: wysiwyg
|
||||
langcode: language
|
||||
field_memo: field_memo
|
||||
field_workflow:
|
||||
-
|
||||
plugin: default_value
|
||||
source: workflow
|
||||
default_value: 2
|
||||
-
|
||||
plugin: static_map
|
||||
default_value: 2
|
||||
map:
|
||||
1: "workflow_creation"
|
||||
2: "workflow_hidden"
|
||||
3: "workflow_visible"
|
||||
4: "workflow_imported"
|
||||
5: "workflow_edited"
|
||||
field_thesaurus:
|
||||
plugin: migration_lookup
|
||||
migration: d7_taxonomy_term_thesaurus
|
||||
source: field_onthologie
|
||||
field_tags:
|
||||
plugin: migration_lookup
|
||||
migration: d7_taxonomy_term_tags
|
||||
source: field_tags_libres
|
||||
field_video:
|
||||
plugin: iterator
|
||||
source: field_video_filter
|
||||
process:
|
||||
value: url
|
||||
field_linked_materials:
|
||||
-
|
||||
plugin: skip_on_empty
|
||||
method: process
|
||||
source: linked_materials
|
||||
-
|
||||
plugin: migration_lookup
|
||||
migration: d7_node_materiau
|
||||
no_stub: true
|
||||
|
||||
# field_visuel: field_visuel
|
||||
|
||||
|
||||
migration_dependencies:
|
||||
required:
|
||||
- d7_taxonomy_term_thesaurus
|
||||
- d7_taxonomy_term_tags
|
||||
- d7_taxonomy_term_company
|
||||
- d7_taxonomy_term_showroom
|
||||
optional:
|
||||
- d7_node_materiau
|
@@ -37,14 +37,19 @@ process:
|
||||
langcode: language
|
||||
field_memo: field_memo
|
||||
field_workflow:
|
||||
plugin: static_map
|
||||
source: workflow
|
||||
map:
|
||||
1: "workflow_creation"
|
||||
2: "workflow_hidden"
|
||||
3: "workflow_visible"
|
||||
4: "workflow_imported"
|
||||
5: "workflow_edited"
|
||||
-
|
||||
plugin: default_value
|
||||
source: workflow
|
||||
default_value: 2
|
||||
-
|
||||
plugin: static_map
|
||||
default_value: 2
|
||||
map:
|
||||
1: "workflow_creation"
|
||||
2: "workflow_hidden"
|
||||
3: "workflow_visible"
|
||||
4: "workflow_imported"
|
||||
5: "workflow_edited"
|
||||
|
||||
field_thesaurus:
|
||||
plugin: migration_lookup
|
||||
@@ -67,14 +72,32 @@ process:
|
||||
source: field_video_filter
|
||||
process:
|
||||
value: url
|
||||
field_linked_materials:
|
||||
-
|
||||
plugin: skip_on_empty
|
||||
method: process
|
||||
source: linked_materials
|
||||
-
|
||||
plugin: migration_lookup
|
||||
migration: d7_node_materiau
|
||||
no_stub: true
|
||||
field_linked_breves:
|
||||
-
|
||||
plugin: skip_on_empty
|
||||
method: process
|
||||
source: linked_breves
|
||||
-
|
||||
plugin: migration_lookup
|
||||
migration: d7_node_breve
|
||||
no_stub: true
|
||||
|
||||
# field_materiau_images: field_materiau_image
|
||||
# field_attachments: field_attachments
|
||||
# field_linked_materials: field_materiau_ref
|
||||
# field_linked_breves: field_breve_ref
|
||||
|
||||
# field_famille: field_famille
|
||||
# field_index: field_identifiant
|
||||
# field_reference: field_reference_materio
|
||||
|
||||
# just archives
|
||||
# : field_localisation
|
||||
# TODO: need to find an alternative or rebuild the custom module
|
||||
@@ -86,3 +109,5 @@ migration_dependencies:
|
||||
- d7_taxonomy_term_tags
|
||||
- d7_taxonomy_term_company
|
||||
- d7_taxonomy_term_showroom
|
||||
optional:
|
||||
- d7_node_breve
|
||||
|
@@ -0,0 +1,229 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\materio_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\EntityManagerInterface;
|
||||
use Drupal\Core\Extension\ModuleHandler;
|
||||
use Drupal\Core\State\StateInterface;
|
||||
use Drupal\migrate\Plugin\MigrationInterface;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
|
||||
/**
|
||||
* Drupal 7 node source from database.
|
||||
*
|
||||
* @MigrateSource(
|
||||
* id = "d7_node_breve",
|
||||
* source_module = "node"
|
||||
* )
|
||||
*/
|
||||
class D7NodeBreve extends FieldableEntity {
|
||||
/**
|
||||
* The module handler.
|
||||
*
|
||||
* @var \Drupal\Core\Extension\ModuleHandlerInterface
|
||||
*/
|
||||
protected $moduleHandler;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function __construct(array $configuration, $plugin_id, $plugin_definition, MigrationInterface $migration, StateInterface $state, EntityManagerInterface $entity_manager, ModuleHandlerInterface $module_handler) {
|
||||
parent::__construct($configuration, $plugin_id, $plugin_definition, $migration, $state, $entity_manager);
|
||||
$this->moduleHandler = $module_handler;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@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.manager'),
|
||||
$container->get('module_handler')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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',
|
||||
'language',
|
||||
'status',
|
||||
'created',
|
||||
'changed',
|
||||
'comment',
|
||||
'promote',
|
||||
'sticky',
|
||||
'tnid',
|
||||
'translate',
|
||||
])
|
||||
->fields('nr', [
|
||||
'vid',
|
||||
'title',
|
||||
'log',
|
||||
'timestamp',
|
||||
])
|
||||
->orderBy('nid');
|
||||
|
||||
$query->addField('n', 'uid', 'node_uid');
|
||||
$query->addField('nr', 'uid', 'revision_uid');
|
||||
$query->innerJoin('node', 'n', static::JOIN);
|
||||
|
||||
// If the content_translation module is enabled, get the source langcode
|
||||
// to fill the content_translation_source field.
|
||||
if ($this->moduleHandler->moduleExists('content_translation')) {
|
||||
$query->leftJoin('node', 'nt', 'n.tnid = nt.nid');
|
||||
$query->addField('nt', 'language', 'source_langcode');
|
||||
}
|
||||
$this->handleTranslations($query);
|
||||
|
||||
if (isset($this->configuration['node_type'])) {
|
||||
$query->condition('n.type', $this->configuration['node_type']);
|
||||
}
|
||||
|
||||
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_print('-- '.$nid."\t".$title);
|
||||
|
||||
// If this entity was translated using Entity Translation, we need to get
|
||||
// its source language to get the field values in the right language.
|
||||
// The translations will be migrated by the d7_node_entity_translation
|
||||
// migration.
|
||||
$entity_translatable = $this->isEntityTranslatable('node') && (int) $this->variableGet('language_content_type_' . $type, 0) === 4;
|
||||
$language = $entity_translatable ? $this->getEntityTranslationSourceLanguage('node', $nid) : $row->getSourceProperty('language');
|
||||
|
||||
// Get Field API field values.
|
||||
foreach ($this->getFields('node', $type) as $field_name => $field) {
|
||||
// Ensure we're using the right language if the entity and the field are
|
||||
// translatable.
|
||||
$field_language = $entity_translatable && $field['translatable'] ? $language : NULL;
|
||||
$row->setSourceProperty($field_name, $this->getFieldValues('node', $field_name, $nid, $vid, $field_language));
|
||||
}
|
||||
|
||||
// linked materials
|
||||
$linked_materials = [];
|
||||
if(!empty($row->getSourceProperty('field_materiau_ref'))){
|
||||
// print_r($row->getSourceProperty('field_materiau_ref'));
|
||||
foreach ($row->getSourceProperty('field_materiau_ref') as $key => $value) {
|
||||
$linked_materials[] = $value['target_id'];
|
||||
}
|
||||
// print_r($linked_materials);
|
||||
}
|
||||
$row->setSourceProperty('linked_materials', $linked_materials);
|
||||
|
||||
// Make sure we always have a translation set.
|
||||
if ($row->getSourceProperty('tnid') == 0) {
|
||||
$row->setSourceProperty('tnid', $row->getSourceProperty('nid'));
|
||||
}
|
||||
|
||||
// If the node title was replaced by a real field using the Drupal 7 Title
|
||||
// module, use the field value instead of the node title.
|
||||
if ($this->moduleExists('title')) {
|
||||
$title_field = $row->getSourceProperty('title_field');
|
||||
if (isset($title_field[0]['value'])) {
|
||||
$row->setSourceProperty('title', $title_field[0]['value']);
|
||||
}
|
||||
}
|
||||
|
||||
// workflow
|
||||
$query = $this->select('workflow_node', 'wn');
|
||||
$query->fields('wn', ['sid']);
|
||||
$query->condition('wn.nid', $nid);
|
||||
$results = $query->execute()->fetchField();
|
||||
if(!$results){
|
||||
$results = 2;
|
||||
// add bad workflow to memo field
|
||||
$memo .= "#migration : invalid workflow\n";
|
||||
drush_print('WARNING: no workflow');
|
||||
}
|
||||
$row->setSourceProperty('workflow', $results);
|
||||
|
||||
|
||||
// record migration errors in field_memo
|
||||
if(isset($memo)){
|
||||
$field_memo = $row->getSourceProperty('field_memo');
|
||||
$field_memo[0]['value'] .= "\n".$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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adapt our query for translations.
|
||||
*
|
||||
* @param \Drupal\Core\Database\Query\SelectInterface $query
|
||||
* The generated query.
|
||||
*/
|
||||
protected function handleTranslations(SelectInterface $query) {
|
||||
// Check whether or not we want translations.
|
||||
if (empty($this->configuration['translations'])) {
|
||||
// No translations: Yield untranslated nodes, or default translations.
|
||||
$query->where('n.tnid = 0 OR n.tnid = n.nid');
|
||||
}
|
||||
else {
|
||||
// Translations: Yield only non-default translations.
|
||||
$query->where('n.tnid <> 0 AND n.tnid <> n.nid');
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@@ -126,9 +126,27 @@ class D7NodeMateriau extends FieldableEntity {
|
||||
$field_language = $entity_translatable && $field['translatable'] ? $language : NULL;
|
||||
$row->setSourceProperty($field_name, $this->getFieldValues('node', $field_name, $nid, $vid, $field_language));
|
||||
}
|
||||
if(!empty($row->getSourceProperty('field_video_filter'))){
|
||||
print_r($row->getSourceProperty('field_video_filter'));
|
||||
|
||||
// linked materials
|
||||
$linked_materials = [];
|
||||
if(!empty($row->getSourceProperty('field_materiau_ref'))){
|
||||
// print_r($row->getSourceProperty('field_materiau_ref'));
|
||||
foreach ($row->getSourceProperty('field_materiau_ref') as $key => $value) {
|
||||
$linked_materials[] = $value['target_id'];
|
||||
}
|
||||
// print_r($linked_materials);
|
||||
}
|
||||
$row->setSourceProperty('linked_materials', $linked_materials);
|
||||
|
||||
//linked breves
|
||||
$linked_breves = [];
|
||||
if(!empty($row->getSourceProperty('field_breve_ref'))){
|
||||
foreach ($row->getSourceProperty('field_breve_ref') as $key => $value) {
|
||||
$linked_breves[] = $value['target_id'];
|
||||
}
|
||||
}
|
||||
$row->setSourceProperty('linked_breves', $linked_breves);
|
||||
|
||||
|
||||
// Make sure we always have a translation set.
|
||||
if ($row->getSourceProperty('tnid') == 0) {
|
||||
|
Reference in New Issue
Block a user