migration showroom ok

This commit is contained in:
Bachir Soussi Chiadmi 2018-12-10 15:22:44 +01:00
parent b17458fe4a
commit f3bd4cb8d3
24 changed files with 610 additions and 66 deletions

View File

@ -23,23 +23,65 @@ process:
plugin: default_value
default_value: showroom
name: name
'description/value': description
'description/format': format
weight: weight
# Only attempt to stub real (non-zero) parents.
parent_id:
-
plugin: skip_on_empty
method: process
source: parent
-
plugin: migration_lookup
migration: d7_taxonomy_term_showroom
parent:
plugin: default_value
default_value: 0
source: '@parent_id'
forum_container: is_container
changed: timestamp
langcode:
plugin: default_value
default_value: 'und'
field_migration:
plugin: default_value
default_value: 'migration_imported'
field_workflow:
plugin: default_value
default_value: 'workflow_visible'
# TODO: tode node showroom
# tode node showroom
field_website:
plugin: iterator
source: field_website
process:
uri: url
title: title
options: attributes
field_memo: field_memo
field_public_phone: public_phone
field_public_email:
plugin: iterator
source: field_public_email
process:
value: email
field_public_address:
plugin: iterator
source: field_public_address
process:
# langcode:
country_code: country
administrative_area: administrative_area
locality: locality
dependent_locality: dependent_locality
postal_code: postal_code
# sorting_code:
address_line1: thoroughfare
# address_line2:
organization: organisation_name
given_name: first_name
# additional_name:
family_name: last_name
# SOURCES
# sub_administrative_area
# premise
# sub_premise
# name_line
# data
description:
plugin: iterator
source: body
process:
value: value
format:
plugin: default_value
default_value: wysiwyg

View File

