diff --git a/config/schema/islandora_spreadsheet_ingest.schema.yml b/config/schema/islandora_spreadsheet_ingest.schema.yml index 258d7fa..8f8b697 100644 --- a/config/schema/islandora_spreadsheet_ingest.schema.yml +++ b/config/schema/islandora_spreadsheet_ingest.schema.yml @@ -12,3 +12,66 @@ islandora_spreadsheet_ingest.settings: label: 'Allowed source URI schemes.' sequence: type: string + +islandora_spreadsheet_ingest.request.*: + type: config_entity + mapping: + id: + type: string + label: ID + label: + type: label + label: Label + active: + type: boolean + label: Active + description: If this request should have migrations derived for it. + sheet: + type: mapping + mapping: + file: + # XXX: Really... kind of indicative that these should be pulled out + # to content entities instead of being config entities... the whole + # having-to-reference a file thing... because the "entity:file" + # thing does not appear to work... + #type: entity:file + type: ignore + label: The spreadsheet file to process. + sheet: + type: string + label: The worksheet of the file to process. + mappings: + type: islandora_spreadsheet_ingest.migration_structure + owner: + # XXX: Further reinforcement that these should be pulled out to content + # entities instead of config, because we are relating to the user here. + #type: entity:user + type: ignore + label: The owner's ID; should be either an int or a string. + originalMapping: + type: string + label: | + Reference to the original mapping from which this request was derived. + +islandora_spreadsheet_ingest.migration_structure: + type: mapping + mapping: + original_migration_id: + type: string + label: ID + mappings: + type: sequence + sequence: + type: mapping + mapping: + weight: + type: integer + pipeline: + type: sequence + sequence: + # XXX: The migrate plugin does not define schemas for its plugins, + # nor any obvious mechanism by which to make reference to them... + # migrate_plus _does_ roll a handful, describing the things from + # migrate; however, it is not complete, nor necessarily desirable. + # ... so let's just ignore, for now at least. + type: ignore diff --git a/islandora_spreadsheet_ingest.install b/islandora_spreadsheet_ingest.install index 039f1f7..dd4d4c6 100644 --- a/islandora_spreadsheet_ingest.install +++ b/islandora_spreadsheet_ingest.install @@ -5,121 +5,35 @@ * Installation hooks. */ -use Drupal\Core\Entity\ContentEntityType; -use Drupal\Core\Field\BaseFieldDefinition; -use Drupal\islandora_spreadsheet_ingest\Entity\Request; - /** - * Implements hook_update_last_removed(). + * Drop old, disused tables. */ -function islandora_spreadsheet_ingest_update_last_removed() : int { - return 9001; +function islandora_spreadsheet_ingest_update_8201() { + $schema = \Drupal::service('database')->schema(); + + $tables = [ + 'islandora_spreadsheet_ingest_templates', + 'islandora_spreadsheet_ingest_ingests', + ]; + array_map([$schema, 'dropTable'], $tables); + + return t('Dropped tables.'); } /** - * Replace config entity with content entity. + * Ensure the Islandora Spreadsheet Request ConfigEntityType is installed. */ -function islandora_spreadsheet_ingest_update_9002() : void { +function islandora_spreadsheet_ingest_update_9001() { $upm = \Drupal::entityDefinitionUpdateManager(); + $ent = $upm->getEntityType('isi_request'); + if (is_null($ent)) { + $upm->installEntityType(\Drupal::entityTypeManager() + ->getDefinition('isi_request') + ); - $upm->uninstallEntityType($upm->getEntityType('isi_request')); - - // Much like general schema updates, this needs to include the definition - // inline to be installed, including field definitions, instead of dynamically - // lifting the definitions from the entity type manager in order to be able to - // reliably apply future updates. - $definition = new ContentEntityType([ - "id" => "isi_request", - "label" => \t("Islandora Spreadsheet Ingest Request"), - "handlers" => [ - "storage_schema" => "Drupal\islandora_spreadsheet_ingest\RequestStorageSchema", - "list_builder" => "Drupal\islandora_spreadsheet_ingest\Controller\RequestListBuilder", - "form" => [ - "process" => "Drupal\islandora_spreadsheet_ingest\Form\Ingest\Review", - "add" => "Drupal\islandora_spreadsheet_ingest\Form\Ingest\FileUpload", - "delete" => "Drupal\islandora_spreadsheet_ingest\Form\RequestDeleteForm", - "edit" => "Drupal\islandora_spreadsheet_ingest\Form\Ingest\FileUpload", - "view" => "Drupal\islandora_spreadsheet_ingest\Form\Ingest\Review", - ], - "access" => "Drupal\islandora_spreadsheet_ingest\RequestAccessControlHandler", - "view_builder" => "Drupal\islandora_spreadsheet_ingest\RequestViewBuilder", - ], - "admin_permission" => "administer islandora_spreadsheet_ingest requests", - "base_table" => "islandora_spreadsheet_ingest_request", - "entity_keys" => [ - "id" => "id", - "uuid" => "uuid", - "label" => "label", - "owner" => "uid", - ], - "links" => [ - "canonical" => "/admin/content/islandora_spreadsheet_ingest/{isi_request}", - "process-form" => "/admin/content/islandora_spreadsheet_ingest/{isi_request}/process", - "edit-form" => "/admin/content/islandora_spreadsheet_ingest/{isi_request}/edit", - "map-form" => "/admin/content/islandora_spreadsheet_ingest/{isi_request}/mapping", - "delete-form" => "/admin/content/islandora_spreadsheet_ingest/{isi_request}/delete", - ], - ]); - $fields = []; - $fields['uid'] = BaseFieldDefinition::create('entity_reference') - ->setLabel(\t('User ID')) - ->setSetting('target_type', 'user') - ->setTranslatable(FALSE) - ->setDefaultValueCallback(Request::class . '::getDefaultEntityOwner'); - $fields['label'] = BaseFieldDefinition::create('string') - ->setLabel(\t('Title')) - ->setRequired(TRUE) - ->setTranslatable(FALSE) - ->setRevisionable(FALSE) - ->setSetting('max_length', 255) - ->setDisplayOptions('view', [ - 'label' => 'hidden', - 'type' => 'string', - 'weight' => -5, - ]) - ->setDisplayOptions('form', [ - 'type' => 'string_textfield', - 'weight' => -5, - ]) - ->setDisplayConfigurable('form', TRUE) - ->setCardinality(1); - $fields['machine_name'] = BaseFieldDefinition::create('string') - ->setLabel(\t('Machine Name')) - ->setRequired(TRUE) - ->setTranslatable(FALSE) - ->setRevisionable(FALSE) - ->setCardinality(1) - ->addConstraint('UniqueField', [ - 'message' => 'The machine_name %value is already in use.', - ]); - $fields['active'] = BaseFieldDefinition::create('boolean') - ->setLabel(\t('Label')) - ->setRequired(TRUE) - ->setCardinality(1) - ->setTranslatable(FALSE) - ->setRevisionable(FALSE); - $fields['sheet_file'] = BaseFieldDefinition::create('entity_reference') - ->setLabel(\t('Spreadsheet file')) - ->setRequired(TRUE) - ->setTranslatable(FALSE) - ->setRevisionable(FALSE) - ->setSetting('target_type', 'file') - ->setDisplayOptions('form', [ - 'type' => 'file_generic', - ]) - ->setCardinality(1); - $fields['sheet_sheet'] = BaseFieldDefinition::create('string') - ->setLabel(\t('Worksheet')) - ->setDescription(\t('The specific worksheet if the file corresponds to an ODS/XLSX which is possible of containing multiple.')) - ->setCardinality(1); - $fields['mappings'] = BaseFieldDefinition::create('map') - ->setLabel(\t('Mappings')) - ->setDescription(\t('Migration mappings')) - ->setCardinality(1); - $fields['original_mapping'] = BaseFieldDefinition::create('string') - ->setLabel(\t('Original mapping')) - ->setDescription(\t('Original migration template')) - ->setCardinality(1); - - $upm->installFieldableEntityType($definition, $fields); + return t('The "isi_request" config entity has been installed.'); + } + else { + return t('The "isi_request" config entity is already installed.'); + } } diff --git a/islandora_spreadsheet_ingest.post_update.php b/islandora_spreadsheet_ingest.post_update.php index c887edf..abd0571 100644 --- a/islandora_spreadsheet_ingest.post_update.php +++ b/islandora_spreadsheet_ingest.post_update.php @@ -5,131 +5,6 @@ * Post-update hooks. */ -use Drupal\Core\Utility\UpdateException; -use Drupal\migrate\Plugin\migrate\id_map\Sql; - -/** - * Migrate request entities from config to content. - */ -function islandora_spreadsheet_ingest_post_update_migrate_requests_from_config_to_content_0(array &$sandbox) { - $config_factory = \Drupal::configFactory(); - if (!isset($sandbox['count'])) { - $sandbox['names'] = $config_factory->listAll('islandora_spreadsheet_ingest.request'); - $sandbox['count'] = count($sandbox['names']); - if ($sandbox['count'] === 0) { - return "No entities to migrate."; - } - $sandbox['current'] = 0; - } - - if (!($current = array_pop($sandbox['names']))) { - throw new UpdateException("Unexpectedly failed to get item from array."); - } - - // Create copy of request. - $config = $config_factory->get($current); - /** @var \Drupal\islandora_spreadsheet_ingest\RequestInterface $request */ - $request = \Drupal::entityTypeManager()->getStorage('isi_request')->create([ - 'label' => $config->get('label'), - 'machine_name' => $config->get('id'), - 'sheet_file' => $config->get('sheet')['file'], - 'sheet_sheet' => $config->get('sheet')['sheet'], - 'mappings' => $config->get('mappings'), - 'original_mapping' => $config->get('originalMapping'), - 'owner' => $config->get('owner'), - 'active' => $config->get('active'), - ]); - $request->save(); - - // Copy ID map and messages tables to the new entities, as those - // associated with the old should be deleted in the next phase. - $source_mg_name = "isi__{$config->get('id')}"; - $dest_mg_name = \Drupal::service('islandora_spreadsheet_ingest.migration_group_deriver')->deriveName($request); - /** @var \Drupal\migrate\Plugin\MigrationPluginManagerInterface $migration_plugin_manager */ - $migration_plugin_manager = \Drupal::service('plugin.manager.migration'); - foreach (array_keys($request->getMappings()) as $name) { - $source_migration_id = "{$source_mg_name}_{$name}"; - $dest_migration_id = "{$dest_mg_name}_{$name}"; - /** @var \Drupal\migrate\Plugin\MigrationInterface $source_migration */ - $source_migration = $migration_plugin_manager->createInstance($source_migration_id); - /** @var \Drupal\migrate\Plugin\MigrationInterface $dest_migration */ - $dest_migration = $migration_plugin_manager->createInstance($dest_migration_id); - $source_id_map = $source_migration->getIdMap(); - $dest_id_map = $dest_migration->getIdMap(); - if (!($source_id_map instanceof Sql)) { - continue; - } - if (!($dest_id_map instanceof Sql)) { - continue; - } - - // XXX: Calling Sql::getDatabase() presently initializes things, to ensure - // that the relevant tables exist. - $source_id_map->getDatabase(); - $database = $dest_id_map->getDatabase(); - - $database->insert($dest_id_map->mapTableName()) - ->from( - $database->select($source_id_map->mapTableName(), 'm') - ->fields('m') - ) - ->execute(); - $database->insert($dest_id_map->messageTableName()) - ->from( - $database->select($source_id_map->messageTableName(), 'm') - ->fields('m') - ) - ->execute(); - } - - $sandbox['#finished'] = ++$sandbox['current'] / $sandbox['count']; -} - -/** - * Delete disused request config entities. - */ -function islandora_spreadsheet_ingest_post_update_migrate_requests_from_config_to_content_1(array &$sandbox) { - $config_factory = \Drupal::configFactory(); - if (!isset($sandbox['count'])) { - $sandbox['names'] = $config_factory->listAll('islandora_spreadsheet_ingest.request'); - $sandbox['count'] = count($sandbox['names']); - if ($sandbox['count'] === 0) { - return "No entities to delete."; - } - $sandbox['current'] = 0; - } - - if (!($current = array_pop($sandbox['names']))) { - throw new UpdateException("Unexpectedly failed to get item from array."); - } - - $config = $config_factory->getEditable($current); - - $file_usage_service = \Drupal::service('file.usage'); - $file_service = \Drupal::service('entity_type.manager')->getStorage('file'); - $fids = $config->get('sheet')['file']; - if ($fids && ($file = $file_service->load(reset($fids)))) { - $file_usage_service->delete( - $file, - 'islandora_spreadsheet_ingest', - 'isi_request', - $config->get('id'), - ); - } - $source_mg_name = "isi__{$config->get('id')}"; - /** @var \Drupal\migrate\Plugin\MigrationPluginManagerInterface $migration_plugin_manager */ - $migration_plugin_manager = \Drupal::service('plugin.manager.migration'); - foreach (array_keys($config->get('mappings')) as $name) { - $source_migration_id = "{$source_mg_name}_{$name}"; - /** @var \Drupal\migrate\Plugin\MigrationInterface $source_migration */ - $source_migration = $migration_plugin_manager->createInstance($source_migration_id); - $source_migration->getIdMap()->destroy(); - } - - $config->delete(); - $sandbox['#finished'] = ++$sandbox['current'] / $sandbox['count']; -} - /** * Set a value for islandora_spreadsheet_ingest.settings:schemes, if unset. */ diff --git a/islandora_spreadsheet_ingest.routing.yml b/islandora_spreadsheet_ingest.routing.yml index dfe8801..4609ac6 100644 --- a/islandora_spreadsheet_ingest.routing.yml +++ b/islandora_spreadsheet_ingest.routing.yml @@ -20,10 +20,6 @@ entity.isi_request.edit_form: _entity_form: 'isi_request.edit' requirements: _entity_access: 'isi_request.update' - options: - parameters: - isi_request: - type: islandora_spreadsheet_ingest_request entity.isi_request.delete_form: path: '/admin/content/islandora_spreadsheet_ingest/{isi_request}/delete' defaults: @@ -31,20 +27,12 @@ entity.isi_request.delete_form: _entity_form: 'isi_request.delete' requirements: _entity_access: 'isi_request.delete' - options: - parameters: - isi_request: - type: islandora_spreadsheet_ingest_request entity.isi_request.canonical: path: '/admin/content/islandora_spreadsheet_ingest/{isi_request}' defaults: _entity_view: 'isi_request.full' requirements: _entity_access: 'isi_request.view' - options: - parameters: - isi_request: - type: islandora_spreadsheet_ingest_request entity.isi_request.process_form: path: '/admin/content/islandora_spreadsheet_ingest/{isi_request}/process' defaults: @@ -52,10 +40,6 @@ entity.isi_request.process_form: _entity_form: 'isi_request.process' requirements: _entity_access: 'isi_request.activate' - options: - parameters: - isi_request: - type: islandora_spreadsheet_ingest_request islandora_spreadsheet_ingest.admin: path: '/admin/config/islandora_spreadsheet_ingest' defaults: diff --git a/islandora_spreadsheet_ingest.services.yml b/islandora_spreadsheet_ingest.services.yml index 5063510..a140abe 100644 --- a/islandora_spreadsheet_ingest.services.yml +++ b/islandora_spreadsheet_ingest.services.yml @@ -33,13 +33,6 @@ services: arguments: - isi_deferred_ingest - true - islandora_spreadsheet_ingest.param_converter.request: - class: Drupal\islandora_spreadsheet_ingest\Routing\RequestParamConverter - factory: [null, 'create'] - arguments: - - '@service_container' - tags: - - { name: paramconverter } islandora_spreadsheet_ingest.event_subscriber.config_transform: class: Drupal\islandora_spreadsheet_ingest\EventSubscriber\ConfigTransformationEventSubscriber factory: [null, 'create'] diff --git a/src/Controller/RequestListBuilder.php b/src/Controller/RequestListBuilder.php index 3795f4d..8f475d8 100644 --- a/src/Controller/RequestListBuilder.php +++ b/src/Controller/RequestListBuilder.php @@ -2,8 +2,8 @@ namespace Drupal\islandora_spreadsheet_ingest\Controller; +use Drupal\Core\Config\Entity\ConfigEntityListBuilder; use Drupal\Core\Entity\EntityInterface; -use Drupal\Core\Entity\EntityListBuilder; use Drupal\Core\Entity\EntityTypeInterface; use Drupal\Core\Link; use Drupal\islandora_spreadsheet_ingest\Entity\Request; @@ -12,7 +12,7 @@ /** * Request config entity list builder. */ -class RequestListBuilder extends EntityListBuilder { +class RequestListBuilder extends ConfigEntityListBuilder { /** * The migration group deriver service. diff --git a/src/Entity/Request.php b/src/Entity/Request.php index 61ce8aa..f6fb2e1 100644 --- a/src/Entity/Request.php +++ b/src/Entity/Request.php @@ -2,21 +2,16 @@ namespace Drupal\islandora_spreadsheet_ingest\Entity; -use Drupal\Core\Entity\ContentEntityBase; -use Drupal\Core\Entity\EntityTypeInterface; -use Drupal\Core\Field\BaseFieldDefinition; +use Drupal\Core\Config\Entity\ConfigEntityBase; use Drupal\islandora_spreadsheet_ingest\RequestInterface; -use Drupal\user\EntityOwnerInterface; -use Drupal\user\EntityOwnerTrait; /** * Defines the Request entity. * - * @ContentEntityType( + * @ConfigEntityType( * id = "isi_request", * label = @Translation("Islandora Spreadsheet Ingest Request"), * handlers = { - * "storage_schema" = "Drupal\islandora_spreadsheet_ingest\RequestStorageSchema", * "list_builder" = "Drupal\islandora_spreadsheet_ingest\Controller\RequestListBuilder", * "form" = { * "process" = "Drupal\islandora_spreadsheet_ingest\Form\Ingest\Review", @@ -28,13 +23,20 @@ * "access" = "Drupal\islandora_spreadsheet_ingest\RequestAccessControlHandler", * "view_builder" = "Drupal\islandora_spreadsheet_ingest\RequestViewBuilder", * }, + * config_prefix = "request", * admin_permission = "administer islandora_spreadsheet_ingest requests", - * base_table = "islandora_spreadsheet_ingest_request", * entity_keys = { * "id" = "id", - * "uuid" = "uuid", * "label" = "label", - * "owner" = "owner", + * }, + * config_export = { + * "id", + * "label", + * "sheet", + * "originalMapping", + * "mappings", + * "active", + * "owner", * }, * links = { * "canonical" = "/admin/content/islandora_spreadsheet_ingest/{isi_request}", @@ -45,129 +47,139 @@ * } * ) */ -class Request extends ContentEntityBase implements EntityOwnerInterface, RequestInterface { +class Request extends ConfigEntityBase implements RequestInterface { - use EntityOwnerTrait { - getOwner as traitGetOwner; - } + /** + * The ID of the request. + * + * @var string + */ + protected $id; + + /** + * The request's label. + * + * @var string + */ + protected $label; + + /** + * Coordinates for where to find the particular worksheet. + * + * Includes: + * - sheet: The name of the worksheet. + * - file: An array of file IDs... though there should just be one. + * + * @var array + */ + protected $sheet; + + /** + * A representation of the original mapping. + * + * Should only ever be a "migration_group:*" kind of thing... + * + * @var string + */ + protected $originalMapping = 'migration_group:isi'; + + /** + * The associative array of mappings. + * + * Mapping migration names to: + * - original_migration_id: The name of the original migration + * - mappings: An associative array mapping field/property names to an + * associative array containing: + * - pipeline: The array of process plugin definitions. + * + * May be NULL if not yet set. + * + * @var array|null + */ + protected $mappings = NULL; + + /** + * Whether this request should be eligible to be processed. + * + * @var bool + * + * @todo Review whether or not the core ConfigEntityBase's "status" may cover + * the same situation. + */ + protected $active = FALSE; + + /** + * The creator/owner of this request. + * + * @var string + */ + protected $owner = NULL; /** * {@inheritdoc} */ public function getOriginalMapping() { - return $this->get('original_mapping')->getString(); + return $this->originalMapping; } /** * {@inheritdoc} */ public function getActive() { - return $this->get('active')->first()->getValue()['value']; + return $this->active; } /** * {@inheritdoc} */ public function getSheet() { - return [ - 'file' => [$this->get('sheet_file')->first()->getString()], - 'sheet' => $this->get('sheet_sheet')->first()->getString(), - ]; + return $this->sheet; } /** * {@inheritdoc} */ public function getMappings() { - return $this->get('mappings')->first()->getValue(); + return $this->mappings; } /** * {@inheritdoc} */ public function getOwner() { - return $this->traitGetOwner()->id(); + return $this->owner; } /** - * {@inheritDoc} + * {@inheritdoc} */ - public function set($name, $value, $notify = TRUE) { - if ($name === 'sheet') { - \trigger_deprecation('discoverygarden/islandora_spreadsheet_ingest', '4.0.0', 'Setting `sheet` directly is deprecated as of 4.0.0; instead set `sheet_file` and `sheet_sheet` individually.'); - return $this->set('sheet_file', $value['file'] ?? [], $notify) - ->set('sheet_sheet', $value['sheet'] ?? '', $notify); + 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) { + if ($storage->load($original_migration_id)) { + $this->addDependency('config', "migrate_plus.migration.{$original_migration_id}"); + } } - if ($name === 'originalMapping') { - \trigger_deprecation('discoverygarden/islandora_spreadsheet_ingest', '4.0.0', '`originalMapping` has been renamed to `original_mapping` as of 4.0.0.'); - return $this->set('original_mapping', $value, $notify); + [$type, $id] = explode(':', $this->getOriginalMapping()); + switch ($type) { + case 'migration_group': + $this->addDependency('config', "migrate_plus.migration_group.{$id}"); + break; + + default: + throw new Exception(strtr('Unknown type of original mapping: "!type"', [ + '!type' => $type, + ])); + } - return parent::set($name, $value, $notify); - } - /** - * {@inheritDoc} - */ - public static function baseFieldDefinitions(EntityTypeInterface $entity_type) { - $fields = parent::baseFieldDefinitions($entity_type); - $fields += static::ownerBaseFieldDefinitions($entity_type); - - $fields['label'] = BaseFieldDefinition::create('string') - ->setLabel(\t('Title')) - ->setRequired(TRUE) - ->setTranslatable(FALSE) - ->setRevisionable(FALSE) - ->setSetting('max_length', 255) - ->setDisplayOptions('view', [ - 'label' => 'hidden', - 'type' => 'string', - 'weight' => -5, - ]) - ->setDisplayOptions('form', [ - 'type' => 'string_textfield', - 'weight' => -5, - ]) - ->setDisplayConfigurable('form', TRUE) - ->setCardinality(1); - $fields['machine_name'] = BaseFieldDefinition::create('string') - ->setLabel(\t('Machine Name')) - ->setRequired(TRUE) - ->setTranslatable(FALSE) - ->setRevisionable(FALSE) - ->setCardinality(1) - ->addConstraint('UniqueField', [ - 'message' => 'The machine_name %value is already in use.', - ]); - $fields['active'] = BaseFieldDefinition::create('boolean') - ->setLabel(\t('Label')) - ->setRequired(TRUE) - ->setCardinality(1) - ->setTranslatable(FALSE) - ->setRevisionable(FALSE); - $fields['sheet_file'] = BaseFieldDefinition::create('entity_reference') - ->setLabel(\t('Spreadsheet file')) - ->setRequired(TRUE) - ->setTranslatable(FALSE) - ->setRevisionable(FALSE) - ->setSetting('target_type', 'file') - ->setDisplayOptions('form', [ - 'type' => 'file_generic', - ]) - ->setCardinality(1); - $fields['sheet_sheet'] = BaseFieldDefinition::create('string') - ->setLabel(\t('Worksheet')) - ->setDescription(\t('The specific worksheet if the file corresponds to an ODS/XLSX which is possible of containing multiple.')) - ->setCardinality(1); - $fields['mappings'] = BaseFieldDefinition::create('map') - ->setLabel(\t('Mappings')) - ->setDescription(\t('Migration mappings')) - ->setCardinality(1); - $fields['original_mapping'] = BaseFieldDefinition::create('string') - ->setLabel(\t('Original mapping')) - ->setDescription(\t('Original migration template')) - ->setCardinality(1); - - return $fields; + return $this; } } diff --git a/src/EventSubscriber/ConfigTransformationEventSubscriber.php b/src/EventSubscriber/ConfigTransformationEventSubscriber.php index ed3a6f4..b867d6a 100644 --- a/src/EventSubscriber/ConfigTransformationEventSubscriber.php +++ b/src/EventSubscriber/ConfigTransformationEventSubscriber.php @@ -17,9 +17,6 @@ */ class ConfigTransformationEventSubscriber implements EventSubscriberInterface, ContainerInjectionInterface { - const MIGRATION_GROUP_PREFIX = 'migrate_plus.migration_group.isi__'; - const MIGRATION_PREFIX = 'migrate_plus.migration.isi__'; - /** * Constructor. */ @@ -93,9 +90,10 @@ public function onImportTransform(StorageTransformEvent $event) : void { * @return \Generator * The names of the configs that should never be changed on imports/exports. */ - protected function toIgnore(StorageInterface $storage) { - yield from $storage->listAll(static::MIGRATION_PREFIX); - yield from $storage->listAll(static::MIGRATION_GROUP_PREFIX); + protected function toIgnore(StorageInterface $storage) : \Generator { + yield from $storage->listAll('migrate_plus.migration.isi__'); + yield from $storage->listAll('migrate_plus.migration_group.isi__'); + yield from $storage->listAll('islandora_spreadsheet_ingest.request.'); } } diff --git a/src/Form/Ingest/FileUpload.php b/src/Form/Ingest/FileUpload.php index 2128cf4..52d13bb 100644 --- a/src/Form/Ingest/FileUpload.php +++ b/src/Form/Ingest/FileUpload.php @@ -174,9 +174,9 @@ public function form(array $form, FormStateInterface $form_state) { '#description' => $this->t("Label for the Example."), '#required' => TRUE, ]; - $form['machine_name'] = [ + $form['id'] = [ '#type' => 'machine_name', - '#default_value' => $entity->get('machine_name')->getString(), + '#default_value' => $entity->id(), '#disabled' => !$entity->isNew(), '#machine_name' => [ 'exists' => [$this, 'exist'], @@ -261,15 +261,14 @@ protected function builder($entity_type_id, RequestInterface $request, array &$f // Copy/transform the info from the target. [$original, $mapped] = $this->mapMappings($request->getOriginalMapping()); $request->set('mappings', $mapped); - $request->set('original_mapping', $original); - $request->set( - 'sheet_file', - $form_state->getValue(['sheet', 'file', 'fids']) ?? $form_state->getValue(['sheet', 'file']), - ); - $request->set('sheet_sheet', $form_state->getValue(['sheet', 'sheet'])); + $request->set('originalMapping', $original); + $request->set('sheet', [ + 'file' => ($form_state->getValue(['sheet', 'file', 'fids']) ?? + $form_state->getValue(['sheet', 'file'])), + 'sheet' => $form_state->getValue(['sheet', 'sheet']), + ]); $request->set('owner', $this->currentUser()->id()); $request->set('active', TRUE); - $request->set('machine_name', $form_state->getValue('machine_name')); } /** @@ -307,7 +306,7 @@ public function exist($id) { // existence of other requests; however, unsure if we are particularly // concerned. ->accessCheck(FALSE) - ->condition('machine_name', $id) + ->condition('id', $id) ->execute(); return (bool) $entity; } diff --git a/src/MigrationDeriver.php b/src/MigrationDeriver.php index 52a0505..77d5a5e 100644 --- a/src/MigrationDeriver.php +++ b/src/MigrationDeriver.php @@ -175,12 +175,11 @@ protected function deriveMigrationName($mg_name, $target) { * TRUE if it is the same; otherwise, FALSE. */ protected function sameMigrationGroup(MigrationInterface $mig, $target) { + /** @var \Drupal\migrate\Plugin\MigrationInterface $loaded_target */ $loaded_target = $this->migrationPluginManager->createInstance($target); - // XXX: General getters were deprecated and removed in: - // https://www.drupal.org/node/2873795. Given how migrate_plus injects - // the group need to get it without it. - $mg = $loaded_target->migration_group; - return $mg && $mg == $mig->migration_group; + + $mg = $loaded_target->getPluginDefinition()['migration_group'] ?? FALSE; + return $mg && ($mg === ($mig->getPluginDefinition()['migration_group'] ?? FALSE)); } const SUBPROCESSING_PLUGINS = [ @@ -275,7 +274,7 @@ protected function mapPipelineMigrations(array $processes, MigrationInterface $m * {@inheritdoc} */ public function createAll(RequestInterface $request) { - if (!$request->getActive()) { + if (!$request->status() || !$request->getActive()) { $this->logger->info('Call to create on non-active request {id}.', ['id' => $request->id()]); return; } @@ -286,6 +285,7 @@ public function createAll(RequestInterface $request) { foreach ($request->getMappings() as $name => $info) { $original_migration = $this->migrationPluginManager->createInstance($info['original_migration_id']); + assert($original_migration instanceof MigrationInterface); $derived_name = $this->deriveMigrationName($mg_name, $name); $source_config = $original_migration->getSourceConfiguration(); $info = [ diff --git a/src/RequestInterface.php b/src/RequestInterface.php index b0c44cf..078f3d9 100644 --- a/src/RequestInterface.php +++ b/src/RequestInterface.php @@ -2,12 +2,12 @@ namespace Drupal\islandora_spreadsheet_ingest; -use Drupal\Core\Entity\ContentEntityInterface; +use Drupal\Core\Config\Entity\ConfigEntityInterface; /** * Request content entity interface. */ -interface RequestInterface extends ContentEntityInterface { +interface RequestInterface extends ConfigEntityInterface { /** * Get the sheet to process. diff --git a/src/RequestStorageSchema.php b/src/RequestStorageSchema.php deleted file mode 100644 index 5be0c5b..0000000 --- a/src/RequestStorageSchema.php +++ /dev/null @@ -1,32 +0,0 @@ -getName(); - - if ($table_name === $this->storage->getBaseTable()) { - if ($field_name === 'machine_name') { - $this->addSharedTableFieldUniqueKey($storage_definition, $schema); - } - elseif ($field_name === 'active') { - $this->addSharedTableFieldIndex($storage_definition, $schema); - } - } - - return $schema; - } - -} diff --git a/src/Routing/RequestParamConverter.php b/src/Routing/RequestParamConverter.php deleted file mode 100644 index 4451035..0000000 --- a/src/Routing/RequestParamConverter.php +++ /dev/null @@ -1,59 +0,0 @@ -get('entity_type.manager'), - ); - } - - /** - * {@inheritDoc} - */ - public function convert($value, $definition, $name, array $defaults) { - $request_storage = $this->entityTypeManager->getStorage('isi_request'); - if (is_numeric($value) && ($request = $request_storage->load($value))) { - return $request; - } - if ($requests = $request_storage->loadByProperties(['machine_name' => $value])) { - return reset($requests); - } - - return NULL; - } - - /** - * {@inheritDoc} - */ - public function applies($definition, $name, Route $route) { - return isset($definition['type']) && $definition['type'] === 'islandora_spreadsheet_ingest_request'; - } - -}