From 07ef36303e30c53be1f15783ed5df95e6d213a56 Mon Sep 17 00:00:00 2001 From: Helmut Hummel <typo3@helhum.io> Date: Sun, 24 Dec 2017 15:21:49 +0100 Subject: [PATCH] [TASK] Move changing preview processing config to processing service Instead of complementing processing configuration in the file class, move it to the processing service and LocalPreviewHelper class to not have the code and logic duplicated and to ensure it is always executed, not only when using the file API. Resolves: #83421 Related: #81776 Related: #83242 Releases: master, 8.7, 7.6 Change-Id: I9b3f380625756137a56e7ad0ea55d21f47464ab8 Reviewed-on: https://review.typo3.org/55271 Tested-by: TYPO3com <no-reply@typo3.com> Reviewed-by: Stefan Neufeind <typo3.neufeind@speedpartner.de> Tested-by: Stefan Neufeind <typo3.neufeind@speedpartner.de> --- typo3/sysext/core/Classes/Resource/File.php | 6 ---- .../Processing/LocalPreviewHelper.php | 30 +++++++++++++++---- .../Service/FileProcessingService.php | 7 +++++ 3 files changed, 32 insertions(+), 11 deletions(-) diff --git a/typo3/sysext/core/Classes/Resource/File.php b/typo3/sysext/core/Classes/Resource/File.php index 153a94ee3b6c..a3560f5a25d8 100644 --- a/typo3/sysext/core/Classes/Resource/File.php +++ b/typo3/sysext/core/Classes/Resource/File.php @@ -15,7 +15,6 @@ namespace TYPO3\CMS\Core\Resource; */ use TYPO3\CMS\Core\Utility\GeneralUtility; -use TYPO3\CMS\Core\Utility\MathUtility; /** * File representation in the file abstraction layer. @@ -302,11 +301,6 @@ class File extends AbstractFile */ public function process($taskType, array $configuration) { - if ($taskType === ProcessedFile::CONTEXT_IMAGEPREVIEW) { - $configuration = array_merge(['width' => 64, 'height' => 64], $configuration); - $configuration['width'] = MathUtility::forceIntegerInRange($configuration['width'], 1, 1000); - $configuration['height'] = MathUtility::forceIntegerInRange($configuration['height'], 1, 1000); - } return $this->getStorage()->processFile($this, $taskType, $configuration); } diff --git a/typo3/sysext/core/Classes/Resource/Processing/LocalPreviewHelper.php b/typo3/sysext/core/Classes/Resource/Processing/LocalPreviewHelper.php index 03eca60ee87e..ac791a1e673e 100644 --- a/typo3/sysext/core/Classes/Resource/Processing/LocalPreviewHelper.php +++ b/typo3/sysext/core/Classes/Resource/Processing/LocalPreviewHelper.php @@ -25,6 +25,16 @@ use TYPO3\CMS\Core\Utility\MathUtility; */ class LocalPreviewHelper { + /** + * Default preview configuration + * + * @var array + */ + protected static $defaultConfiguration = [ + 'width' => 64, + 'height' => 64, + ]; + /** * @var LocalImageProcessor */ @@ -38,6 +48,20 @@ class LocalPreviewHelper $this->processor = $processor; } + /** + * Enforce default configuration for preview processing + * + * @param array $configuration + * @return array + */ + public static function preProcessConfiguration(array $configuration) + { + $configuration = array_replace(static::$defaultConfiguration, $configuration); + $configuration['width'] = MathUtility::forceIntegerInRange($configuration['width'], 1, 1000); + $configuration['height'] = MathUtility::forceIntegerInRange($configuration['height'], 1, 1000); + return $configuration; + } + /** * This method actually does the processing of files locally * @@ -60,11 +84,7 @@ class LocalPreviewHelper public function process(TaskInterface $task) { $sourceFile = $task->getSourceFile(); - - // Merge custom configuration with default configuration - $configuration = array_merge(['width' => 64, 'height' => 64], $task->getConfiguration()); - $configuration['width'] = MathUtility::forceIntegerInRange($configuration['width'], 1); - $configuration['height'] = MathUtility::forceIntegerInRange($configuration['height'], 1); + $configuration = static::preProcessConfiguration($task->getConfiguration()); // Do not scale up if the source file has a size and the target size is larger if ($sourceFile->getProperty('width') > 0 && $sourceFile->getProperty('height') > 0 diff --git a/typo3/sysext/core/Classes/Resource/Service/FileProcessingService.php b/typo3/sysext/core/Classes/Resource/Service/FileProcessingService.php index fbabc89fb75a..57f0e57978af 100644 --- a/typo3/sysext/core/Classes/Resource/Service/FileProcessingService.php +++ b/typo3/sysext/core/Classes/Resource/Service/FileProcessingService.php @@ -74,6 +74,13 @@ class FileProcessingService */ public function processFile(Resource\FileInterface $fileObject, Resource\ResourceStorage $targetStorage, $taskType, $configuration) { + // Enforce default configuration for preview processing here, + // to be sure we find already processed files below, + // which we wouldn't if we would change the configuration later, as configuration is part of the lookup. + if ($taskType === Resource\ProcessedFile::CONTEXT_IMAGEPREVIEW) { + $configuration = Resource\Processing\LocalPreviewHelper::preProcessConfiguration($configuration); + } + /** @var $processedFileRepository Resource\ProcessedFileRepository */ $processedFileRepository = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Resource\ProcessedFileRepository::class); -- GitLab