fixe user company bug

This commit is contained in:
Bachir Soussi Chiadmi 2019-04-12 01:06:54 +02:00
parent f9b8effe96
commit d86a4a061a
21 changed files with 207 additions and 54 deletions

View File

@ -1,4 +1,4 @@
uuid: 0760f01a-10ad-4876-8b7c-fc365bb7d604
uuid: 79ab8656-5caa-4963-8a96-b8e99a95734b
langcode: en
status: true
dependencies: { }

View File

@ -1,4 +1,4 @@
uuid: 5e293a2e-4f35-4d00-9c37-d7e10a818d52
uuid: 6699fa94-779c-4ec6-80e7-529a15e8a649
langcode: en
status: true
dependencies: { }

View File

@ -1,4 +1,4 @@
uuid: 04726237-a1a9-4829-a854-a545cded4647
uuid: 2ff8e8e0-ca3d-47d6-875f-f8de1e735f19
langcode: en
status: true
dependencies: { }

View File

@ -1,4 +1,4 @@
uuid: bb67ccda-12a5-4ae9-806f-1f5b61094fc4
uuid: fe4c9750-5837-4072-9c3f-7462e8edd77c
langcode: en
status: true
dependencies: { }

View File

@ -1,4 +1,4 @@
uuid: 7db5c1c8-0479-40a9-a581-dbf82068fb08
uuid: 1cc85278-4253-4ee4-abe9-bdbfdbcd4fd1
langcode: en
status: true
dependencies: { }

View File

@ -1,4 +1,4 @@
uuid: 26d4512d-f71d-4df2-8785-b0c339cbfd13
uuid: d871f284-27e4-4ace-977b-d036fbc3519c
langcode: en
status: true
dependencies: { }

View File

@ -1,4 +1,4 @@
uuid: 15c8fbd5-0cfd-4209-8514-d95334c3ed60
uuid: 1700dfa0-73b4-44a1-a62d-a93055ba700d
langcode: en
status: true
dependencies: { }

View File

@ -1,9 +1,9 @@
uuid: 9fd16d6a-6740-47f9-9f3a-dd63cd8aa468
uuid: 8465fcbe-2003-4af4-ac5b-906f1b85dda7
langcode: en
status: true
dependencies: { }
_core:
default_config_hash: Y7surKNH2d9UWee4zzr6yzSyfIruwBMTs1xSoL_ShG4
default_config_hash: KD8aokrh9C4c7Cnr91IkjxeMimTrOAqjLSWjRACToJ8
id: d7_taxonomy_term_company
class: null
field_plugin_method: null
@ -30,7 +30,7 @@ process:
source: parent
-
plugin: migration_lookup
migration: d7_taxonomy_term_companie
migration: d7_taxonomy_term_company
parent:
plugin: default_value
default_value: 0

View File

@ -1,4 +1,4 @@
uuid: 6e9d0176-5410-4dcd-b620-875eab1348c8
uuid: 82fb4ac1-4ba1-4fe4-9910-1dcb12eae60c
langcode: en
status: true
dependencies: { }

View File

@ -1,4 +1,4 @@
uuid: 8d668861-4599-44b9-b17b-c35120a4d23a
uuid: a314593d-a9b5-4a75-95cf-da2a0b972b72
langcode: en
status: true
dependencies: { }

View File

@ -1,4 +1,4 @@
uuid: 4156ec2e-7374-4270-aea3-40c14ee20790
uuid: 69374e74-992d-4754-a950-8797b63a590d
langcode: en
status: true
dependencies: { }

View File

@ -1,4 +1,4 @@
uuid: 9b453f7f-4fc4-4826-bac6-6f49b734425e
uuid: 44d6af6e-b0be-49e6-8833-351d39efcc9b
langcode: en
status: true
dependencies: { }

View File

@ -1,4 +1,4 @@
uuid: 74f03ea2-db39-4cb2-87e1-e65fa24040dd
uuid: 9180eced-8d25-44f9-8c93-b8c6b00e656e
langcode: en
status: true
dependencies: { }

