company term migration : name, memo, phone, website

This commit is contained in:
Bachir Soussi Chiadmi 2018-12-09 16:20:53 +01:00
parent 43d32db826
commit 1b40733e3c
5 changed files with 478 additions and 23 deletions

View File

@ -10,7 +10,10 @@
"drupal/migrate_tools": "^4.0",
"drupal/config_devel": "^1.2",
"drupal/examples": "1.x-dev",
"drupal/synonyms": "1.x-dev"
"drupal/synonyms": "1.x-dev",
"drupal/address": "^1.4",
"drupal/telephone_validation": "^2.1",
"drupal/telephone_formatter": "^1.0@beta"
},
"replace": {
"drupal/core": "^8.6"

341
composer.lock generated
View File

@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "6d95526da61b6311251b823859c3edcc",
"content-hash": "108796aaf8d4f0d21b1f86729a2b07b8",
"packages": [
{
"name": "alchemy/zippy",
@ -167,6 +167,65 @@
"description": "Drupal code generator",
"time": "2018-10-11T08:05:59+00:00"
},
{
"name": "commerceguys/addressing",
"version": "v1.0.2",
"source": {
"type": "git",
"url": "https://github.com/commerceguys/addressing.git",
"reference": "f23ce2596ccfb47bcdaa9d14fbf9b4f699dc3d4b"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/commerceguys/addressing/zipball/f23ce2596ccfb47bcdaa9d14fbf9b4f699dc3d4b",
"reference": "f23ce2596ccfb47bcdaa9d14fbf9b4f699dc3d4b",
"shasum": ""
},
"require": {
"doctrine/collections": "~1.0",
"php": ">=5.5.0"
},
"require-dev": {
"mikey179/vfsstream": "1.*",
"phpunit/phpunit": "~4.0",
"squizlabs/php_codesniffer": "2.*",
"symfony/validator": ">=3.2"
},
"suggest": {
"symfony/validator": "to validate addresses"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.x-dev"
}
},
"autoload": {
"psr-4": {
"CommerceGuys\\Addressing\\": "src"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Bojan Zivanovic"
},
{
"name": "Damien Tournoud"
}
],
"description": "Addressing library powered by CLDR and Google's address data.",
"keywords": [
"address",
"internationalization",
"localization",
"postal"
],
"time": "2018-10-21T23:38:05+00:00"
},
{
"name": "composer/installers",
"version": "v1.6.0",
@ -1478,6 +1537,65 @@
"source": "http://cgit.drupalcode.org/views_bulk_operations"
}
},
{
"name": "drupal/address",
"version": "1.4.0",
"source": {
"type": "git",
"url": "https://git.drupal.org/project/address",
"reference": "8.x-1.4"
},
"dist": {
"type": "zip",
"url": "https://ftp.drupal.org/files/projects/address-8.x-1.4.zip",
"reference": "8.x-1.4",
"shasum": "143e426be73418c719c6bddd5fb81c610604e860"
},
"require": {
"commerceguys/addressing": "^1.0.0",
"drupal/core": "*"
},
"require-dev": {
"drupal/token": "*"
},
"type": "drupal-module",
"extra": {
"branch-alias": {
"dev-1.x": "1.x-dev"
},
"drupal": {
"version": "8.x-1.4",
"datestamp": "1527081784",
"security-coverage": {
"status": "covered",
"message": "Covered by Drupal's security advisory policy"
}
}
},
"notification-url": "https://packages.drupal.org/8/downloads",
"license": [
"GPL-2.0+"
],
"authors": [
{
"name": "bojanz",
"homepage": "https://www.drupal.org/user/86106"
},
{
"name": "googletorp",
"homepage": "https://www.drupal.org/user/386230"
},
{
"name": "rszrama",
"homepage": "https://www.drupal.org/user/49344"
}
],
"description": "Provides functionality for storing, validating and displaying international postal addresses.",
"homepage": "http://drupal.org/project/address",
"support": {
"source": "http://cgit.drupalcode.org/address"
}
},
{
"name": "drupal/admin_toolbar",
"version": "1.24.0",
@ -5837,6 +5955,109 @@
},
"time": "2018-10-21T17:05:25+00:00"
},
{
"name": "drupal/telephone_formatter",
"version": "1.0.0-beta1",
"source": {
"type": "git",
"url": "https://git.drupal.org/project/telephone_formatter",
"reference": "8.x-1.0-beta1"
},
"dist": {
"type": "zip",
"url": "https://ftp.drupal.org/files/projects/telephone_formatter-8.x-1.0-beta1.zip",
"reference": "8.x-1.0-beta1",
"shasum": "6d606d98840d983ace3f642879cb49683f2c1711"
},
"require": {
"drupal/core": "*",
"giggsey/libphonenumber-for-php": "^8.0"
},
"suggest": {
"drupal/telephone_validation": "Unsure data quality"
},
"type": "drupal-module",
"extra": {
"branch-alias": {
"dev-1.x": "1.x-dev"
},
"drupal": {
"version": "8.x-1.0-beta1",
"datestamp": "1492638542",
"security-coverage": {
"status": "not-covered",
"message": "Beta releases are not covered by Drupal security advisories."
}
}
},
"notification-url": "https://packages.drupal.org/8/downloads",
"license": [
"GPL-2.0+"
],
"authors": [
{
"name": "Jakub Piasecki",
"homepage": "https://www.drupal.org/user/1532844",
"email": "jakub@piaseccy.pl"
}
],
"description": "Additional formatters to Telephone field.",
"homepage": "https://www.drupal.org/project/telephone_formatter",
"support": {
"source": "http://cgit.drupalcode.org/telephone_formatter",
"issues": "http://drupal.org/project/issues/telephone_formatter"
}
},
{
"name": "drupal/telephone_validation",
"version": "2.1.0",
"source": {
"type": "git",
"url": "https://git.drupal.org/project/telephone_validation",
"reference": "8.x-2.1"
},
"dist": {
"type": "zip",
"url": "https://ftp.drupal.org/files/projects/telephone_validation-8.x-2.1.zip",
"reference": "8.x-2.1",
"shasum": "fcdb0c3c5541b06e6dd469a7aacefd2d0a891b74"
},
"require": {
"drupal/core": "^8.0",
"drupal/telephone": "*",
"giggsey/libphonenumber-for-php": "~8.0"
},
"type": "drupal-module",
"extra": {
"branch-alias": {
"dev-2.x": "2.x-dev"
},
"drupal": {
"version": "8.x-2.1",
"datestamp": "1527165785",
"security-coverage": {
"status": "covered",
"message": "Covered by Drupal's security advisory policy"
}
}
},
"notification-url": "https://packages.drupal.org/8/downloads",
"license": [
"GPL-2.0+"
],
"authors": [
{
"name": "zaporylie",
"homepage": "https://www.drupal.org/user/1532844"
}
],
"description": "Use 3rd party library to validate telephone field.",
"homepage": "http://drupal.org/project/telephone_validation",
"support": {
"source": "http://cgit.drupalcode.org/telephone_validation",
"issues": "http://drupal.org/project/issues/telephone_validation"
}
},
{
"name": "drupal/token",
"version": "1.5.0",
@ -6594,6 +6815,123 @@
"description": "Useful scripts for testing multiple sets of Composer dependencies.",
"time": "2018-08-08T23:37:23+00:00"
},
{
"name": "giggsey/libphonenumber-for-php",
"version": "8.10.2",
"source": {
"type": "git",
"url": "https://github.com/giggsey/libphonenumber-for-php.git",
"reference": "a71f260c2efce10ded8af030a20fa13edfb0e9be"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/giggsey/libphonenumber-for-php/zipball/a71f260c2efce10ded8af030a20fa13edfb0e9be",
"reference": "a71f260c2efce10ded8af030a20fa13edfb0e9be",
"shasum": ""
},
"require": {
"ext-mbstring": "*",
"giggsey/locale": "^1.2",
"php": ">=5.3.2"
},
"require-dev": {
"pear/pear-core-minimal": "^1.9",
"pear/pear_exception": "^1.0",
"pear/versioncontrol_git": "^0.5",
"phing/phing": "^2.7",
"php-coveralls/php-coveralls": "^1.0|^2.0",
"phpunit/phpunit": "^4.8.36|^5.0",
"symfony/console": "^2.8|^3.0"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "8.x-dev"
}
},
"autoload": {
"psr-4": {
"libphonenumber\\": "src/"
},
"exclude-from-classmap": [
"/src/data/",
"/src/carrier/data/",
"/src/geocoding/data/",
"/src/timezone/data/"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"Apache-2.0"
],
"authors": [
{
"name": "Joshua Gigg",
"email": "giggsey@gmail.com",
"homepage": "https://giggsey.com/"
}
],
"description": "PHP Port of Google's libphonenumber",
"homepage": "https://github.com/giggsey/libphonenumber-for-php",
"keywords": [
"geocoding",
"geolocation",
"libphonenumber",
"mobile",
"phonenumber",
"validation"
],
"time": "2018-12-06T10:42:08+00:00"
},
{
"name": "giggsey/locale",
"version": "1.6",
"source": {
"type": "git",
"url": "https://github.com/giggsey/Locale.git",
"reference": "da6845720b5d104d319d7e84576f54e44dd9e4f5"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/giggsey/Locale/zipball/da6845720b5d104d319d7e84576f54e44dd9e4f5",
"reference": "da6845720b5d104d319d7e84576f54e44dd9e4f5",
"shasum": ""
},
"require": {
"php": ">=5.3.2"
},
"require-dev": {
"pear/pear-core-minimal": "^1.9",
"pear/pear_exception": "^1.0",
"pear/versioncontrol_git": "^0.5",
"phing/phing": "~2.7",
"phpunit/phpunit": "^4.8|^5.0",
"satooshi/php-coveralls": "^1.0",
"symfony/console": "^2.8|^3.0|^4.0",
"symfony/filesystem": "^2.8|^3.0|^4.0",
"symfony/finder": "^2.8|^3.0|^4.0",
"symfony/process": "^2.8|^3.0|^4.0"
},
"type": "library",
"autoload": {
"psr-4": {
"Giggsey\\Locale\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Joshua Gigg",
"email": "giggsey@gmail.com",
"homepage": "http://giggsey.com/"
}
],
"description": "Locale functions required by libphonenumber-for-php",
"time": "2018-10-18T07:17:52+00:00"
},
{
"name": "grasmash/expander",
"version": "1.0.0",
@ -11762,6 +12100,7 @@
"stability-flags": {
"drupal/examples": 20,
"drupal/synonyms": 20,
"drupal/telephone_formatter": 10,
"drupal/advanced_text_formatter": 10,
"drupal/autocomplete_deluxe": 10,
"drupal/better_exposed_filters": 15,

View File

@ -23,8 +23,6 @@ process:
plugin: default_value
default_value: company
name: name
'description/value': description
'description/format': format
weight: weight
# Only attempt to stub real (non-zero) parents.
parent_id:
@ -34,12 +32,40 @@ process:
source: parent
-
plugin: migration_lookup
migration: d7_taxonomy_term_company
migration: d7_taxonomy_term_companie
parent:
plugin: default_value
default_value: 0
source: '@parent_id'
forum_container: is_container
changed: timestamp
# TODO: tode node company
# FROM TODE (linked tode node)
field_website:
plugin: iterator
source: field_website
process:
uri: url
title: title
options: attributes
field_memo: field_memo
field_public_phone: public_phone
# plugin: iterator
# source: field_public_phone
# process:
# value: number
# # ??: country_codes
# # ??: extension
field_public_email: field_public_email
field_departement: field_departement
field_description: body
# 'description/value': description
# 'description/format': format
field_infos_from_company: field_infos_from_company
field_public_address: field_public_address
field_note: field_note
field_attachments: field_attachments
# workflow ??

View File

@ -11,6 +11,7 @@ dependencies:
- migrate_plus:migrate_plus
- migrate_tools:migrate_tools
# - drupal:field_group_migrate
- telephone_validation
config_devel:
install:

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.
@ -13,7 +22,45 @@ use Drupal\migrate_drupal\Plugin\migrate\source\d7\FieldableEntity;
* source_module = "taxonomy"
* )
*/
class D7TaxonomyTermCompany extends FieldableEntity {
class D7TaxonomyTermCompany extends FieldableEntity implements ContainerFactoryPluginInterface{
/**
* 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}
@ -21,8 +68,8 @@ class D7TaxonomyTermCompany extends FieldableEntity {
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');
@ -46,6 +93,10 @@ class D7TaxonomyTermCompany extends FieldableEntity {
'weight' => $this->t('Weight'),
'parent' => $this->t("The Drupal term IDs of the term's parents."),
'format' => $this->t("Format of the term description."),
'revision_id' => $this->t('Revision ID'),
'language' => $this->t('Term translation language'),
'source' => $this->t('Term translation source language'),
'public_phone' => $this->t('Public phone converted to new format (with libphonenumber)')
];
return $fields;
}
@ -55,12 +106,19 @@ class D7TaxonomyTermCompany 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.' -- '.$tid." -- ".$row->getSourceProperty('name')." -- ".$row->getSourceProperty('weight'));
// 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.
@ -70,25 +128,53 @@ class D7TaxonomyTermCompany extends FieldableEntity {
->execute()
->fetchCol();
$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']);
}
// get the tode nid
$tode_nid = $this->select('field_data_field_tode_company', 'tode')
->condition('entity_type', 'node')
->condition('field_tode_company_tid', $tid)
->fields('tode', ['entity_id'])
->execute()->fetchField();
// drush_print('tode_nid: '.$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);
drush_print($field_name.': ');
print_r($field_values);
$row->setSourceProperty($field_name, $field_values);
}
// make sure that feild_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);
}
}
// TODO: tode node company
// 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']);
$number = $this->phoneUtils->parse($national_number, $region);
$row->setSourceProperty('public_phone', $this->phoneUtils->format($number, PhoneNumberFormat::E164));
}
return parent::prepareRow($row);
}