Skip to content

Commit

Permalink
Merge pull request #150 from discoverygarden/DDST-758
Browse files Browse the repository at this point in the history
[DDST-758] add hook_module_implements_alter to unset some content_sync hooks
  • Loading branch information
nchiasson-dgi authored Nov 18, 2024
2 parents ada58d0 + 92ec42e commit d5c0210
Show file tree
Hide file tree
Showing 18 changed files with 129 additions and 74 deletions.
5 changes: 5 additions & 0 deletions modules/dgi_migrate_big_set_overrides/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ Big Set Overrides is responsible for doing a few main things:
2. Disables the `repository_item_media_content_sync_helper_export` context so that `content_sync` doesn't export any media during the migration.
3. Disables the default Solr index, so items are not immediately indexed upon ingest.
4. Disables the `path_alias` title generation.
5. Unsets these `content_sync` hook implementations when present so
`content_sync` doesn't continuously track entities during the migration:
* `entity_update`
* `entity_insert`
* `entity_delete`

## Installation

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

/**
* @file
* General hook implementations.
*/

/**
* Implements hook_module_implements_alter().
*/
function dgi_migrate_big_set_overrides_module_implements_alter(&$implementations, $hook) {
// Don't let these content_sync hook implementations run because it slows
// down large ingests like site migrations.
$content_sync_hooks_to_unset = [
'entity_update',
'entity_insert',
'entity_delete',
];

// Unset the identified content_sync hook implementations when they exist.
if (
array_key_exists('content_sync', $implementations)
&& in_array($hook, $content_sync_hooks_to_unset)
) {
unset($implementations['content_sync']);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class Overrides implements ConfigFactoryOverrideInterface {
* Constructor.
*/
public function __construct(
ConfigFactoryInterface $config_factory
ConfigFactoryInterface $config_factory,
) {
$this->config = $config_factory->getEditable(static::CONFIG);
// XXX: Appears to be NULL on module installation; however, the requests
Expand Down
2 changes: 1 addition & 1 deletion modules/dgi_migrate_dspace/src/Commands/DspaceCommands.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class DspaceCommands extends DrushCommands {
*/
public function __construct(
MigrationPluginManagerInterface $migration_plugin_manager,
EntityTypeManagerInterface $entity_type_manager
EntityTypeManagerInterface $entity_type_manager,
) {
$this->migrationPluginManager = $migration_plugin_manager;
$this->entityTypeManager = $entity_type_manager;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public function __construct(
/**
* {@inheritDoc}
*/
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition, MigrationInterface $migration = NULL) {
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition, ?MigrationInterface $migration = NULL) {
$configuration['method'] ??= getenv('DGI_MIGRATE_FOXML_STANDARD_MODS_FILE_METHOD') ?: 'copy';
assert(in_array($configuration['method'], ['copy', 'direct']));
/** @var \Drupal\migrate\Plugin\MigratePluginManagerInterface $process_plugin_manager */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

namespace Drupal\Tests\dgi_migrate_foxml_standard_mods\Unit;

use Drupal\dgi_migrate_foxml_standard_mods\Plugin\migrate\process\TypedRelation;
use Drupal\Tests\UnitTestCase;
use Drupal\dgi_migrate_foxml_standard_mods\Plugin\migrate\process\TypedRelation;

/**
* Test out the role mapper.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public function __construct(
LoggerInterface $logger,
FileSystemInterface $file_system,
StreamWrapperManagerInterface $stream_wrapper_manager,
EventDispatcherInterface $event_dispatcher
EventDispatcherInterface $event_dispatcher,
) {
$this->logger = $logger;
$this->fileSystem = $file_system;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,11 @@ public function __construct(PathautoGeneratorInterface $pathauto_generator, Enti
* @validate-module-enabled islandora_drush_utils
* @islandora-drush-utils-user-wrap
*/
public function regenerate($options = [
'bundle' => 'islandora_object',
]) {
public function regenerate(
$options = [
'bundle' => 'islandora_object',
],
) {

$bundles = $this->entityTypeBundleInfo->getBundleInfo('node');
if (!isset($bundles[$options['bundle']])) {
Expand Down
127 changes: 74 additions & 53 deletions src/Drush/Commands/MigrateCommands.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,22 +78,25 @@ class MigrateCommands extends MigrateToolsCommands {
* @throws \Exception
* If there are not enough parameters to the command.
*/
public function batchImport($migration_names = '', array $options = [
'all' => FALSE,
'group' => self::REQ,
'tag' => self::REQ,
'limit' => self::REQ,
'feedback' => self::REQ,
'idlist' => self::REQ,
'idlist-delimiter' => MigrateTools::DEFAULT_ID_LIST_DELIMITER,
'update' => FALSE,
'force' => FALSE,
'continue-on-failure' => FALSE,
'execute-dependencies' => FALSE,
'skip-progress-bar' => FALSE,
'sync' => FALSE,
'run' => NULL,
]) : void {
public function batchImport(
$migration_names = '',
array $options = [
'all' => FALSE,
'group' => self::REQ,
'tag' => self::REQ,
'limit' => self::REQ,
'feedback' => self::REQ,
'idlist' => self::REQ,
'idlist-delimiter' => MigrateTools::DEFAULT_ID_LIST_DELIMITER,
'update' => FALSE,
'force' => FALSE,
'continue-on-failure' => FALSE,
'execute-dependencies' => FALSE,
'skip-progress-bar' => FALSE,
'sync' => FALSE,
'run' => NULL,
],
) : void {
parent::import($migration_names, $options);
}

Expand Down Expand Up @@ -233,18 +236,21 @@ protected function executeMigration(MigrationInterface $migration, $migration_id
* @throws \Exception
* If there are not enough parameters to the command.
*/
public function rollback($migration_names = '', array $options = [
'all' => FALSE,
'group' => self::REQ,
'tag' => self::REQ,
'feedback' => self::REQ,
'idlist' => self::REQ,
'idlist-delimiter' => MigrateTools::DEFAULT_ID_LIST_DELIMITER,
'skip-progress-bar' => FALSE,
'continue-on-failure' => FALSE,
'statuses' => self::REQ,
'run' => NULL,
]) : void {
public function rollback(
$migration_names = '',
array $options = [
'all' => FALSE,
'group' => self::REQ,
'tag' => self::REQ,
'feedback' => self::REQ,
'idlist' => self::REQ,
'idlist-delimiter' => MigrateTools::DEFAULT_ID_LIST_DELIMITER,
'skip-progress-bar' => FALSE,
'continue-on-failure' => FALSE,
'statuses' => self::REQ,
'run' => NULL,
],
) : void {
$group_names = $options['group'];
$tag_names = $options['tag'];
$all = $options['all'];
Expand Down Expand Up @@ -316,13 +322,15 @@ public function rollback($migration_names = '', array $options = [
* @option tag Name of the migration tag to import.
* @option sort Sort according to weight.
*/
public function listMigrations(array $options = [
'all' => FALSE,
'group' => self::REQ,
'tag' => self::REQ,
'format' => 'csv',
'sort' => FALSE,
]) : RowsOfFields {
public function listMigrations(
array $options = [
'all' => FALSE,
'group' => self::REQ,
'tag' => self::REQ,
'format' => 'csv',
'sort' => FALSE,
],
) : RowsOfFields {

$generate_order = function () use ($options) {
$migration_groups = $this->migrationsList('', $options);
Expand Down Expand Up @@ -421,11 +429,14 @@ protected static function getMigrateToolsLogger() : LoggerInterface {
*
* @islandora-drush-utils-user-wrap
*/
public function enqueueMigration(string $migration_id, array $options = [
'update' => FALSE,
'sync' => FALSE,
'run' => NULL,
]) : void {
public function enqueueMigration(
string $migration_id,
array $options = [
'update' => FALSE,
'sync' => FALSE,
'run' => NULL,
],
) : void {
$executable = $this->getExecutable($migration_id, $options);
// drush_op() provides --simulate support.
drush_op([$executable, 'prepareBatch']);
Expand All @@ -444,11 +455,14 @@ public function enqueueMigration(string $migration_id, array $options = [
*
* @islandora-drush-utils-user-wrap
*/
public function processEnqueuedMigration(string $migration_id, array $options = [
'update' => FALSE,
'sync' => FALSE,
'run' => NULL,
]) : void {
public function processEnqueuedMigration(
string $migration_id,
array $options = [
'update' => FALSE,
'sync' => FALSE,
'run' => NULL,
],
) : void {
$executable = $this->getExecutable($migration_id, $options);
// drush_op() provides --simulate support.
$batch = [
Expand Down Expand Up @@ -482,11 +496,14 @@ public function processEnqueuedMigration(string $migration_id, array $options =
*
* @islandora-drush-utils-user-wrap
*/
public function finishEnqueuedMigration(string $migration_id, array $options = [
'update' => FALSE,
'sync' => FALSE,
'run' => NULL,
]) {
public function finishEnqueuedMigration(
string $migration_id,
array $options = [
'update' => FALSE,
'sync' => FALSE,
'run' => NULL,
],
) {
$executable = $this->getExecutable($migration_id, $options);
drush_op([$executable, 'teardownMigration']);
}
Expand All @@ -501,9 +518,13 @@ public function finishEnqueuedMigration(string $migration_id, array $options = [
*
* @command dgi-migrate:enqueue-terminal
*/
public function enqueueTerminal(string $migration_id, string $run_id, array $options = [
'priority' => 4,
]) {
public function enqueueTerminal(
string $migration_id,
string $run_id,
array $options = [
'priority' => 4,
],
) {
$stomp_queue = StompQueue::create($migration_id, $run_id);
$stomp_queue->sendTerminal([
'priority' => $options['priority'] ?? 4,
Expand Down
4 changes: 2 additions & 2 deletions src/Plugin/migrate/destination/DgiRevisionedEntity.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

use Drupal\Core\Entity\ContentEntityInterface;
use Drupal\migrate\MigrateException;
use Drupal\migrate\Plugin\migrate\destination\EntityContentBase;
use Drupal\migrate\Plugin\MigrateIdMapInterface;
use Drupal\migrate\Plugin\MigrationInterface;
use Drupal\migrate\Plugin\migrate\destination\EntityContentBase;
use Drupal\migrate\Row;
use Symfony\Component\DependencyInjection\ContainerInterface;

Expand Down Expand Up @@ -42,7 +42,7 @@ class DgiRevisionedEntity extends EntityContentBase {
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition, MigrationInterface $migration = NULL) {
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition, ?MigrationInterface $migration = NULL) {
$entity_type = $configuration['entity_type'] ?? 'node';
$instance = parent::create($container, $configuration, 'entity:' . $entity_type, $plugin_definition, $migration);
$instance->entityType = $entity_type;
Expand Down
6 changes: 3 additions & 3 deletions src/Plugin/migrate/id_map/SmartSql.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\migrate\EntityFieldDefinitionTrait;
use Drupal\migrate\MigrateException;
use Drupal\migrate\Plugin\migrate\destination\Entity;
use Drupal\migrate\Plugin\migrate\id_map\Sql;
use Drupal\migrate\Plugin\MigrateIdMapInterface;
use Drupal\migrate\Plugin\MigrationInterface;
use Drupal\migrate\Plugin\MigrationPluginManagerInterface;
use Drupal\migrate\Plugin\migrate\destination\Entity;
use Drupal\migrate\Plugin\migrate\id_map\Sql;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;

Expand Down Expand Up @@ -108,7 +108,7 @@ public function __construct(array $configuration, $plugin_id, $plugin_definition
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition, MigrationInterface $migration = NULL) {
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition, ?MigrationInterface $migration = NULL) {
return parent::create($container, $configuration, $plugin_id, $plugin_definition, $migration)
->setEntityTypeManager($container->get('entity_type.manager'));
}
Expand Down
2 changes: 1 addition & 1 deletion src/Plugin/migrate/process/DetermineExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class DetermineExtension extends ProcessPluginBase {
/**
* Constructor.
*/
public function __construct(array $configuration, $plugin_id, $plugin_definition, MigrationInterface $migration = NULL) {
public function __construct(array $configuration, $plugin_id, $plugin_definition, ?MigrationInterface $migration = NULL) {
parent::__construct($configuration, $plugin_id, $plugin_definition, $migration);

$this->mimeTypes = new MimeTypes();
Expand Down
2 changes: 1 addition & 1 deletion src/Plugin/migrate/process/LockingMigrationLookup.php
Original file line number Diff line number Diff line change
Expand Up @@ -578,7 +578,7 @@ protected function doStub(&$context) {
/**
* {@inheritDoc}
*/
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition, MigrationInterface $migration = NULL) {
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition, ?MigrationInterface $migration = NULL) {
$instance = new static($configuration, $plugin_id, $plugin_definition);

/** @var \Drupal\Component\Plugin\PluginManagerInterface $process_plugin_manager */
Expand Down
2 changes: 1 addition & 1 deletion src/Plugin/migrate/process/NaiveFileCopy.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
use Drupal\Core\StreamWrapper\StreamWrapperManagerInterface;
use Drupal\migrate\MigrateException;
use Drupal\migrate\MigrateExecutableInterface;
use Drupal\migrate\Plugin\migrate\process\FileCopy;
use Drupal\migrate\Plugin\MigrateProcessInterface;
use Drupal\migrate\Plugin\migrate\process\FileCopy;
use Drupal\migrate\Row;
use Symfony\Component\DependencyInjection\ContainerInterface;

Expand Down
2 changes: 1 addition & 1 deletion src/Plugin/migrate/process/RequiredEntityLookup.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class RequiredEntityLookup extends EntityLookup {
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, array $configuration, $pluginId, $pluginDefinition, MigrationInterface $migration = NULL) {
public static function create(ContainerInterface $container, array $configuration, $pluginId, $pluginDefinition, ?MigrationInterface $migration = NULL) {
$instance = parent::create($container, $configuration, $pluginId, $pluginDefinition, $migration);

$instance->missingBehaviorInit();
Expand Down
2 changes: 1 addition & 1 deletion src/Plugin/migrate/process/StaticMap.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
use Drupal\migrate\MigrateExecutableInterface;
use Drupal\migrate\MigrateSkipProcessException;
use Drupal\migrate\MigrateSkipRowException;
use Drupal\migrate\Plugin\migrate\process\StaticMap as Upstream;
use Drupal\migrate\Plugin\MigrationInterface;
use Drupal\migrate\Plugin\migrate\process\StaticMap as Upstream;
use Drupal\migrate\Row;

/**
Expand Down
4 changes: 2 additions & 2 deletions src/Plugin/migrate/source/Migration.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\dgi_migrate\MigrationIterator;
use Drupal\migrate\Plugin\migrate\source\SourcePluginBase;
use Drupal\migrate\Plugin\MigrationInterface;
use Drupal\migrate\Plugin\MigrationPluginManagerInterface;
use Drupal\migrate\Plugin\migrate\source\SourcePluginBase;
use Symfony\Component\DependencyInjection\ContainerInterface;

/**
Expand Down Expand Up @@ -45,7 +45,7 @@ public function __construct(array $configuration, $plugin_id, $plugin_definition
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition, MigrationInterface $migration = NULL) {
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition, ?MigrationInterface $migration = NULL) {
return new static(
$configuration,
$plugin_id,
Expand Down
2 changes: 1 addition & 1 deletion src/StompQueue.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public function __construct(
IStateful $stomp,
LoggerInterface $logger,
string $name,
string $group
string $group,
) {
$this->stomp = $stomp;
$this->logger = $logger;
Expand Down

0 comments on commit d5c0210

Please sign in to comment.