Skip to content

Commit

Permalink
Merge pull request #131 from discoverygarden/feature/stomp-queue-update
Browse files Browse the repository at this point in the history
DDST-136: Feature/stomp queue update
  • Loading branch information
nchiasson-dgi authored Jun 11, 2024
2 parents 3e7c555 + 62ca009 commit 3ba3b05
Show file tree
Hide file tree
Showing 45 changed files with 440 additions and 98 deletions.
9 changes: 8 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"require": {
"discoverygarden/dgi_saxon_helper": "^1",
"discoverygarden/foxml": "^1",
"discoverygarden/islandora_drush_utils": "^1",
"discoverygarden/islandora_drush_utils": "^1 || ^2",
"discoverygarden/update-helper": "^1",
"drupal/imagemagick": "^3.2",
"drupal/migrate_directory": "^1 || ^2",
Expand All @@ -24,5 +24,12 @@
"suggest": {
"discoverygarden/entity_reference_integrity_extra": "Deal with addtional 'entity_reference' fields.",
"drupal/entity_reference_integrity": "Used to check things when a migration elects to 'manage_orphans'."
},
"extra": {
"drush": {
"services": {
"drush.10-11.services.yml": "^10 || ^11"
}
}
}
}
7 changes: 5 additions & 2 deletions drush.services.yml → drush.10-11.services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@
services:
dgi_migrate.commands:
class: \Drupal\dgi_migrate\Drush\Commands\MigrateCommands
factory: [null, create]
arguments: ['@service_container']
arguments:
- '@plugin.manager.migration'
- '@date.formatter'
- '@entity_type.manager'
- '@keyvalue'
tags:
- { name: drush.command }
2 changes: 1 addition & 1 deletion modules/devel/src/Plugin/migrate/process/Ddm.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

namespace Drupal\dgi_migrate_devel\Plugin\migrate\process;

use Drupal\migrate\ProcessPluginBase;
use Drupal\migrate\MigrateExecutableInterface;
use Drupal\migrate\ProcessPluginBase;
use Drupal\migrate\Row;

/**
Expand Down
49 changes: 49 additions & 0 deletions modules/dgi_migrate_alter/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# DGI Migrate Alter

## Introduction
A module to easily alter migrations using the `MigrationAlter` plugin.

## Features
The module adds the `MigrationAlter` plugin base, which allows for the easy alteration of migrations.

The `MigrationAlter` plugin base has four fields:
- `id`
- `label`
- `description`
- `migration_id`
- The id of the migration you wish to alter

The path to place the alter plugins is as follows:
- `module/Plugin/dgi_migrate_alter/spreadsheet`
- `module/Plugin/dgi_migrate_alter/foxml`

There is no strict difference between the two, and are pathed as such strictly for organization.

The alter itself should be written in the `alter` function.

## Installation

Install as usual, see
[this](https://drupal.org/documentation/install/modules-themes/modules-8) for
further information.

## Troubleshooting/Issues

Having problems or solved a problem? Contact
[discoverygarden](http://support.discoverygarden.ca).

## Maintainers and Sponsors

Current maintainers:

* [discoverygarden](http://www.discoverygarden.ca)

## Development/Contribution

If you would like to contribute to this module, please check out github's helpful
[Contributing to projects](https://docs.github.com/en/get-started/quickstart/contributing-to-projects) documentation and Islandora community's [Documention for developers](https://islandora.github.io/documentation/contributing/CONTRIBUTING/#github-issues) to create an issue or pull request and/or
contact [discoverygarden](http://support.discoverygarden.ca).

## License

[GPLv3](http://www.gnu.org/licenses/gpl-3.0.txt)
5 changes: 5 additions & 0 deletions modules/dgi_migrate_alter/dgi_migrate_alter.info.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
name: 'DGI Migrate Alter'
description: "Allows easy alterations of migrations through plugins."
type: module
package: DGI
core_version_requirement: ^9 || ^10
45 changes: 45 additions & 0 deletions modules/dgi_migrate_alter/dgi_migrate_alter.module
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php

/**
* @file
* Contains dgi_migrate_alter.module.
*/

use Drupal\dgi_migrate_alter\Exception\MigrationNotFoundException;

