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

@@ -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 [];
}
}