Skip to content

Commit

Permalink
Move plugin into the FOXML submodule, and update docs.
Browse files Browse the repository at this point in the history
  • Loading branch information
adam-vessey committed Sep 18, 2024
1 parent 01b7691 commit 725d9f6
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 7 deletions.
8 changes: 8 additions & 0 deletions modules/dgi_migrate_foxml_standard_mods/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,14 @@ further information.

The migration can be run using the `foxml_to_dgis` migration group.

## Configuration

### Environment variables

| Variable | Default | Description |
| --- |----------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `DGI_MIGRATE_FOXML_STANDARD_MODS_FILE_METHOD` | (unset, defaults to `copy`) | To `copy` or attempt to reference files `direct`ly. Despite configuration, copying will be forced for URIs referencing parts of base64 encoded archival FOXML. |

## Troubleshooting/Issues

Having problems or solved a problem? Contact
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ process:
- '@_ext'
delimiter: '.'
uri:
- plugin: dgi_migrate.foxml_file
- plugin: dgi_migrate_foxml_standard_mods.foxml_file
source: '@_source_uri'
destination: constants/file_dest
date: '@created'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ process:
- '@_ext'
delimiter: '.'
uri:
- plugin: dgi_migrate.foxml_file
- plugin: dgi_migrate_foxml_standard_mods.foxml_file
source: '@_source_uri'
destination: constants/file_dest
date: '@created'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
<?php

namespace Drupal\dgi_migrate\Plugin\migrate\process;
namespace Drupal\dgi_migrate_foxml_standard_mods\Plugin\migrate\process;

use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\Core\StreamWrapper\StreamWrapperManagerInterface;
use Drupal\dgi_migrate\Plugin\migrate\process\EnsureNonWritableTrait;
use Drupal\migrate\MigrateExecutableInterface;
use Drupal\migrate\Plugin\MigrateProcessInterface;
use Drupal\migrate\Plugin\MigrationInterface;
Expand All @@ -16,15 +18,16 @@
* Accepts:
* - method: One of "copy" (to copy the file) or "direct" (to directly use the
* file). Defaults to "copy". Can be set with the DGI_MIGRATE_FILE_METHOD
* environment variable.
* environment variable. Will be forced to "copy" if the value for "source"
* is not of the "foxml://" scheme.
* - destination: Property in the row containing the destination, to build out
* a destination path if copying.
* - date: Property in the row containing a date with which to build a path in
* the destination, when copying.
* - filename: Property in the row containing a filename.
*
* @MigrateProcessPlugin(
* id = "dgi_migrate.foxml_file"
* id = "dgi_migrate_foxml_standard_mods.foxml_file"
* )
*/
class FoxmlFile extends ProcessPluginBase implements ContainerFactoryPluginInterface {
Expand All @@ -40,6 +43,7 @@ public function __construct(
$plugin_definition,
protected ?MigrationInterface $migration,
protected MigrateProcessInterface $naiveCopyPlugin,
protected StreamWrapperManagerInterface $streamWrapperManager,
) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
}
Expand All @@ -48,7 +52,7 @@ public function __construct(
* {@inheritDoc}
*/
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition, MigrationInterface $migration = NULL) {
$configuration['method'] ??= getenv('DGI_MIGRATE_FILE_METHOD') ?: 'copy';
$configuration['method'] ??= getenv('DGI_MIGRATE_FOXML_STANDARD_MODS_FILE_METHOD') ?: 'copy';
assert(in_array($configuration['method'], ['copy', 'direct']));
/** @var \Drupal\migrate\Plugin\MigratePluginManagerInterface $process_plugin_manager */
$process_plugin_manager = $container->get('plugin.manager.migrate.process');
Expand All @@ -62,14 +66,25 @@ public static function create(ContainerInterface $container, array $configuratio
'move' => FALSE,
'file_exists' => 'rename',
], $migration),
$container->get('stream_wrapper_manager'),
);
}

/**
* {@inheritDoc}
*/
public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) {
return match ($this->configuration['method']) {
$method = $this->configuration['method'];
if ($this->streamWrapperManager::getScheme($value) !== 'foxml') {
// XXX: If not "foxml://", force to "copy", as it is probably from
// archival FOXML, and we do not want to allow for the possibility of
// continuous base 64 decoding of datastreams that might entail, nor is
// there an an endpoint to support directly serving "php://filter" URIs
// nor "foxml.substream://" stream wrappers associated with doing so.
$method = 'copy';
}

return match ($method) {
'copy' => $this->naiveCopyPlugin->transform(
[
$value,
Expand Down

0 comments on commit 725d9f6

Please sign in to comment.