View File

@ -1,4 +1,4 @@
uuid: f3576dd2-cf66-4cfc-b41e-45d4855ac987
uuid: 2612da83-201b-49c2-aa68-a0503029ab47
langcode: en
status: true
dependencies:

View File

@ -1,4 +1,4 @@
uuid: a76e06da-26f4-44b5-90d8-22a080c05bef
uuid: 71aada73-563b-44cd-b369-249fe043905e
langcode: en
status: true
dependencies:

View File

@ -1,11 +1,11 @@
uuid: ec3736c2-9d18-46ee-bda0-e0b1f350b69e
uuid: 0e8915f4-3471-4dbf-8d6a-767622125b26
langcode: en
status: true
dependencies: { }
_core:
default_config_hash: A9EdRJlr8o5qMY-JbJU_n7Cv0Java4lZouu__eONDWM
default_config_hash: MSrCVV09c4n2q36chsUNrsaE87aqSrk3FfoG7QBzuxg
id: d7_users
class: Drupal\user\Plugin\migrate\User
class: null
field_plugin_method: null
cck_plugin_method: null
migration_tags:
@ -15,7 +15,7 @@ migration_tags:
migration_group: d7_materio
label: 'User accounts'
source:
plugin: d7_user
plugin: d7_users
process:
name: name
pass: pass
@ -68,21 +68,15 @@ process:
11: alpha_testeur
12: translator
13: admin_showroom
user_picture:
-
plugin: default_value
source: picture
default_value: null
-
plugin: migration_lookup
migration: d7_file
field_company:
plugin: migration_lookup
migration: d7_taxonomy_term_company
source: field_company
no_stub: true
field_showroom:
plugin: migration_lookup
migration: d7_taxonomy_term_showroom
no_stub: true
source: field_showroom
field_memo: field_memo
destination:
@ -90,3 +84,5 @@ destination:
migration_dependencies:
required:
- d7_allpublicfiles
- d7_taxonomy_term_showroom
- d7_taxonomy_term_company

View File

@ -1,5 +1,5 @@
uuid: 400201fd-9145-4ea2-bace-9325c7ef59f5
langcode: fr
uuid: 75218419-b6ef-4f16-9ea9-bc7a04727826
langcode: en
status: true
dependencies:
enforced:

View File

@ -39,7 +39,7 @@ sleep 5
echo " "
echo "Migrating Users"
drush mim d7_users --feedback="1000"
drush mim d7_users --update --feedback="1000"
echo " "
drush mim d7_user_profile --feedback="1000"
echo " "

View File

@ -32,7 +32,7 @@ process:
source: parent
-
plugin: migration_lookup
migration: d7_taxonomy_term_companie
migration: d7_taxonomy_term_company
parent:
plugin: default_value
default_value: 0

View File

@ -6,19 +6,14 @@ migration_tags:
- Drupal 7
- Content
- Materio
class: Drupal\user\Plugin\migrate\User
source:
plugin: d7_user
plugin: d7_users
destination:
plugin: entity:user
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:
@ -53,10 +48,6 @@ process:
source: language
fallback_to_site_default: true
init: init
# roles:
# plugin: migration_lookup
# migration: d7_user_role
# source: roles
roles:
plugin: static_map
source: roles
@ -76,29 +67,43 @@ process:
12: "translator"
13: "admin_showroom"
user_picture:
-
plugin: default_value
source: picture
default_value: null
-
plugin: migration_lookup
migration: d7_file
# TODO : a vérifier
# jai fait un test de recherche sur ce tableau user (recherche par email "@materio.com"), les réponses sont pour linstant aberrantes (kevin travaille par exemple chez Onip Peinture)
field_company:
plugin: migration_lookup
migration: d7_taxonomy_term_company
source: field_company
no_stub: true
# field_company:
# -
# plugin: sub_process
# source: field_company
# process:
# target_id:
# plugin: migration_lookup
# migration: d7_taxonomy_term_company
# source: tid
# no_stub: true
# field_company:
# plugin: default_value
# default_value: 2673
field_showroom:
plugin: migration_lookup
migration: d7_taxonomy_term_showroom
no_stub: true
source: field_showroom
field_memo: field_memo
# user_picture:
# -
# plugin: default_value
# source: picture
# default_value: null
# -
# plugin: migration_lookup
# migration: d7_file
# no_stub: true
migration_dependencies:
required:
- d7_allpublicfiles

