migration materiau: title, short-description, body, workflow, memo, migration; admin content nodes

This commit is contained in:
Bachir Soussi Chiadmi 2018-12-11 16:58:49 +01:00
parent 89fcefa951
commit 8ac49ad737
15 changed files with 1433 additions and 13 deletions

View File

@ -0,0 +1,71 @@
id: d7_node_materiau
label: Node Materiau
migration_group: d7_materio
audit: true
migration_tags:
- Drupal 7
- Content
- Materio
deriver: Drupal\taxonomy\Plugin\migrate\D7TaxonomyTermDeriver
source:
plugin: d7_node_materiau
node_type: materiau
destination:
plugin: entity:node
process:
# nid: nid
type:
plugin: default_value
default_value: materiau
title: title
field_short_description: field_nature_titre
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: static_map
source: workflow
map:
1: "workflow_creation"
2: "workflow_hidden"
3: "workflow_visible"
4: "workflow_imported"
5: "workflow_edited"
# field_thesaurus: field_onthologie
# field_tags: field_tags_libres
# field_materiau_images: field_materiau_image
# field_video: field_video_filter
# field_manufacturer: field_company_fab
# field_distributor: field_company_distrib
# 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
# : field_location
migration_dependencies:
required:
- d7_taxonomy_term_thesaurus
- d7_taxonomy_term_tags
- d7_taxonomy_term_company
- d7_taxonomy_term_showroom

View File

@ -0,0 +1,220 @@
<?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_materiau",
* source_module = "node"
* )
*/
class D7NodeMateriau 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');
drush_print('-- '.$language."\t".$nid);
// 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));
}
// 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');
}
}
}

View File

@ -0,0 +1,55 @@
uuid: f113a2b3-4712-484a-94d9-e755aa11b066
langcode: en
status: true
dependencies: { }
_core:
default_config_hash: yKRLVNGN4qBohpANHHYbIJR7GZba5K4Ojq0NJBWJkTM
id: d7_node_materiau
class: null
field_plugin_method: null
cck_plugin_method: null
migration_tags:
- 'Drupal 7'
- Content
- Materio
migration_group: d7_materio
label: 'Node Materiau'
source:
plugin: d7_node_materiau
node_type: materiau
process:
type:
plugin: default_value
default_value: materiau
title: title
field_short_description: field_nature_titre
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: static_map
source: workflow
map:
1: workflow_creation
2: workflow_hidden
3: workflow_visible
4: workflow_imported
5: workflow_edited
destination:
plugin: 'entity:node'
migration_dependencies:
required:
- d7_taxonomy_term_thesaurus
- d7_taxonomy_term_tags
- d7_taxonomy_term_company
- d7_taxonomy_term_showroom

View File

@ -1,4 +1,4 @@
uuid: 4c8a0fc1-0787-4f77-97b2-f346c79a94db uuid: a69469c2-0d5a-432c-b906-223054de2196
langcode: en langcode: en
status: true status: true
dependencies: { } dependencies: { }

View File

@ -1,4 +1,4 @@
uuid: d6b557c9-4571-474e-8dbe-29c8a4633893 uuid: 22243933-2e32-4739-8760-638eff3f9901
langcode: en langcode: en
status: true status: true
dependencies: { } dependencies: { }

View File

@ -1,4 +1,4 @@
uuid: ee3c366d-33d3-4a01-9762-f7009e7ca383 uuid: 86690803-46fe-456c-ad89-cf0cc53c0158
langcode: en langcode: en
status: true status: true
dependencies: { } dependencies: { }

View File

@ -1,4 +1,4 @@
uuid: c1ae337a-6919-47bd-9fd7-ad062e5a6669 uuid: 10660226-a750-44f8-8f51-faddf13e44b0
langcode: en langcode: en
status: true status: true
dependencies: { } dependencies: { }

View File

@ -1,4 +1,4 @@
uuid: 111d2fff-d284-497c-8ef6-56a08b5ed4d5 uuid: e3c72c0b-c97c-4f47-984a-a04ef7a51a9b
langcode: en langcode: en
status: true status: true
dependencies: { } dependencies: { }

View File

@ -1,4 +1,4 @@
uuid: 1db4c3ff-2004-4d45-baff-ef3238071b75 uuid: 17e19467-985f-45e4-8e68-79a323cc8908
langcode: en langcode: en
status: true status: true
dependencies: { } dependencies: { }

View File

@ -1,4 +1,4 @@
uuid: 771b5dfa-c03a-4ec2-9fd1-affbbd53117d uuid: 2376dc54-4fa9-4570-9baf-a9d9b4446a74
langcode: en langcode: en
status: true status: true
dependencies: dependencies:

File diff suppressed because it is too large Load Diff

View File

@ -11,8 +11,8 @@ module: workflow
from_sid: workflow_creation from_sid: workflow_creation
to_sid: workflow_edited to_sid: workflow_edited
roles: roles:
workflow_author: '0' workflow_author: workflow_author
anonymous: '0' anonymous: anonymous
authenticated: '0' authenticated: '0'
admin: '0' admin: '0'
root: '0' root: '0'

View File

@ -12,8 +12,8 @@ from_sid: workflow_creation
to_sid: workflow_hidden to_sid: workflow_hidden
roles: roles:
workflow_author: workflow_author workflow_author: workflow_author
anonymous: anonymous
admin: admin admin: admin
root: root root: root
anonymous: '0'
authenticated: '0' authenticated: '0'
user: '0' user: '0'

View File

@ -11,8 +11,8 @@ module: workflow
from_sid: workflow_creation from_sid: workflow_creation
to_sid: workflow_imported to_sid: workflow_imported
roles: roles:
workflow_author: '0' workflow_author: workflow_author
anonymous: '0' anonymous: anonymous
authenticated: '0' authenticated: '0'
admin: '0' admin: '0'
root: '0' root: '0'

View File

@ -12,8 +12,8 @@ from_sid: workflow_creation
to_sid: workflow_visible to_sid: workflow_visible
roles: roles:
workflow_author: workflow_author workflow_author: workflow_author
anonymous: anonymous
admin: admin admin: admin
root: root root: root
anonymous: '0'
authenticated: '0' authenticated: '0'
user: '0' user: '0'