migration is ok again (remains probleme of ram consuming > 4Go for users

This commit is contained in:
2020-11-17 11:23:03 +01:00
parent ee5f880f2c
commit 8db06621ce
57 changed files with 801 additions and 162 deletions

View File

@@ -7,13 +7,13 @@ function computed_field_field_index_compute($entity_type_manager, $entity, $fiel
// ksm($fields);
// ksm($delta);
$famille = $entity->get('field_famille')->getValue()[0]['value'];
// $entity->isNew(); ??
// TODO: what if familly change ?
if (!empty($entity->field_index->value)) { // the node is not new
return $entity->field_index->value;
}
// the node is new
// get all same entities in same family
$query = \Drupal::entityQuery($entity->getEntityTypeId())
@@ -21,17 +21,22 @@ function computed_field_field_index_compute($entity_type_manager, $entity, $fiel
->condition('field_famille', $famille)
->sort('field_index', 'DESC')
->range(0,1);
$nids = $query->execute();
$index = null;
if(is_array($nids)){
$last = entity_load($entity->getEntityTypeId(), array_pop($nids));
// get identifiants fo these entities
$index = $last->get('field_index')->getValue()[0]['value'] + 1;
}else{
$index = '1';
$nid = array_pop($nids);
if ($nid) {
$last = entity_load($entity->getEntityTypeId(), array_pop($nids));
// get identifiants fo these entities
$index = $last->get('field_index')->getValue()[0]['value'] + 1;
}
}
return $index;
// if(!$index){
// $index = '1';
// }
return $index ? $index : '1';
}
@@ -69,7 +74,7 @@ function materio_id_form_node_materiau_edit_form_alter(&$form, \Drupal\Core\Form
// dsm($family);
$form['field_famille']['widget']['#disabled'] = true;
}
// adding reference to the form title
$ref = $node->field_reference->value;
// dsm($ref);

View File

@@ -9,9 +9,10 @@ migration_tags:
- Content
- Materio
- Files
source:
plugin: d7_pubic_file
batch_size: 5000
scheme: public
constants:
# The tool configuring this migration must set source_base_path. It

View File

@@ -10,6 +10,7 @@ migration_tags:
source:
plugin: d7_node_materiau
node_type: materiau
batch_size: 500
high_water_property:
name: changed
alias: n
@@ -51,6 +52,10 @@ process:
plugin: default_value
source: workflow
default_value: 2
# -
# plugin: debug
# source: workflow
# label: workflow_debug
-
plugin: static_map
default_value: 2

View File

@@ -62,7 +62,8 @@ process:
4: "workflow_imported"
5: "workflow_edited"
simplenews_issue:
# https://www.drupal.org/project/simplenews/issues/3037694
simplenews_issue/target_id:
-
plugin: extract
source: field_simplenews_term
@@ -76,8 +77,15 @@ process:
6374: "ze_daily_materio_"
6274: "materio_newsletter"
7881: "companies"
# Sent status
simplenews_issue/sent_count: snn_sent_subscriber_count
simplenews_issue/status: snn_status
simplenews_issue/error_count:
plugin: default_value
default_value: 0
simplenews_issue/subscribers: snn_sent_subscriber_count
simplenews_issue/handler:
plugin: default_value
default_value: simplenews_all
migration_dependencies:
required:

View File

@@ -9,6 +9,7 @@ migration_tags:
source:
plugin: d7_user_profile
batch_size: 1000
high_water_property:
name: changed
alias: p

View File

@@ -9,6 +9,7 @@ migration_tags:
source:
plugin: d7_users
batch_size: 1000
destination:
plugin: entity:user

View File

@@ -12,12 +12,24 @@ dependencies:
- migrate_tools:migrate_tools
# - drupal:field_group_migrate
- telephone_validation
# config_devel:
# install:
# - migrate_plus.migration_group.d7_materio
# - migrate_plus.migration.d7_taxonomy_term_thesaurus
# - migrate_plus.migration.d7_taxonomy_term_tags
# - migrate_plus.migration.d7_taxonomy_term_showroom
# - migrate_plus.migration.d7_taxonomy_term_company
# - migrate_plus.migration.d7_node_entity_translation_materiau
# https://www.liip.ch/en/blog/using-the-new-drupal-8-migration-api-module
config_devel:
install:
- migrate_plus.migration.d7_users
- migrate_plus.migration.d7_allpublicfiles
- migrate_plus.migration.d7_taxonomy_term_company
- migrate_plus.migration.d7_uc_roles_license
- migrate_plus.migration.d7_simplenews_subscribers
- migrate_plus.migration.d7_node_article
- migrate_plus.migration.d7_simplenews_nodes
- migrate_plus.migration.d7_node_materiau
- migrate_plus.migration.d7_node_materiau_i18n
- migrate_plus.migration.d7_node_article_i18n
- migrate_plus.migration.d7_user_profile
- migrate_plus.migration_group.d7_materio
- migrate_plus.migration.d7_taxonomy_term_showroom
- migrate_plus.migration.d7_taxonomy_term_tags_i18n
- migrate_plus.migration.d7_taxonomy_term_tags
- migrate_plus.migration.d7_taxonomy_term_thesaurus_i18n
- migrate_plus.migration.d7_taxonomy_term_thesaurus

View File

@@ -178,7 +178,7 @@ class D7NodeMateriau extends FieldableEntity {
drush_print('WARNING: no workflow');
}
$row->setSourceProperty('workflow', $results);
// drush_print('workflow: '.$results);
// record migration errors in field_memo
if(isset($memo)){
@@ -186,7 +186,6 @@ class D7NodeMateriau extends FieldableEntity {
$field_memo[0]['value'] .= "\n".$memo;
$row->setSourceProperty('field_memo', $field_memo);
}
return parent::prepareRow($row);
}

View File

@@ -84,9 +84,13 @@ class D7SimplenewsNodes extends FieldableEntity {
])
->orderBy('changed');
$query->innerJoin('node', 'n', static::JOIN);
$query->addField('n', 'uid', 'node_uid');
$query->addField('nr', 'uid', 'revision_uid');
$query->innerJoin('node', 'n', static::JOIN);
$query->innerJoin('simplenews_newsletter', 'snn', 'snn.nid = n.nid');
$query->addField('snn', 'status', 'snn_status');
$query->addField('snn', 'sent_subscriber_count', 'snn_sent_subscriber_count');
if (isset($this->configuration['node_type'])) {
$query->condition('n.type', $this->configuration['node_type']);

View File

@@ -149,6 +149,8 @@ class D7TaxonomyTermCompany extends FieldableEntity implements ContainerFactoryP
// drush_print('tode_nid: ');
// print_r($tode_nid);
// drush_print(' ');
// TODO: [error] Drupal\Core\Entity\EntityStorageException: Route "entity.workflow_state.canonical" does not exist. in Drupal\Core\Entity\Sql\SqlContentEntityStorage->save() (line 846 of /var/www/html/d8.materio.com/public_html/web/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php).
if($tode_nid){
// get the tode fields
foreach ($this->getFields('node', 'company') as $field_name => $field) {

View File

@@ -127,7 +127,7 @@ class D7UcRolesLicense extends DrupalSqlBase {
'created',
'modified',
]);
$query->orderBy('created', DESC);
$query->orderBy('created', 'DESC');
$orders = $query->execute()->fetchAll();
// print_r($orders);

View File

@@ -21,7 +21,7 @@ class D7Users extends FieldableEntity {
public function query() {
return $this->select('users', 'u')
->fields('u')
->condition('u.uid', 0, '>');
->condition('u.uid', 1, '>');
}
/**

View File

@@ -0,0 +1,43 @@
Copied from https://www.drupal.org/sandbox/onkeltem/2828817 and added the patch from https://www.drupal.org/project/2828817/issues/2919993
# About
On Drupal 7 we could disable hooks while running migrations:
https://www.drupal.org/node/2136601
This module adds a similar feature. You can disable hooks
in settings.php or by editing configuratoin object `migrate_booster.settings`.
There are two ways to disable hooks:
1) Disable specific hooks and modules:
```
$config['migrate_booster.settings']['hooks'] = [
# Entity insert
'entity_insert' => [
'workbench_moderation',
'pathauto',
'xmlsitemap',
],
# Entity presave
'entity_presave' => [
'xmlsitemap',
],
# Entity predelete
'entity_predelete' => [
'flag',
],
];
```
2) Disable all hooks of specific modules:
```
$config['migrate_booster.settings']['modules'] = [
'workbench_moderation',
'pathauto',
'xmlsitemap',
];
```

View File

@@ -0,0 +1,3 @@
commands:
- migrate:import
- migrate:rollback

View File

@@ -0,0 +1,6 @@
services:
migrate_booster.commands:
class: \Drupal\migrate_booster\Commands\MigrateBoosterCommands
arguments: ['@plugin.manager.migration', '@date.formatter', '@entity_type.manager', '@keyvalue']
tags:
- { name: drush.command }

View File

@@ -0,0 +1,30 @@
<?php
use Drupal\migrate_booster\MigrateBooster;
/**
* Implements hook_drush_init().
*/
function migrate_booster_drush_init() {
// Skip when bootstrap level is low (e.g. drush cr)
if (!\Drupal::hasContainer()) {
return;
}
MigrateBooster::bootDrush();
}
/**
* Implements hook_drush_command().
*/
function migrate_booster_drush_command() {
$items['migrate-booster-reset'] = [
'description' => 'Resets migrate booster and implementation cache.',
'aliases' => ['mbr'],
'drupal dependencies' => ['migrate_booster'],
];
return $items;
}
function drush_migrate_booster_reset() {
MigrateBooster::disable();
}

View File

@@ -0,0 +1,7 @@
name: Migrate booster
type: module
description: Hooks disabler
core: 8.x
package: Migration
dependencies:
- migrate

View File

@@ -0,0 +1,15 @@
<?php
use Drupal\migrate_booster\MigrateBooster;
/** @noinspection PhpInconsistentReturnPointsInspection */
/**
* Implements hook_module_implements_alter().
* @param $implementations
* @param $hook
* @return null
*/
function migrate_booster_module_implements_alter(&$implementations, $hook) {
MigrateBooster::alter($implementations, $hook);
}

View File

@@ -0,0 +1,5 @@
services:
migrate_booster.hooks_enabler_subscriber:
class: Drupal\migrate_booster\HooksEnablerSubscriber
tags:
- { name: 'event_subscriber' }

View File

@@ -0,0 +1,10 @@
<?php
use Drupal\migrate_booster\MigrateBooster;
use Symfony\Component\Console\Event\ConsoleCommandEvent;
use Symfony\Component\Console\ConsoleEvents;
/** @noinspection PhpUnusedParameterInspection */
$GLOBALS['dispatcher']->addListener(ConsoleEvents::COMMAND, function (ConsoleCommandEvent $event) {
MigrateBooster::bootDrupal();
});

View File

@@ -0,0 +1,61 @@
<?php
namespace Drupal\migrate_booster\Commands;
use Consolidation\AnnotatedCommand\AnnotationData;
use Drupal\migrate_booster\MigrateBooster;
use Drush\Commands\DrushCommands;
use Symfony\Component\Console\Input\InputInterface;
/**
*
* In addition to a commandfile like this one, you need a drush.services.yml
* in root of your module.
*
* See these files for an example of injecting Drupal services:
* - http://cgit.drupalcode.org/devel/tree/src/Commands/DevelCommands.php
* - http://cgit.drupalcode.org/devel/tree/drush.services.yml
*/
class MigrateBoosterCommands extends DrushCommands {
/**
* Resets migrate booster and implementation cache.
*
* @command migrate:booster:reset
*
* @validate-module-enabled migrate_booster
* @aliases mbr,migrate-booster-reset
*/
public function boosterReset()
{
// See bottom of https://weitzman.github.io/blog/port-to-drush9 for details on what to change when porting a
// legacy command.
MigrateBooster::reset();
}
/**
* Enables migrate booster and implementation cache.
*
* @command migrate:booster:enable
*
* @validate-module-enabled migrate_booster
* @aliases mbe,migrate-booster-enable
*/
public function boosterEnable()
{
// See bottom of https://weitzman.github.io/blog/port-to-drush9 for details on what to change when porting a
// legacy command.
MigrateBooster::enable();
}
/**
* @hook init *
*/
public function initCommand(InputInterface $input, AnnotationData $annotationData) {
// Skip when bootstrap level is low (e.g. drush cr)
if (!\Drupal::hasContainer()) {
return;
}
MigrateBooster::bootDrush($input, $annotationData);
}
}

View File

@@ -0,0 +1,29 @@
<?php
namespace Drupal\migrate_booster;
use Symfony\Component\HttpKernel\KernelEvents;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
/**
* Provides a MyModuleSubscriber.
*/
class HooksEnablerSubscriber implements EventSubscriberInterface {
/**
* {@inheritdoc}
*/
static function getSubscribedEvents() {
$events[KernelEvents::REQUEST][] = array('ensureHooksEnabled', 20);
return $events;
}
/**
* Triggers on 'kernel.request' event which occurs when Drupal
* bootstraps (but not when Drush or Drupal console command runs).
*/
public function ensureHooksEnabled() {
MigrateBooster::bootDrupal();
}
}

View File

@@ -0,0 +1,115 @@
<?php
namespace Drupal\migrate_booster;
use Consolidation\AnnotatedCommand\AnnotationData;
use Symfony\Component\Console\Input\InputInterface;
class MigrateBooster {
protected static $alterActive;
protected static $config;
const CID = 'migrate_booster_enabled';
// Startup hooks
/**
* Reacts on HOOK_drush_init().
*
* Enables/disables booster depending on a drush command invoked.
*/
public static function bootDrush(InputInterface $input, AnnotationData $annotationData) {
if (in_array($annotationData['command'], static::getConfig('commands'))) {
static::enable();
}
else {
static::disable();
}
}
/**
* Disables booster on Drupal and Drupal console boots.
*/
public static function bootDrupal() {
static::disable();
}
/**
* Enables booster.
*
* Resets implementation cache and sets $alterActive class variable.
*
*/
public static function enable() {
static::$alterActive = TRUE;
static::reset();
}
/**
* Disables booster.
*
* Resets implementation cache.
*/
public static function disable() {
static::reset();
}
/**
* Resets implementations cache.
*/
public static function reset() {
$module_handler = \Drupal::moduleHandler();
$module_handler->resetImplementations();
}
/** @noinspection PhpInconsistentReturnPointsInspection */
/**
* Implements hook_module_implementation_alter().
*
* Disables configured hooks.
* @param $implementations
* @param $hook
* @return null
*/
public static function alter(&$implementations, $hook) {
if (!static::$alterActive) {
return NULL;
}
if (!$implementations) {
return NULL;
}
$hooks = static::getConfig('hooks');
$modules = static::getConfig('modules');
$disabled = [];
// Disable by hook + module
if (array_key_exists($hook, $hooks)) {
$disabled = array_intersect_key($implementations, array_flip($hooks[$hook]));
}
// Disable by module
$disabled += array_intersect_key($implementations, array_flip($modules));
$implementations = array_diff_key($implementations, $disabled);
/** @noinspection PhpUnusedParameterInspection */
array_walk($disabled, function ($el, $key) use ($hook) {
error_log('DISABLED: ' . $key . '_' . $hook);
});
}
/**
* Helper functions
*
* @param $key
* @return array
*/
protected static function getConfig($key) {
if (!static::$config) {
static::$config = \Drupal::config('migrate_booster.settings')->get();
}
if ($key && isset(static::$config[$key])) {
return static::$config[$key];
}
return [];
}
}