Skip to content

Commit

Permalink
Merge pull request #77 from discoverygarden/dev-IMT78
Browse files Browse the repository at this point in the history
Move away from config entities
  • Loading branch information
JojoVes authored Sep 10, 2021
2 parents 1221cd0 + bd4b6e1 commit d19e2c7
Show file tree
Hide file tree
Showing 10 changed files with 123 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

/**
* @file
* Misc (un)installation/update hooks.
*/

/**
* Remove config entities.
*/
function islandora_spreadsheet_ingest_example_update_8100() {
$storage = \Drupal::service('entity_type.manager')->getStorage('isi_request');
$requests = $storage->loadMultiple();

$entities = [
'migrate_plus.migration.isi_file',
'migrate_plus.migration.isi_media_audio',
'migrate_plus.migration.isi_media_doc',
'migrate_plus.migration.isi_media_file',
'migrate_plus.migration.isi_media_image',
'migrate_plus.migration.isi_media_video',
'migrate_plus.migration.isi_node',
];

$config_factory = \Drupal::configFactory();
foreach ($entities as $entity) {
$config_factory->getEditable($entity)->delete();
}

// XXX: Resave requests to remove the config dependency.
foreach ($requests as $request) {
$request->save();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,20 @@ id: isi_file
label: Create files from rows in the csv.
migration_group: isi
source:
plugin: spreadsheet
source_module: migrate_spreadsheet
# Worksheet nonsensical but required.
worksheet: nada
track_changes: true
file: 'modules/contrib/islandora_spreadsheet_ingest/modules/islandora_spreadsheet_ingest_example/fixtures/migration_example.csv'
header_row: 1
keys:
'ID':
type: integer
columns:
- 'ID'
- 'Digital_File'
migration_tags: []
process:
_file_defined:
- plugin: get
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,22 @@ id: isi_media_audio
label: Create audio media from rows in the csv.
migration_group: isi
source:
plugin: spreadsheet
source_module: migrate_spreadsheet
# Worksheet nonsensical but required.
worksheet: nada
track_changes: true
file: 'modules/contrib/islandora_spreadsheet_ingest/modules/islandora_spreadsheet_ingest_example/fixtures/migration_example.csv'
header_row: 1
keys:
'ID':
type: integer
columns:
- 'ID'
- 'Title'
- 'Model'
- 'Digital_File'
migration_tags: []
process:
_file_exists:
- plugin: get
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,22 @@ id: isi_media_doc
label: Create document media from rows in the csv.
migration_group: isi
source:
plugin: spreadsheet
source_module: migrate_spreadsheet
# Worksheet nonsensical but required.
worksheet: nada
track_changes: true
file: 'modules/contrib/islandora_spreadsheet_ingest/modules/islandora_spreadsheet_ingest_example/fixtures/migration_example.csv'
header_row: 1
keys:
'ID':
type: integer
columns:
- 'ID'
- 'Title'
- 'Model'
- 'Digital_File'
migration_tags: []
process:
_file_exists:
- plugin: get
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,22 @@ id: isi_media_file
label: Create file media from rows in the csv.
migration_group: isi
source:
plugin: spreadsheet
source_module: migrate_spreadsheet
# Worksheet nonsensical but required.
worksheet: nada
track_changes: true
file: 'modules/contrib/islandora_spreadsheet_ingest/modules/islandora_spreadsheet_ingest_example/fixtures/migration_example.csv'
header_row: 1
keys:
'ID':
type: integer
columns:
- 'ID'
- 'Title'
- 'Model'
- 'Digital_File'
migration_tags: []
process:
_file_exists:
- plugin: get
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,22 @@ id: isi_media_image
label: Create image media from rows in the csv.
migration_group: isi
source:
plugin: spreadsheet
source_module: migrate_spreadsheet
# Worksheet nonsensical but required.
worksheet: nada
track_changes: true
file: 'modules/contrib/islandora_spreadsheet_ingest/modules/islandora_spreadsheet_ingest_example/fixtures/migration_example.csv'
header_row: 1
keys:
'ID':
type: integer
columns:
- 'ID'
- 'Title'
- 'Model'
- 'Digital_File'
migration_tags: []
process:
_file_exists:
- plugin: get
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,22 @@ id: isi_media_video
label: Create video media from rows in the csv.
migration_group: isi
source:
plugin: spreadsheet
source_module: migrate_spreadsheet
# Worksheet nonsensical but required.
worksheet: nada
track_changes: true
file: 'modules/contrib/islandora_spreadsheet_ingest/modules/islandora_spreadsheet_ingest_example/fixtures/migration_example.csv'
header_row: 1
keys:
'ID':
type: integer
columns:
- 'ID'
- 'Title'
- 'Model'
- 'Digital_File'
migration_tags: []
process:
_file_exists:
- plugin: get
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,24 @@ id: isi_node
label: Create nodes from rows in the csv.
migration_group: isi
source:
plugin: spreadsheet
source_module: migrate_spreadsheet
# Worksheet nonsensical but required.
worksheet: nada
track_changes: true
file: 'modules/contrib/islandora_spreadsheet_ingest/modules/islandora_spreadsheet_ingest_example/fixtures/migration_example.csv'
header_row: 1
keys:
'ID':
type: integer
columns:
- 'ID'
- 'Title'
- 'Model'
- 'Member_of'
- 'Member_of_existing_entity'
- 'Description'
migration_tags: []
process:
field_model:
- plugin: get
Expand Down
9 changes: 8 additions & 1 deletion src/Entity/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,15 @@ public function getOwner() {
public function calculateDependencies() {
parent::calculateDependencies();

$storage = $this->entityTypeManager()->getStorage('migration');

// XXX: We expect the module to be accounted for in the "migration_group"
// config entity, an so need need deal with it specifically for the
// migration plugin.
foreach (array_column($this->getMappings(), 'original_migration_id') as $original_migration_id) {
$this->addDependency('config', "migrate_plus.migration.{$original_migration_id}");
if ($storage->load($original_migration_id)) {
$this->addDependency('config', "migrate_plus.migration.{$original_migration_id}");
}
}
list($type, $id) = explode(':', $this->getOriginalMapping());
switch ($type) {
Expand Down
5 changes: 3 additions & 2 deletions src/Form/Ingest/FileUpload.php
Original file line number Diff line number Diff line change
Expand Up @@ -300,8 +300,9 @@ protected function mapMappings($mapping) {
*/
protected function mapMappingFromMigrationGroup($id) {
$map_migrations = function ($etm, $mpm) use ($id) {
$storage = $etm->getStorage('migration');
$names = $storage->getQuery()->condition('migration_group', $id)->execute();
$names = array_keys(array_filter($mpm->getDefinitions(), function (array $def) use ($id) {
return ($def['migration_group'] ?? '') === $id;
}));

$migrations = $mpm->createInstances($names);

Expand Down

0 comments on commit d19e2c7

Please sign in to comment.