diff --git a/README.md b/README.md index 9d0f9cf..87cce03 100644 --- a/README.md +++ b/README.md @@ -19,8 +19,7 @@ Note: using drush with migrate_tools is optional, but the instructions assume it 0. Copy the data directory to your drupal web root (e.g. in my tests the drupal web root is `/var/www/drupalvm/drupal/web` and the data directory is `/var/www/drupalvm/drupal/web/data`). 0. Copy the migrate_cdm and unlv_image directories to your modules directory. 0. Enable the modules. E.g. `drush en -y migrate_tools migrate_apollo`. -0. Run the migration. E.g. `drush -l http://localhost:8000 mim --all`. *Note: drush must be run by the webserver user because the claw_file migration copies files to the "public://directory". E.g.* `sudo -u www-data drush -l http://localhost:8000 mim --all` *if you are using vagrant.* -0. Generate service images. *Still addressing issues with service file generation. Until we figure out that problem you will need to do it yourself by going to the content page, selecting all the items you migrated, and then use the "Generate a service file from image preservation master". This will trigger both the service image and, as a chain reaction, the thumbnail generation.* +0. Run the migration. E.g. `drush -l http://localhost:8000 mim --userid=1 --all`. *Note: drush must be run by the webserver user because the claw_file migration copies files to the "public://directory". E.g.* `sudo -u www-data drush -l http://localhost:8000 mim --userid=1 --all` *if you are using vagrant. Also, the userid flag is specific to the migrate:import command, it provides the necessary user information to the JWT authentication to enable derivatives.* 0. See a wonderful list of the newly migrated images on your Drupal site's front page! # Combining People and Subject entities in a single column diff --git a/migrate_apollo/config/install/migrate_plus.migration.claw_image.yml b/migrate_apollo/config/install/migrate_plus.migration.claw_image.yml index 6678eed..d4bc83d 100644 --- a/migrate_apollo/config/install/migrate_plus.migration.claw_image.yml +++ b/migrate_apollo/config/install/migrate_plus.migration.claw_image.yml @@ -20,6 +20,7 @@ source: constants: collection_alias: 'apollo' image: 'Image' + uid: 1 # UID of Admin user, may be changed to uid of someone with permission to create items column_names: 0: digital_id: 'Digital ID' @@ -41,6 +42,7 @@ process: default_value: unlv_image # One-to-One mappings + uid: constants/uid field_digital_id: digital_id title: title field_description: description diff --git a/migrate_apollo/config/install/migrate_plus.migration.claw_media.yml b/migrate_apollo/config/install/migrate_plus.migration.claw_media.yml index a05bad8..7b6251b 100644 --- a/migrate_apollo/config/install/migrate_plus.migration.claw_media.yml +++ b/migrate_apollo/config/install/migrate_plus.migration.claw_media.yml @@ -16,6 +16,7 @@ source: - digital_id constants: preservation_master: 'Preservation Master' + uid: 1 # UID of Admin user, may be changed to uid of someone with permission to create items column_names: 0: digital_id: 'Digital ID' # identifier key @@ -27,6 +28,8 @@ process: source: digital_id no_stub: true + uid: constants/uid + # Lookup the Tiff we just migrated field_media_file/target_id: plugin: migration_lookup diff --git a/migrate_apollo/drush.services.yml b/migrate_apollo/drush.services.yml new file mode 100644 index 0000000..d98f11a --- /dev/null +++ b/migrate_apollo/drush.services.yml @@ -0,0 +1,5 @@ +services: + migrate_apollo.commands: + class: \Drupal\migrate_apollo\Commands\MigrateApolloCommands + tags: + - { name: drush.command } diff --git a/migrate_apollo/src/Commands/MigrateApolloCommands.php b/migrate_apollo/src/Commands/MigrateApolloCommands.php new file mode 100644 index 0000000..a6d0e8c --- /dev/null +++ b/migrate_apollo/src/Commands/MigrateApolloCommands.php @@ -0,0 +1,83 @@ + self::REQ]) + { + } + + /** + * @hook validate migrate:import + */ + public function validateUser(CommandData $commandData) + { + $userid = $commandData->input()->getOption('userid'); + if($userid) + { + $account = \Drupal\user\Entity\User::load($userid); + if (!$account) { + throw new \Exception("User ID does not match an existing user."); + } + } + } + + /** + * @hook pre-command migrate:import + */ + public function preImport(CommandData $commandData) + { + // + $userid = $commandData->input()->getOption('userid'); + if ($userid) + { + $account = \Drupal\user\Entity\User::load($userid); + $accountSwitcher = \Drupal::service('account_switcher'); + $userSession = new UserSession([ + 'uid' => $account->id(), + 'name'=>$account->getUsername(), + 'roles'=>$account->getRoles() + ]); + $accountSwitcher->switchTo($userSession); + $this->logger()->notice( + dt( + 'Now acting as user ID @id', + ['@id'=>\Drupal::currentUser()->id()] + ) + ); + } + } + + /** + * @hook post-command migrate:import + */ + public function postImport($result, CommandData $commandData) + { + if ($commandData->input()->getOption('userid')) + { + $accountSwitcher = \Drupal::service('account_switcher'); + $this->logger()->notice(dt( + 'Switching back from user @uid.', + ['@uid'=>\Drupal::currentUser()->id()] + )); + $accountSwitcher->switchBack(); + } + } +}