@ -159,17 +159,6 @@ class D7TaxonomyTermCompany extends FieldableEntity implements ContainerFactoryP
$row->setSourceProperty($field_name, $field_values);
}
// $body = $row->getSourceProperty('body');
// if(!empty($body)){
// drush_print('body: ');
// print_r($body);
// }
// $field_infos_from_company = $row->getSourceProperty('field_infos_from_company');
// if(!empty($field_infos_from_company)){
// drush_print('field_infos_from_company: ');
// print_r($field_infos_from_company);
// }
// make sure that field_website url is absolute
$field_website = $row->getSourceProperty('field_website');
if(isset($field_website[0]['url'])){

View File

@ -4,6 +4,15 @@ namespace Drupal\materio_migrate\Plugin\migrate\source;
use Drupal\migrate\Row;
use Drupal\migrate_drupal\Plugin\migrate\source\d7\FieldableEntity;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\migrate\Plugin\MigrationInterface;
use Drupal\Core\State\StateInterface;
use Drupal\Core\Entity\EntityManagerInterface;
use Drupal\Core\Locale\CountryManagerInterface;
use libphonenumber\PhoneNumber;
use libphonenumber\PhoneNumberUtil;
use libphonenumber\PhoneNumberFormat;
/**
* Taxonomy term source from database.
@ -15,14 +24,52 @@ use Drupal\migrate_drupal\Plugin\migrate\source\d7\FieldableEntity;
*/
class D7TaxonomyTermShowroom extends FieldableEntity {
/**
* Phone Number util.
*
* @var \libphonenumber\PhoneNumberUtil
*/
public $phoneUtils;
/**
* Country Manager service.
*
* @var \Drupal\Core\Locale\CountryManagerInterface
*/
public $countryManager;
/**
* {@inheritdoc}
*/
public function __construct(array $configuration, $plugin_id, $plugin_definition, MigrationInterface $migration, StateInterface $state, EntityManagerInterface $entity_manager, CountryManagerInterface $country_manager) {
parent::__construct($configuration, $plugin_id, $plugin_definition, $migration, $state, $entity_manager);
$this->phoneUtils = PhoneNumberUtil::getInstance();
$this->countryManager = $country_manager;
}
/**
* {@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('country_manager')
);
}
/**
* {@inheritdoc}
*/
public function query() {
$query = $this->select('taxonomy_term_data', 'td')
->fields('td')
->distinct()
->orderBy('tid');
$query->leftJoin('taxonomy_vocabulary', 'tv', 'td.vid = tv.vid');
$query->addField('tv', 'machine_name');
@ -55,12 +102,19 @@ class D7TaxonomyTermShowroom extends FieldableEntity {
* {@inheritdoc}
*/
public function prepareRow(Row $row) {
print("\n".'-- prepareRow -- '.$row->getSourceProperty('tid')." -- ".$row->getSourceProperty('name')."\n");
$language = $row->getSourceProperty('language');
$tid = $row->getSourceProperty('tid');
drush_print('-- '.$language."\t".$tid."\t".$row->getSourceProperty('name'));
// vocabulary machine name
$machine_name = $row->getSourceProperty('machine_name');
$revid = $row->getSourceProperty('revision_id');
// Get Field API field values.
foreach (array_keys($this->getFields('taxonomy_term', $row->getSourceProperty('machine_name'))) as $field) {
$tid = $row->getSourceProperty('tid');
$row->setSourceProperty($field, $this->getFieldValues('taxonomy_term', $field, $tid));
foreach ($this->getFields('taxonomy_term', $machine_name) as $field_name => $field) {
// Ensure we're using the right language if the entity is translatable.
$field_language = $field['translatable'] ? $language : NULL;
$row->setSourceProperty($field_name, $this->getFieldValues('taxonomy_term', $field_name, $tid, $revid, $field_language));
}
// Find parents for this row.
@ -72,23 +126,73 @@ class D7TaxonomyTermShowroom extends FieldableEntity {
$row->setSourceProperty('parent', $parents);
// print_r($parents);
// If the term name or term description were replaced by real fields using
// the Drupal 7 Title module, use the fields value instead of the term name
// or term description.
// TODO: translations
// 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')) {
$name_field = $row->getSourceProperty('name_field');
// print_r($name_field);
if (isset($name_field[0]['value'])) {
$row->setSourceProperty('name', $name_field[0]['value']);
}
$description_field = $row->getSourceProperty('description_field');
if (isset($description_field[0]['value'])) {
$row->setSourceProperty('description', $description_field[0]['value']);
}
}
// TODO: tode node showroom
// get the tode nid
$tode_nid = $this->select('field_data_field_tode_showroom', 'tode')
->condition('entity_type', 'node')
->condition('field_tode_showroom_tid', $tid)
->fields('tode', ['entity_id'])
->execute()->fetchField();
// drush_print('tode_nid: '.$tode_nid);
// drush_print('tode_nid: ');
// print_r($tode_nid);
// drush_print(' ');
if($tode_nid){
// get the tode fields
foreach ($this->getFields('node', 'company') as $field_name => $field) {
// Ensure we're using the right language if the entity is translatable.
$field_language = $field['translatable'] ? $language : NULL;
$field_values = $this->getFieldValues('node', $field_name, $tode_nid, null, $field_language);
$row->setSourceProperty($field_name, $field_values);
}
// make sure that field_website url is absolute
$field_website = $row->getSourceProperty('field_website');
if(isset($field_website[0]['url'])){
$url = $field_website[0]['url'];
if(!strpos($url, 'http://')){
$field_website[0]['url'] = 'http://'.$url;
$row->setSourceProperty('field_website', $field_website);
}
}
// convert phone field with libphonenumber
$field_phone = $row->getSourceProperty('field_public_phone');
if(isset($field_phone[0]['number']) && !empty($field_phone[0]['number'])){
$national_number = $field_phone[0]['number'];
$region = strtoupper($field_phone[0]['country_codes']);
// isValidRegionCode($regionCode)
if($this->phoneUtils->isPossibleNumber($national_number, $region)){
$number = $this->phoneUtils->parse($national_number, $region);
$row->setSourceProperty('public_phone', $this->phoneUtils->format($number, PhoneNumberFormat::E164));
}else{
// add bad phone number to memo field
$memo .= "#migration : invalid phone number: ".$national_number.' region: '.$region."\n";
drush_print('WARNING: phone number invalide; number: '.$national_number.' region: '.$region);
}
}
}else{
// if no tode set workflow to hidden
$memo .= "#migration : missing data from tode\n";
drush_print('WARNING: no tode');
}
// 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);

View File

@ -66,7 +66,7 @@ class D7TaxonomyTermTags extends FieldableEntity {
*/
public function prepareRow(Row $row) {
$language = $row->getSourceProperty('language');
drush_print('-- '.$language.' -- '.$row->getSourceProperty('tid')." -- ".$row->getSourceProperty('name')." -- ".$row->getSourceProperty('weight'));
drush_print('-- '.$language."\t".$row->getSourceProperty('tid')."\t".$row->getSourceProperty('name'));
$tid = $row->getSourceProperty('tid');
// vocabulary machine name

View File

@ -64,7 +64,7 @@ class D7TaxonomyTermTagsI18n extends FieldableEntity {
$language = $row->getSourceProperty('language');
$tid = $row->getSourceProperty('tid');
drush_print('-- '. $language .' -- '.$tid." -- ".$row->getSourceProperty('name')." -- ".$row->getSourceProperty('weight'));
drush_print('-- '. $language ."\t".$tid."\t".$row->getSourceProperty('name'));
// vocabulary machine name
$machine_name = $row->getSourceProperty('machine_name');

View File

@ -66,7 +66,7 @@ class D7TaxonomyTermThesaurus extends FieldableEntity {
*/
public function prepareRow(Row $row) {
$language = $row->getSourceProperty('language');
drush_print('-- '.$language.' -- '.$row->getSourceProperty('tid')." -- ".$row->getSourceProperty('name')." -- ".$row->getSourceProperty('weight'));
drush_print('-- '.$language."\t".$row->getSourceProperty('tid')."\t".$row->getSourceProperty('name'));
$tid = $row->getSourceProperty('tid');
// vocabulary machine name

View File

@ -64,7 +64,7 @@ class D7TaxonomyTermThesaurusI18n extends FieldableEntity {
$language = $row->getSourceProperty('language');
$tid = $row->getSourceProperty('tid');
drush_print('-- '. $language .' -- '.$tid." -- ".$row->getSourceProperty('name')." -- ".$row->getSourceProperty('weight'));
drush_print('-- '. $language ."\t".$tid."\t".$row->getSourceProperty('name'));
// vocabulary machine name
$machine_name = $row->getSourceProperty('machine_name');

View File

@ -0,0 +1,155 @@
uuid: 3e50cbc5-1363-4439-9330-0b24547e9768
langcode: en
status: true
dependencies:
config:
- field.field.taxonomy_term.showroom.field_memo
- field.field.taxonomy_term.showroom.field_migration
- field.field.taxonomy_term.showroom.field_public_address
- field.field.taxonomy_term.showroom.field_public_email
- field.field.taxonomy_term.showroom.field_public_phone
- field.field.taxonomy_term.showroom.field_workflow
- taxonomy.vocabulary.showroom
module:
- address
- field_group
- telephone
- text
- workflow
third_party_settings:
field_group:
group_tabs:
children:
- group_contents
- group_info
- group_internal
parent_name: ''
weight: 1
format_type: tabs
format_settings:
id: ''
classes: ''
direction: horizontal
label: Tabs
group_info:
children:
- field_public_email
- field_public_phone
- field_public_address
parent_name: group_tabs
weight: 21
format_type: tab
format_settings:
id: ''
classes: ''
formatter: open
description: ''
required_fields: true
label: Infos
group_internal:
children:
- langcode
- field_memo
- translation
- field_workflow
- field_migration
parent_name: group_tabs
weight: 22
format_type: tab
format_settings:
id: ''
classes: ''
formatter: closed
description: ''
required_fields: true
label: Internal
group_contents:
children:
- description
parent_name: group_tabs
weight: 20
format_type: tab
format_settings:
id: ''
classes: ''
formatter: closed
description: ''
required_fields: true
label: Contents
id: taxonomy_term.showroom.default
targetEntityType: taxonomy_term
bundle: showroom
mode: default
content:
description:
type: text_textarea
weight: 2
region: content
settings:
placeholder: ''
rows: 5
third_party_settings: { }
field_memo:
weight: 4
settings:
rows: 5
placeholder: ''
third_party_settings: { }
type: string_textarea
region: content
field_migration:
weight: 7
settings: { }
third_party_settings: { }
type: workflow_default
region: content
field_public_address:
weight: 5
settings:
default_country: null
third_party_settings: { }
type: address_default
region: content
field_public_email:
weight: 3
settings:
size: 60
placeholder: ''
third_party_settings: { }
type: email_default
region: content
field_public_phone:
weight: 4
settings:
placeholder: ''
third_party_settings: { }
type: telephone_default
region: content
field_workflow:
weight: 6
settings: { }
third_party_settings: { }
type: workflow_default
region: content
langcode:
type: language_select
weight: 3
region: content
settings:
include_locked: true
third_party_settings: { }
name:
type: string_textfield
weight: 0
region: content
settings:
size: 60
placeholder: ''
third_party_settings: { }
translation:
weight: 5
region: content
settings: { }
third_party_settings: { }
hidden:
path: true

View File

@ -0,0 +1,72 @@
uuid: 47e24039-1ffa-4443-84ba-79abb16929e1
langcode: en
status: true
dependencies:
config:
- field.field.taxonomy_term.showroom.field_memo
- field.field.taxonomy_term.showroom.field_migration
- field.field.taxonomy_term.showroom.field_public_address
- field.field.taxonomy_term.showroom.field_public_email
- field.field.taxonomy_term.showroom.field_public_phone
- field.field.taxonomy_term.showroom.field_workflow
- taxonomy.vocabulary.showroom
module:
- address
- options
- text
id: taxonomy_term.showroom.default
targetEntityType: taxonomy_term
bundle: showroom
mode: default
content:
description:
label: hidden
type: text_default
weight: 0
region: content
settings: { }
third_party_settings: { }
field_memo:
weight: 4
label: above
settings: { }
third_party_settings: { }
type: basic_string
region: content
field_migration:
weight: 6
label: above
settings: { }
third_party_settings: { }
type: list_default
region: content
field_public_address:
weight: 2
label: above
settings: { }
third_party_settings: { }
type: address_default
region: content
field_public_email:
weight: 3
label: above
settings: { }
third_party_settings: { }
type: basic_string
region: content
field_public_phone:
weight: 1
label: above
settings: { }
third_party_settings: { }
type: basic_string
region: content
field_workflow:
weight: 5
label: above
settings: { }
third_party_settings: { }
type: list_default
region: content
hidden:
langcode: true

View File

@ -0,0 +1,19 @@
uuid: 4a77383f-9706-4f38-8fe4-190f68144275
langcode: en
status: true
dependencies:
config:
- field.storage.taxonomy_term.field_memo
- taxonomy.vocabulary.showroom
id: taxonomy_term.showroom.field_memo
field_name: field_memo
entity_type: taxonomy_term
bundle: showroom
label: Memo
description: ''
required: false
translatable: false
default_value: { }
default_value_callback: ''
settings: { }
field_type: string_long

View File

@ -0,0 +1,22 @@
uuid: e0715174-5390-45ad-9254-2b074f67e774
langcode: en
status: true
dependencies:
config:
- field.storage.taxonomy_term.field_migration
- taxonomy.vocabulary.showroom
module:
- workflow
id: taxonomy_term.showroom.field_migration
field_name: field_migration
entity_type: taxonomy_term
bundle: showroom
label: Migration
description: ''
required: true
translatable: false
default_value:
- { }
default_value_callback: ''
settings: { }
field_type: workflow

View File

@ -0,0 +1,47 @@
uuid: f6908a06-6071-4467-a801-fd5323e54e40
langcode: en
status: true
dependencies:
config:
- field.storage.taxonomy_term.field_public_address
- taxonomy.vocabulary.showroom
module:
- address
id: taxonomy_term.showroom.field_public_address
field_name: field_public_address
entity_type: taxonomy_term
bundle: showroom
label: Address
description: ''
required: false
translatable: true
default_value: { }
default_value_callback: ''
settings:
available_countries: { }
langcode_override: ''
field_overrides:
givenName:
override: optional
additionalName:
override: optional
familyName:
override: optional
organization:
override: optional
addressLine1:
override: optional
addressLine2:
override: optional
postalCode:
override: optional
sortingCode:
override: optional
dependentLocality:
override: optional
locality:
override: optional
administrativeArea:
override: optional
fields: { }
field_type: address

View File

@ -0,0 +1,19 @@
uuid: 7c14f885-b2d9-4fef-8cf3-f21f5a226016
langcode: en
status: true
dependencies:
config:
- field.storage.taxonomy_term.field_public_email
- taxonomy.vocabulary.showroom
id: taxonomy_term.showroom.field_public_email
field_name: field_public_email
entity_type: taxonomy_term
bundle: showroom
label: Email
description: ''
required: false
translatable: false
default_value: { }
default_value_callback: ''
settings: { }
field_type: email

View File

@ -0,0 +1,21 @@
uuid: ff7f7c76-c045-42a0-84e3-85954341d9af
langcode: en
status: true
dependencies:
config:
- field.storage.taxonomy_term.field_public_phone
- taxonomy.vocabulary.showroom
module:
- telephone
id: taxonomy_term.showroom.field_public_phone
field_name: field_public_phone
entity_type: taxonomy_term
bundle: showroom
label: Phone
description: ''
required: false
translatable: false
default_value: { }
default_value_callback: ''
settings: { }
field_type: telephone

View File

@ -0,0 +1,22 @@
uuid: c2c80ddb-a2df-4b7d-b078-a919b649dda0
langcode: en
status: true
dependencies:
config:
- field.storage.taxonomy_term.field_workflow
- taxonomy.vocabulary.showroom
module:
- workflow
id: taxonomy_term.showroom.field_workflow
field_name: field_workflow
entity_type: taxonomy_term
bundle: showroom
label: Workflow
description: ''
required: true
translatable: false
default_value:
- { }
default_value_callback: ''
settings: { }
field_type: workflow

View File

@ -14,5 +14,5 @@ third_party_settings:
id: taxonomy_term.showroom
target_entity_type_id: taxonomy_term
target_bundle: showroom
default_langcode: site_default
default_langcode: und
language_alterable: true

View File

@ -1,4 +1,4 @@
uuid: d6f76d50-f791-43a9-88f4-ce9ac8d3e492
uuid: 4c8a0fc1-0787-4f77-97b2-f346c79a94db
langcode: en
status: true
dependencies: { }

View File

@ -1,9 +1,9 @@
uuid: 9966f636-b14c-444a-b773-2c1c20fb5267
uuid: d6b557c9-4571-474e-8dbe-29c8a4633893
langcode: en
status: true
dependencies: { }
_core:
default_config_hash: IGag-Zj7gnWLJ2WslveQgN5A2JMdpCjA9pUY3J3qYhU
default_config_hash: Oip5TPNIP8RxEmtUffgwo8AuBwxsYGMdECAxEqmnCiA
id: d7_taxonomy_term_showroom
class: null
field_plugin_method: null
@ -22,23 +22,55 @@ process:
plugin: default_value
default_value: showroom
name: name
description/value: description
description/format: format
weight: weight
parent_id:
-
plugin: skip_on_empty
method: process
source: parent
-
plugin: migration_lookup
migration: d7_taxonomy_term_showroom
parent:
plugin: default_value
default_value: 0
source: '@parent_id'
forum_container: is_container
changed: timestamp
langcode:
plugin: default_value
default_value: und
field_migration:
plugin: default_value
default_value: migration_imported
field_workflow:
plugin: default_value
default_value: workflow_visible
field_website:
plugin: iterator
source: field_website
process:
uri: url
title: title
options: attributes
field_memo: field_memo
field_public_phone: public_phone
field_public_email:
plugin: iterator
source: field_public_email
process:
value: email
field_public_address:
plugin: iterator
source: field_public_address
process:
country_code: country
administrative_area: administrative_area
locality: locality
dependent_locality: dependent_locality
postal_code: postal_code
address_line1: thoroughfare
organization: organisation_name
given_name: first_name
family_name: last_name
description:
plugin: iterator
source: body
process:
value: value
format:
plugin: default_value
default_value: wysiwyg
destination:
plugin: 'entity:taxonomy_term'
migration_dependencies: null

View File

@ -1,4 +1,4 @@
uuid: de8abcf5-874a-44e7-a02a-d3e767bb27a3
uuid: ee3c366d-33d3-4a01-9762-f7009e7ca383
langcode: en
status: true
dependencies: { }

View File

@ -1,4 +1,4 @@
uuid: b128c8a9-da5b-4680-b954-96c748f85aee
uuid: c1ae337a-6919-47bd-9fd7-ad062e5a6669
langcode: en
status: true
dependencies: { }

View File

@ -1,4 +1,4 @@
uuid: ade5d159-a4df-4ec9-b38b-53efa4d3f82b
uuid: 111d2fff-d284-497c-8ef6-56a08b5ed4d5
langcode: en
status: true
dependencies: { }

View File

@ -1,4 +1,4 @@
uuid: ff6e047a-f5b3-4f56-9588-fccfdce4e09f
uuid: 1db4c3ff-2004-4d45-baff-ef3238071b75
langcode: en
status: true
dependencies: { }

View File

@ -1,4 +1,4 @@
uuid: 99c21b67-4b40-449e-8980-c8d56df8e5a6
uuid: 771b5dfa-c03a-4ec2-9fd1-affbbd53117d
langcode: en
status: true
dependencies:

View File

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