/**
* Implements hook_migration_plugins_alter().
*/
function dgi_migrate_alter_migration_plugins_alter(array &$migrations) {
$logger = \Drupal::logger('dgi_migrate_alter');

$spreadsheet_alter_manager = \Drupal::service('plugin.manager.dgi_migrate_alter.spreadsheet');
$foxml_alter_manager = \Drupal::service('plugin.manager.dgi_migrate_alter.foxml');

$spreadsheet_definitions = $spreadsheet_alter_manager->getDefinitions();
$foxml_definitions = $foxml_alter_manager->getDefinitions();

foreach ($spreadsheet_definitions as $id => $definition) {
$logger->info('Altering migrations with spreadsheet plugin: ' . $id);
$plugin = $spreadsheet_alter_manager->createInstance($id);

try {
$plugin->alterMigrations($migrations);
}
catch (MigrationNotFoundException $e) {
$logger->error('Migration not found: ' . $e->getMessage());
}
}

foreach ($foxml_definitions as $id => $definition) {
$logger->info('Altering migrations with foxml plugin: ' . $id);
$plugin = $foxml_alter_manager->createInstance($id);

try {
$plugin->alterMigrations($migrations);
}
catch (MigrationNotFoundException $e) {
$logger->error('Migration not found: ' . $e->getMessage());
}
}
}
8 changes: 8 additions & 0 deletions modules/dgi_migrate_alter/dgi_migrate_alter.services.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
services:
plugin.manager.dgi_migrate_alter.spreadsheet:
class: Drupal\dgi_migrate_alter\Plugin\MigrationAlterPluginManager
arguments: [spreadsheet, '@container.namespaces', '@cache.discovery', '@module_handler']
plugin.manager.dgi_migrate_alter.foxml:
class: Drupal\dgi_migrate_alter\Plugin\MigrationAlterPluginManager
arguments: [foxml, '@container.namespaces', '@cache.discovery', '@module_handler']
46 changes: 46 additions & 0 deletions modules/dgi_migrate_alter/src/Annotation/MigrationAlter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php

namespace Drupal\dgi_migrate_alter\Annotation;

use Drupal\Component\Annotation\Plugin;