View File

@ -0,0 +1,152 @@
<?php
namespace Drupal\materio_migrate\Plugin\migrate\source;
use Drupal\migrate\Row;
use Drupal\migrate_drupal\Plugin\migrate\source\d7\FieldableEntity;
/**
* Drupal 7 user source from database.
*
* @MigrateSource(
* id = "d7_users",
* source_module = "user"
* )
*/
class D7Users extends FieldableEntity {
/**
* {@inheritdoc}
*/
public function query() {
return $this->select('users', 'u')
->fields('u')
->condition('u.uid', 0, '>');
}
/**
* {@inheritdoc}
*/
public function fields() {
$fields = [
'uid' => $this->t('User ID'),
'name' => $this->t('Username'),
'pass' => $this->t('Password'),
'mail' => $this->t('Email address'),
'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'),
'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) {
$uid = $row->getSourceProperty('uid');
$roles = $this->select('users_roles', 'ur')
->fields('ur', ['rid'])
->condition('ur.uid', $uid)
->execute()
->fetchCol();
$row->setSourceProperty('roles', $roles);
$row->setSourceProperty('data', unserialize($row->getSourceProperty('data')));
// 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_user_entity_translation
// migration.
$entity_translatable = $this->isEntityTranslatable('user');
$source_language = $this->getEntityTranslationSourceLanguage('user', $uid);
$language = $entity_translatable && $source_language ? $source_language : $row->getSourceProperty('language');
$row->setSourceProperty('entity_language', $language);
// Get Field API field values.
foreach ($this->getFields('user') 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;
$field_values = $this->getFieldValues('user', $field_name, $uid, NULL, $field_language);
// $field_values = [];
// if ($field_name === 'field_company') {
// // print($uid . " ---\n");
// // print_r($tmp_field_values);
// // fix the taxo tid as tode module replace it by node nid
// // get the real tode tid
// foreach ($tmp_field_values as $key => $value) {
// $tode_tid = $this->select('field_data_field_tode_company', 'tode')
// ->condition('entity_type', 'node')
// ->condition('entity_id', $value['tid'])
// ->fields('tode', ['field_tode_company_tid'])
// ->execute()->fetchField();
// $field_values[] = array('tid'=>$tode_tid);
// }
// // print_r($field_values);
// $row->setSourceProperty('companies', $field_values);
// }
$row->setSourceProperty($field_name, $field_values);
}
// Get profile field values. This code is lifted directly from the D6
// ProfileFieldValues plugin.
if ($this->getDatabase()->schema()->tableExists('profile_value')) {
$query = $this->select('profile_value', 'pv')
->fields('pv', ['fid', 'value']);
$query->leftJoin('profile_field', 'pf', 'pf.fid=pv.fid');
$query->fields('pf', ['name', 'type']);
$query->condition('uid', $row->getSourceProperty('uid'));
$results = $query->execute();
foreach ($results as $profile_value) {
if ($profile_value['type'] == 'date') {
$date = unserialize($profile_value['value']);
$date = date('Y-m-d', mktime(0, 0, 0, $date['month'], $date['day'], $date['year']));
$row->setSourceProperty($profile_value['name'], ['value' => $date]);
}
elseif ($profile_value['type'] == 'list') {
// Explode by newline and comma.
$row->setSourceProperty($profile_value['name'], preg_split("/[\r\n,]+/", $profile_value['value']));
}
else {
$row->setSourceProperty($profile_value['name'], [$profile_value['value']]);
}
}
}
return parent::prepareRow($row);
}
/**
* {@inheritdoc}
*/
public function getIds() {
return [
'uid' => [
'type' => 'integer',
'alias' => 'u',
],
];
}
}