X-Git-Url: http://aleph1.co.uk/gitweb/?a=blobdiff_plain;f=web%2Fcore%2Fmodules%2Fmigrate%2Fsrc%2FPlugin%2Fmigrate%2Fprocess%2FDownload.php;h=cc5ed859f01301baff095c326f278d39044b45cb;hb=5b8bb166bfa98770daef9de5c127fc2e6ef02340;hp=cfcba8115b933225294b9216ecb6988eec7627c4;hpb=a2bd1bf0c2c1f1a17d188f4dc0726a45494cefae;p=yaffs-website diff --git a/web/core/modules/migrate/src/Plugin/migrate/process/Download.php b/web/core/modules/migrate/src/Plugin/migrate/process/Download.php index cfcba8115..cc5ed859f 100644 --- a/web/core/modules/migrate/src/Plugin/migrate/process/Download.php +++ b/web/core/modules/migrate/src/Plugin/migrate/process/Download.php @@ -6,7 +6,6 @@ use Drupal\Core\File\FileSystemInterface; use Drupal\Core\Plugin\ContainerFactoryPluginInterface; use Drupal\migrate\MigrateException; use Drupal\migrate\MigrateExecutableInterface; -use Drupal\migrate\ProcessPluginBase; use Drupal\migrate\Row; use GuzzleHttp\Client; use Symfony\Component\DependencyInjection\ContainerInterface; @@ -19,8 +18,12 @@ use Symfony\Component\DependencyInjection\ContainerInterface; * - destination URI, e.g. 'public://images/foo.img' * * Available configuration keys: - * - rename: (optional) If set, a unique destination URI is generated. If not - * set, the destination URI will be overwritten if it exists. + * - 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. * - guzzle_options: (optional) * @link http://docs.guzzlephp.org/en/latest/request-options.html Array of request options for Guzzle. @endlink * @@ -42,7 +45,7 @@ use Symfony\Component\DependencyInjection\ContainerInterface; * source: * - source_url * - destination_uri - * rename: true + * file_exists: rename * @endcode * * This will download source_url to destination_uri and ensure that the @@ -53,7 +56,7 @@ use Symfony\Component\DependencyInjection\ContainerInterface; * id = "download" * ) */ -class Download extends ProcessPluginBase implements ContainerFactoryPluginInterface { +class Download extends FileProcessBase implements ContainerFactoryPluginInterface { /** * The file system service. @@ -85,7 +88,6 @@ class Download extends ProcessPluginBase implements ContainerFactoryPluginInterf */ public function __construct(array $configuration, $plugin_id, array $plugin_definition, FileSystemInterface $file_system, Client $http_client) { $configuration += [ - 'rename' => FALSE, 'guzzle_options' => [], ]; parent::__construct($configuration, $plugin_id, $plugin_definition); @@ -118,10 +120,12 @@ class Download extends ProcessPluginBase implements ContainerFactoryPluginInterf list($source, $destination) = $value; // Modify the destination filename if necessary. - $replace = !empty($this->configuration['rename']) ? - FILE_EXISTS_RENAME : - FILE_EXISTS_REPLACE; - $final_destination = file_destination($destination, $replace); + $final_destination = file_destination($destination, $this->configuration['file_exists']); + + // Reuse if file exists. + if (!$final_destination) { + return $destination; + } // Try opening the file first, to avoid calling file_prepare_directory() // unnecessarily. We're suppressing fopen() errors because we want to try