started migration edlp6 module: users and taxonomy terms are migrated

This commit is contained in:
Bachir Soussi Chiadmi
2017-11-22 13:30:49 +01:00
parent 38f62621b1
commit 3b5f075855
10 changed files with 365 additions and 0 deletions
@@ -0,0 +1,90 @@
id: edlp_d6_corpus
label: Edlp Drupal 6 corpus
migration_tags:
- Drupal 6
deriver: Drupal\node\Plugin\migrate\D6NodeDeriver
migration_group: edlp
source:
plugin: edlp_d6_corpus
node_type: corpus
process:
# In D6, nodes always have a tnid, but it's zero for untranslated nodes.
# We normalize it to equal the nid in that case.
# @see \Drupal\node\Plugin\migrate\source\d6\Node::prepareRow().
# If you are using this file to build a custom migration consider removing
# the nid and vid fields to allow incremental migrations.
# nid: tnid
# vid: vid
type:
plugin: default_value
default_value: enregistrement
langcode:
plugin: default_value
source: language
default_value: "und"
title: title
uid:
plugin: migration
migration: edlp_d6_users
source: uid
status: status
created: created
changed: changed
promote: promote
sticky: sticky
# 'body/format':
# plugin: migration_lookup
# migration: d6_filter_format
# source: format
'body/value': notes
# 'body/summary': teaser
revision_uid: revision_uid
revision_log: log
revision_timestamp: timestamp
#
# custom fields
# workflow
# text -> entity ref terms
# field_artiste: field_locuteur_s
# text -> entity ref terms
# field_compositeur: field_collectionneur_s
# taxo term -> entity ref terms
# field_entree_s:
# plugin: entity_generate
# source: Type
# entity_type: taxonomy_term
# bundle_key: vid
# bundle: entrees
# value_key: name
# field_genre: field_genre_s
# field_genre_s:
# plugin: entity_generate
# source: field_genre
# entity_type: taxonomy_term
# bundle_key: vid
# bundle: genres
# value_key: name
# taxo term -> entity ref terms
# field_langue: field_langue_s
# file
# field_mp3: field_fichier_son
# node ref -> text
# field_article: body
# unmapped d6 fields.
# tnid
# translate
# moderate
# comment
destination:
plugin: entity:node
migration_dependencies:
required:
- edlp_d6_users
- edlp_d6_entrees
@@ -0,0 +1,17 @@
id: edlp_d6_entrees
label: Edlp Drupal 6 entrees
migration_tags:
- Drupal 6
migration_group: edlp
source:
plugin: d6_taxonomy_term
bundle: 2
process:
name: name
description: description
vid:
plugin: default_value
default_value: entrees
destination:
plugin: entity:taxonomy_term
@@ -0,0 +1,17 @@
id: edlp_d6_genres
label: Edlp Drupal 6 genres
migration_tags:
- Drupal 6
migration_group: edlp
source:
plugin: d6_taxonomy_term
bundle: 3
process:
name: name
description: description
vid:
plugin: default_value
default_value: genres
destination:
plugin: entity:taxonomy_term
@@ -0,0 +1,17 @@
id: edlp_d6_langues
label: Edlp Drupal 6 langues
migration_tags:
- Drupal 6
migration_group: edlp
source:
plugin: d6_taxonomy_term
bundle: 4
process:
name: name
description: description
vid:
plugin: default_value
default_value: langues
destination:
plugin: entity:taxonomy_term
@@ -0,0 +1,48 @@
id: edlp_d6_users
label: Edlp Drupal 6 User accounts
migration_tags:
- Drupal 6
migration_group: edlp
source:
plugin: edlp_d6_users
process:
# If you are using this file to build a custom migration consider removing
# the uid field to allow incremental migrations.
# uid: uid
name: name
pass: pass
mail: mail
created: created
access: access
login: login
status: status
timezone:
plugin: user_update_7002
source: timezone
langcode:
plugin: user_langcode
source: language
fallback_to_site_default: false
preferred_langcode:
plugin: user_langcode
source: language
fallback_to_site_default: true
preferred_admin_langcode:
plugin: user_langcode
source: language
fallback_to_site_default: true
init: init
roles:
plugin: default_value
default_value: "collectionneur"
destination:
plugin: entity:user
md5_passwords: true
migration_dependencies:
# required:
# - d6_user_role
optional:
- language
- default_language
@@ -0,0 +1,8 @@
name: Edlp migration
type: module
description: Defines custom migration for edlp (from d6 to d8).
core: 8.x
package: Edlp
dependencies:
- migrate_drupal
- migrate_plus
@@ -0,0 +1,7 @@
id: edlp
label: Edlp
description: Drupal 6 edlp content migrated to Drupal 8.
source_type: Drupal 6.
shared_configuration:
source:
key: legacy
@@ -0,0 +1,11 @@
https://www.drupaleasy.com/blogs/ultimike/2016/04/drupal-6-drupal-81x-custom-content-migration
https://thinkshout.com/blog/2017/05/skipping-a-version-migrating-from-drupal-6-to-drupal-8-with-drupal-migrate/
https://www.drupal.org/docs/8/upgrade/known-issues-when-upgrading-from-drupal-6-or-7-to-drupal-8
https://drupal.stackexchange.com/questions/164612/how-do-i-remove-a-configuration-object-from-the-active-configuration
https://www.metaltoad.com/blog/drupal-8-migrations-part-3-migrating-taxonomies-drupal-7
https://www.sitepoint.com/your-first-drupal-8-migration/
@@ -0,0 +1,18 @@
<?php
namespace Drupal\edlp_migrate\Plugin\migrate\source;
use Drupal\migrate\Row;
use Drupal\node\Plugin\migrate\source\d6\Node as D6Node;
/**
* Source plugin for edlp corpus migration.
*
* @MigrateSource(
* id = "edlp_d6_corpus"
* )
*/
class EdlpD6Corpus extends D6Node {
}
@@ -0,0 +1,132 @@
<?php
namespace Drupal\edlp_migrate\Plugin\migrate\source;
use Drupal\migrate\Row;
use Drupal\user\Plugin\migrate\source\d6\User as D6User;
/**
* Source plugin for edlp user accounts.
*
* @MigrateSource(
* id = "edlp_d6_users"
* )
*/
class EdlpD6Users extends D6User {
/**
* {@inheritdoc}
*/
public function query() {
return $this->select('users', 'u')
->fields('u', array_keys($this->baseFields()))
->condition('u.uid', 0, '>');
}
/**
* {@inheritdoc}
*/
public function fields() {
$fields = $this->baseFields();
// Add roles field.
$fields['roles'] = $this->t('Roles');
// Profile fields.
if ($this->moduleExists('profile')) {
$fields += $this->select('profile_fields', 'pf')
->fields('pf', ['name', 'title'])
->execute()
->fetchAllKeyed();
}
return $fields;
}
/**
* {@inheritdoc}
*/
public function prepareRow(Row $row) {
// User roles.
$roles = $this->select('users_roles', 'ur')
->fields('ur', ['rid'])
->condition('ur.uid', $row->getSourceProperty('uid'))
->execute()
->fetchCol();
$row->setSourceProperty('roles', $roles);
// We are adding here the Event contributed module column.
// @see https://api.drupal.org/api/drupal/modules%21user%21user.install/function/user_update_7002/7
if ($row->hasSourceProperty('timezone_id') && $row->getSourceProperty('timezone_id')) {
if ($this->getDatabase()->schema()->tableExists('event_timezones')) {
$event_timezone = $this->select('event_timezones', 'e')
->fields('e', ['name'])
->condition('e.timezone', $row->getSourceProperty('timezone_id'))
->execute()
->fetchField();
if ($event_timezone) {
$row->setSourceProperty('event_timezone', $event_timezone);
}
}
}
// Unserialize Data.
$row->setSourceProperty('data', unserialize($row->getSourceProperty('data')));
return parent::prepareRow($row);
}
/**
* {@inheritdoc}
*/
public function getIds() {
return [
'uid' => [
'type' => 'integer',
'alias' => 'u',
],
];
}
/**
* Returns the user base fields to be migrated.
*
* @return array
* Associative array having field name as key and description as value.
*/
protected function baseFields() {
$fields = [
'uid' => $this->t('User ID'),
'name' => $this->t('Username'),
'pass' => $this->t('Password'),
'mail' => $this->t('Email address'),
'theme' => $this->t('Theme'),
'signature' => $this->t('Signature'),
'signature_format' => $this->t('Signature format'),
'created' => $this->t('Registered timestamp'),
'access' => $this->t('Last access timestamp'),
'login' => $this->t('Last login timestamp'),
'status' => $this->t('Status'),
'timezone' => $this->t('Timezone'),
'language' => $this->t('Language'),
'picture' => $this->t('Picture'),
'init' => $this->t('Init'),
'data' => $this->t('User data'),
];
// Possible field added by Date contributed module.
// @see https://api.drupal.org/api/drupal/modules%21user%21user.install/function/user_update_7002/7
if ($this->getDatabase()->schema()->fieldExists('users', 'timezone_name')) {
$fields['timezone_name'] = $this->t('Timezone (Date)');
}
// Possible field added by Event contributed module.
// @see https://api.drupal.org/api/drupal/modules%21user%21user.install/function/user_update_7002/7
if ($this->getDatabase()->schema()->fieldExists('users', 'timezone_id')) {
$fields['timezone_id'] = $this->t('Timezone (Event)');
}
return $fields;
}
}