X-Git-Url: http://aleph1.co.uk/gitweb/?a=blobdiff_plain;f=web%2Fcore%2Fmodules%2Fmigrate%2Fsrc%2FPlugin%2Fmigrate%2Fprocess%2FFileCopy.php;h=88f22123224253f4ced725ab106909ce1bb7e770;hb=1c1cb0980bfa6caf0c24cce671b6bb541dc87583;hp=f24131244f9735aa7984b9d98c417c33a2519faa;hpb=a2bd1bf0c2c1f1a17d188f4dc0726a45494cefae;p=yaffs-website diff --git a/web/core/modules/migrate/src/Plugin/migrate/process/FileCopy.php b/web/core/modules/migrate/src/Plugin/migrate/process/FileCopy.php index f24131244..88f221232 100644 --- a/web/core/modules/migrate/src/Plugin/migrate/process/FileCopy.php +++ b/web/core/modules/migrate/src/Plugin/migrate/process/FileCopy.php @@ -9,7 +9,6 @@ use Drupal\Core\StreamWrapper\StreamWrapperManagerInterface; use Drupal\migrate\MigrateException; use Drupal\migrate\MigrateExecutableInterface; use Drupal\migrate\Plugin\MigrateProcessInterface; -use Drupal\migrate\ProcessPluginBase; use Drupal\migrate\Row; use Symfony\Component\DependencyInjection\ContainerInterface; @@ -19,19 +18,19 @@ use Symfony\Component\DependencyInjection\ContainerInterface; * The file can be moved, reused, or set to be automatically renamed if a * duplicate exists. * - * The source value is an array of two values: - * - source: The source path or URI, e.g. '/path/to/foo.txt' or - * 'public://bar.txt'. - * - destination: The destination path or URI, e.g. '/path/to/bar.txt' or - * 'public://foo.txt'. + * The source value is an indexed array of two values: + * - The source path or URI, e.g. '/path/to/foo.txt' or 'public://bar.txt'. + * - The destination URI, e.g. 'public://foo.txt'. * * Available configuration keys: * - move: (optional) Boolean, if TRUE, move the file, otherwise copy the file. * Defaults to FALSE. - * - rename: (optional) Boolean, if TRUE, rename the file by appending a number - * until the name is unique. Defaults to FALSE. - * - reuse: (optional) Boolean, if TRUE, reuse the current file in its existing - * location rather than move/copy/rename the file. Defaults to FALSE. + * - file_exists: (optional) Replace behavior when the destination file already + * exists: + * - 'replace' - (default) Replace the existing file. + * - 'rename' - Append _{incrementing number} until the filename is + * unique. + * - 'use existing' - Do nothing and return FALSE. * * Examples: * @@ -39,8 +38,9 @@ use Symfony\Component\DependencyInjection\ContainerInterface; * process: * path_to_file: * plugin: file_copy - * source: /path/to/file.png - * destination: /new/path/to/file.png + * source: + * - /path/to/file.png + * - public://new/path/to/file.png * @endcode * * @see \Drupal\migrate\Plugin\MigrateProcessInterface @@ -49,7 +49,7 @@ use Symfony\Component\DependencyInjection\ContainerInterface; * id = "file_copy" * ) */ -class FileCopy extends ProcessPluginBase implements ContainerFactoryPluginInterface { +class FileCopy extends FileProcessBase implements ContainerFactoryPluginInterface { /** * The stream wrapper manager service. @@ -91,8 +91,6 @@ class FileCopy extends ProcessPluginBase implements ContainerFactoryPluginInterf public function __construct(array $configuration, $plugin_id, array $plugin_definition, StreamWrapperManagerInterface $stream_wrappers, FileSystemInterface $file_system, MigrateProcessInterface $download_plugin) { $configuration += [ 'move' => FALSE, - 'rename' => FALSE, - 'reuse' => FALSE, ]; parent::__construct($configuration, $plugin_id, $plugin_definition); $this->streamWrapperManager = $stream_wrappers; @@ -110,7 +108,7 @@ class FileCopy extends ProcessPluginBase implements ContainerFactoryPluginInterf $plugin_definition, $container->get('stream_wrapper_manager'), $container->get('file_system'), - $container->get('plugin.manager.migrate.process')->createInstance('download') + $container->get('plugin.manager.migrate.process')->createInstance('download', $configuration) ); } @@ -151,7 +149,7 @@ class FileCopy extends ProcessPluginBase implements ContainerFactoryPluginInterf } } - $final_destination = $this->writeFile($source, $destination, $this->getOverwriteMode()); + $final_destination = $this->writeFile($source, $destination, $this->configuration['file_exists']); if ($final_destination) { return $final_destination; } @@ -182,24 +180,6 @@ class FileCopy extends ProcessPluginBase implements ContainerFactoryPluginInterf return $function($source, $destination, $replace); } - /** - * Determines how to handle file conflicts. - * - * @return int - * FILE_EXISTS_REPLACE (default), FILE_EXISTS_RENAME, or FILE_EXISTS_ERROR - * depending on the current configuration. - */ - protected function getOverwriteMode() { - if (!empty($this->configuration['rename'])) { - return FILE_EXISTS_RENAME; - } - if (!empty($this->configuration['reuse'])) { - return FILE_EXISTS_ERROR; - } - - return FILE_EXISTS_REPLACE; - } - /** * Returns the directory component of a URI or path. *