/**
* Defines a MigrationAlter annotation object.
*
* @Annotation
*/
class MigrationAlter extends Plugin {

/**
* The plugin ID.
*
* @var string
*/
public $id;

/**
* The human-readable name of the migration alteration.
*
* @var \Drupal\Core\Annotation\Translation
*
* @ingroup plugin_translatable
*/
public $label;

/**
* The description of the migration alteration.
*
* @var \Drupal\Core\Annotation\Translation
*
* @ingroup plugin_translatable
*/
public $description;

/**
* The migration ID.
*
* @var string
*/
public $migration_id;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

namespace Drupal\dgi_migrate_alter\Exception;

/**
* To throw when the Plugin Manager fails to find a migration to alter.
*/
class MigrationNotFoundException extends \Exception {}
39 changes: 39 additions & 0 deletions modules/dgi_migrate_alter/src/Plugin/MigrationAlterBase.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

namespace Drupal\dgi_migrate_alter\Plugin;

use Drupal\Component\Plugin\PluginBase;
use Drupal\dgi_migrate_alter\Exception\MigrationNotFoundException;

/**
* Base class for migration alter plugins.
*/
abstract class MigrationAlterBase extends PluginBase implements MigrationAlterInterface {

/**
* {@inheritdoc}
*
* @throws \Drupal\dgi_migrate_alter\Exception\MigrationNotFoundException
*/
final public function alterMigrations(array &$migrations) {
$migration_id = $this->getPluginDefinition()['migration_id'];
if (isset($migrations[$migration_id])) {
$this->alter($migrations[$migration_id]);
}
else {
throw new MigrationNotFoundException("Migration $migration_id not found.");
}
}

/**
* Alters the specified migration array provided by alterMigrations.
*
* This method is intended to be overridden in child classes.
* Each child class should implement its own logic.
*
* @param array &$migration
* The migration array to alter.
*/
abstract protected function alter(array &$migration);

}
20 changes: 20 additions & 0 deletions modules/dgi_migrate_alter/src/Plugin/MigrationAlterInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

namespace Drupal\dgi_migrate_alter\Plugin;

use Drupal\Component\Plugin\PluginInspectionInterface;

/**
* Interface for CSV Alteration plugins.
*/
interface MigrationAlterInterface extends PluginInspectionInterface {

/**
* Alters the migrations.
*
* @param array $migrations
* The migrations array.
*/
public function alterMigrations(array &$migrations);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

namespace Drupal\dgi_migrate_alter\Plugin;

use Drupal\Core\Cache\CacheBackendInterface;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\Core\Plugin\DefaultPluginManager;

/**
* Provides the migration alter plugin manager.
*/
class MigrationAlterPluginManager extends DefaultPluginManager {

/**
* Constructs a new MigrationAlterManager object.
*
* @param string $type
* The type of the plugin: spreadsheet, foxml.
* @param \Traversable $namespaces
* An object that implements \Traversable which contains the root paths
* keyed by the corresponding namespace to look for plugin implementations.
* @param \Drupal\Core\Cache\CacheBackendInterface $cache_backend
* Cache backend instance to use.
* @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
* The module handler.
*/
public function __construct($type, \Traversable $namespaces, CacheBackendInterface $cache_backend, ModuleHandlerInterface $module_handler) {
parent::__construct(
"Plugin/dgi_migrate_alter/$type",
$namespaces,
$module_handler,
'Drupal\dgi_migrate_alter\Plugin\MigrationAlterInterface',
'Drupal\dgi_migrate_alter\Annotation\MigrationAlter'
);
$this->alterInfo('dgi_migrate_alter_' . $type . '_info');
$this->setCacheBackend($cache_backend, 'dgi_migrate_alter' . $type . '_plugins');
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

use Drupal\Component\Utility\NestedArray;
use Drupal\Core\Cache\CacheableMetadata;
use Drupal\Core\Config\ConfigFactoryOverrideInterface;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Config\ConfigFactoryOverrideInterface;
use Drupal\Core\Config\StorageInterface;

/**
Expand Down
3 changes: 1 addition & 2 deletions modules/dgi_migrate_dspace/src/Commands/DspaceCommands.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@

namespace Drupal\dgi_migrate_dspace\Commands;

use Drupal\migrate\Plugin\MigrationPluginManagerInterface;

use Drupal\Core\Entity\EntityStorageInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\migrate\Plugin\MigrationPluginManagerInterface;
use Drush\Commands\DrushCommands;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,12 @@

namespace Drupal\dgi_migrate_foxml_standard_mods_xslt\Controller;

use Drupal\dgi_migrate_foxml_standard_mods_xslt\Form\Settings;

use Drupal\Core\Access\AccessResult;
use Drupal\Core\Cache\CacheableResponse;
use Drupal\Core\Config\Config;
use Drupal\Core\DependencyInjection\ContainerInjectionInterface;
use Drupal\Core\Session\AccountInterface;

use Drupal\dgi_migrate_foxml_standard_mods_xslt\Form\Settings;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\IpUtils;
use Symfony\Component\HttpFoundation\Request;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@

namespace Drupal\dgi_migrate_foxml_standard_mods_xslt\EventSubscriber;

use Drupal\dgi_migrate_foxml_standard_mods_xslt\Form\Settings;
use Drupal\migrate\Plugin\MigrationPluginManagerInterface;

use Drupal\Component\Plugin\Discovery\CachedDiscoveryInterface;
use Drupal\Core\Config\ConfigCrudEvent;
use Drupal\Core\Config\ConfigEvents;

use Drupal\dgi_migrate_foxml_standard_mods_xslt\Form\Settings;
use Drupal\migrate\Plugin\MigrationPluginManagerInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@

namespace Drupal\dgi_migrate_foxml_standard_mods_xslt\Plugin\migrate\process;

use Drupal\dgi_saxon_helper_migrate\Plugin\migrate\process\Saxon;
use Drupal\dgi_saxon_helper\TransformerInterface;

use Drupal\Core\Url;
use Drupal\dgi_saxon_helper\TransformerInterface;
use Drupal\dgi_saxon_helper_migrate\Plugin\migrate\process\Saxon;

/**
* Wrapper to help perform _our_ transformation.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

namespace Drupal\dgi_migrate_foxml_standard_mods\Plugin\migrate\process;

use Drupal\migrate\ProcessPluginBase;
use Drupal\migrate\MigrateExecutableInterface;
use Drupal\migrate\ProcessPluginBase;
use Drupal\migrate\Row;

/**
Expand Down
Loading

0 comments on commit 3ba3b05

Please sign in to comment.