Skip to content

Commit

Permalink
Fix copy control.
Browse files Browse the repository at this point in the history
  • Loading branch information
adam-vessey committed Sep 18, 2024
1 parent 514b7a5 commit 01b7691
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 6 deletions.
19 changes: 14 additions & 5 deletions src/Plugin/migrate/process/FoxmlFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,11 @@ public static function create(ContainerInterface $container, array $configuratio
$plugin_id,
$plugin_definition,
$migration,
$process_plugin_manager->createInstance('dgi_migrate.naive_file_copy', [], $migration),
$process_plugin_manager->createInstance('dgi_migrate.naive_file_copy', [
'force_stub' => TRUE,
'move' => FALSE,
'file_exists' => 'rename',
], $migration),
);
}

Expand All @@ -66,10 +70,15 @@ public static function create(ContainerInterface $container, array $configuratio
*/
public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) {
return match ($this->configuration['method']) {
'copy' => $this->naiveCopyPlugin->transform([
$value,
$this->getDestinationPath($row),
], $migrate_executable, $row, $destination_property),
'copy' => $this->naiveCopyPlugin->transform(
[
$value,
$this->getDestinationPath($row),
],
$migrate_executable,
$row,
$destination_property,
),
'direct' => static::ensureNonWritable($value),
};
}
Expand Down
14 changes: 13 additions & 1 deletion src/Plugin/migrate/process/NaiveFileCopy.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@
* The core "file_copy" is rather opinionated, complicating the use of the
* php:// scheme.
*
* Extends "file_copy", additionally accepting:
* - force_stub: Boolean to force the copying when the row being processed
* appears to be a stub.
*
* @MigrateProcessPlugin(
* id = "dgi_migrate.naive_file_copy"
* )
Expand All @@ -33,13 +37,21 @@ class NaiveFileCopy extends FileCopy implements ContainerFactoryPluginInterface
*/
protected $migrateConfig;

/**
* Boolean if we should force copying when the row is a stub.
*
* @var bool
*/
protected bool $forceStub;

/**
* Constructor.
*/
public function __construct(array $configuration, $plugin_id, array $plugin_definition, StreamWrapperManagerInterface $stream_wrappers, FileSystemInterface $file_system, MigrateProcessInterface $download_plugin, ConfigFactoryInterface $config_factory) {
parent::__construct($configuration, $plugin_id, $plugin_definition, $stream_wrappers, $file_system, $download_plugin);

$this->migrateConfig = $config_factory->get('dgi_migrate.settings');
$this->forceStub = $this->configuration['force_stub'] ?? FALSE;
}

/**
Expand All @@ -63,7 +75,7 @@ public static function create(ContainerInterface $container, array $configuratio
public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) {
// If we're stubbing a file entity, return a URI of NULL so it will get
// stubbed by the general process.
if ($row->isStub()) {
if (!$this->forceStub && $row->isStub()) {
return NULL;
}
[$source, $destination] = $value;
Expand Down

0 comments on commit 01b7691

Please sign in to comment.