[TASK] Move changing preview processing config to processing service 10/55210/2
authorHelmut Hummel <typo3@helhum.io>
Sun, 24 Dec 2017 14:21:49 +0000 (15:21 +0100)
committerStefan Neufeind <typo3.neufeind@speedpartner.de>
Fri, 5 Jan 2018 07:08:45 +0000 (08:08 +0100)
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/55210
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Benni Mack <benni@typo3.org>
Tested-by: Benni Mack <benni@typo3.org>
Reviewed-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
Tested-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
Reviewed-by: Stefan Neufeind <typo3.neufeind@speedpartner.de>
Tested-by: Stefan Neufeind <typo3.neufeind@speedpartner.de>
typo3/sysext/core/Classes/Resource/File.php
typo3/sysext/core/Classes/Resource/Processing/LocalPreviewHelper.php
typo3/sysext/core/Classes/Resource/Service/FileProcessingService.php

index f28529e..f5e927f 100644 (file)
@@ -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.
@@ -297,11 +296,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);
     }
 
index 4249afe..4fe216f 100644 (file)
@@ -26,6 +26,16 @@ use TYPO3\CMS\Core\Utility\MathUtility;
 class LocalPreviewHelper
 {
     /**
+     * Default preview configuration
+     *
+     * @var array
+     */
+    protected static $defaultConfiguration = [
+        'width' => 64,
+        'height' => 64,
+    ];
+
+    /**
      * @var LocalImageProcessor
      */
     protected $processor;
@@ -39,6 +49,20 @@ class LocalPreviewHelper
     }
 
     /**
+     * Enforce default configuration for preview processing
+     *
+     * @param array $configuration
+     * @return array
+     */
+    public static function preProcessConfiguration(array $configuration): array
+    {
+        $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
      *
      * takes the original file (on remote storages this will be fetched from the remote server)
@@ -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
index 8c032b4..2606b27 100644 (file)
@@ -77,6 +77,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(Resource\ProcessedFileRepository::class);