Skip to content

Commit

Permalink
Merge pull request #75 from discoverygarden/dev-IMT77
Browse files Browse the repository at this point in the history
Prefer plugins over config entity instances
  • Loading branch information
nchiasson-dgi authored Sep 7, 2021
2 parents a03a17d + dc48566 commit 1221cd0
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 17 deletions.
1 change: 1 addition & 0 deletions islandora_spreadsheet_ingest.services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ services:
- '@entity_type.manager'
- '@cache_tags.invalidator'
- '@islandora_spreadsheet_ingest.migration_group_deriver'
- '@plugin.manager.migration'
islandora_spreadsheet_ingest.deferred_ingest.queue:
class: Drupal\Core\Queue\DatabaseQueue
factory: ['@queue', 'get']
Expand Down
10 changes: 1 addition & 9 deletions src/Form/Ingest/FileUpload.php
Original file line number Diff line number Diff line change
Expand Up @@ -303,15 +303,7 @@ protected function mapMappingFromMigrationGroup($id) {
$storage = $etm->getStorage('migration');
$names = $storage->getQuery()->condition('migration_group', $id)->execute();

$migrations = $mpm->createinstances(
$names,
array_map(
function ($a) {
return $a->toArray();
},
$storage->loadMultiple($names)
)
);
$migrations = $mpm->createInstances($names);

$start = 0;
$map_migration = function ($migration) use (&$start) {
Expand Down
26 changes: 18 additions & 8 deletions src/MigrationDeriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
use Drupal\Core\Cache\CacheTagsInvalidatorInterface;
use Psr\Log\LoggerInterface;

use Drupal\migrate_plus\Entity\MigrationInterface;
use Drupal\migrate\Plugin\MigrationInterface;
use Drupal\migrate\Plugin\MigrationPluginManagerInterface;

/**
* Derive migrations for a given request.
Expand Down Expand Up @@ -55,21 +56,30 @@ class MigrationDeriver implements MigrationDeriverInterface {
*/
protected $cacheInvalidator;

/**
* The migration plugin manager service.
*
* @var \Drupal\migrate\Plugin\MigrationPluginManagerInterface
*/
protected $migrationPluginManager;

/**
* Constructor.
*/
public function __construct(
LoggerInterface $logger,
EntityTypeManagerInterface $entity_type_manager,
CacheTagsInvalidatorInterface $invalidator,
MigrationGroupDeriverInterface $migration_group_deriver
MigrationGroupDeriverInterface $migration_group_deriver,
MigrationPluginManagerInterface $migration_plugin_manager
) {
$this->logger = $logger;
$this->entityTypeManager = $entity_type_manager;
$this->migrationGroupDeriver = $migration_group_deriver;
$this->requestStorage = $this->entityTypeManager->getStorage('isi_request');
$this->migrationStorage = $this->entityTypeManager->getStorage('migration');
$this->cacheInvalidator = $invalidator;
$this->migrationPluginManager = $migration_plugin_manager;
}

/**
Expand Down Expand Up @@ -109,7 +119,7 @@ public function getUsedColumns(array $mappings) {
/**
* Remap referenced migration dependencies to their new names.
*
* @param \Drupal\migrate_plus\Entity\MigrationInterface $migration
* @param \Drupal\migrate\Plugin\MigrationInterface $migration
* The original migration from which to scrape the dependencies.
* @param string $new_mg
* The name of the new migration group, such that we can derive the new
Expand Down Expand Up @@ -156,7 +166,7 @@ protected function deriveMigrationName($mg_name, $target) {
/**
* Determine if a migration appears to be a part of the same migration group.
*
* @param \Drupal\migrate_plus\Entity\MigrationInterface $mig
* @param \Drupal\migrate\Plugin\MigrationInterface $mig
* The original migration for comparison.
* @param string $target
* The name/id of the migration to test.
Expand All @@ -165,7 +175,7 @@ protected function deriveMigrationName($mg_name, $target) {
* TRUE if it is the same; otherwise, FALSE.
*/
protected function sameMigrationGroup(MigrationInterface $mig, $target) {
$loaded_target = $this->migrationStorage->load($target);
$loaded_target = $this->migrationPluginManager->createInstance($target);
$mg = $loaded_target->get('migration_group');
return $mg && $mg == $mig->get('migration_group');
}
Expand All @@ -175,7 +185,7 @@ protected function sameMigrationGroup(MigrationInterface $mig, $target) {
*
* @param array $steps
* The array of process plugin definitions to map.
* @param \Drupal\migrate_plus\Entity\MigrationInterface $mig
* @param \Drupal\migrate\Plugin\MigrationInterface $mig
* The original migration for comparison.
* @param string $mg_name
* The name of the migration group we are populating.
Expand Down Expand Up @@ -214,7 +224,7 @@ protected function mapStepMigrations(array $steps, MigrationInterface $mig, $mg_
*
* @param array $processes
* Associative array mapping field names to process info.
* @param \Drupal\migrate_plus\Entity\MigrationInterface $mig
* @param \Drupal\migrate\Plugin\MigrationInterface $mig
* The migration from which we are deriving another migration.
* @param string $mg_name
* The migration group we are populating.
Expand All @@ -239,7 +249,7 @@ public function createAll(RequestInterface $request) {
assert($this->entityTypeManager->getStorage('migration_group')->load($mg_name));

foreach ($request->getMappings() as $name => $info) {
$original_migration = $this->migrationStorage->load($info['original_migration_id']);
$original_migration = $this->migrationPluginManager->createInstance($info['original_migration_id']);
$derived_name = $this->deriveMigrationName($mg_name, $name);
$info = [
'id' => $derived_name,
Expand Down

0 comments on commit 1221cd0

Please sign in to comment.