[!!!][BUGFIX] Scope of ProcessedFile cannot be modified 38/19438/2
authorOliver Hader <oliver@typo3.org>
Sat, 30 Mar 2013 08:55:26 +0000 (09:55 +0100)
committerOliver Hader <oliver.hader@typo3.org>
Mon, 1 Apr 2013 20:44:33 +0000 (22:44 +0200)
A ProcessedFile is used to generate a preview or crop-scaled
version of a File. Actually a Task implementing the
TaskInterface defines the basics and an accordant Helper
object takes care of the modifications to that file.
There are pre-process and post-process signals that seem to
be useless in modifying the scope of a particular task, however.

Imagine a file shall be pre-processed (e.g. color profile
transformation) and that result shall be used for resizing.
The current task implementation is using the original file
directly, however the task actually shall define which is the
source (the original file) the modifications shall be based on.

This change modifies the TaskInterface with a getSourceFile()
method to overcome this limitation.

Change-Id: I280ea9a0bf056f9eee0a06995ab809fdafb8a11a
Fixes: #46795
Releases: 6.0, 6.1
Reviewed-on: https://review.typo3.org/19438
Reviewed-by: Stefan Neufeind
Tested-by: Steffen Ritter
Reviewed-by: Steffen Ritter
Reviewed-by: Philipp Gampe
Tested-by: Philipp Gampe
Reviewed-by: Oliver Hader
Tested-by: Oliver Hader
typo3/sysext/core/Classes/Resource/Processing/AbstractGraphicalTask.php
typo3/sysext/core/Classes/Resource/Processing/AbstractTask.php
typo3/sysext/core/Classes/Resource/Processing/LocalCropScaleMaskHelper.php
typo3/sysext/core/Classes/Resource/Processing/LocalPreviewHelper.php
typo3/sysext/core/Classes/Resource/Processing/TaskInterface.php

index c94d3e6..0a527e4 100644 (file)
@@ -65,7 +65,7 @@ abstract class AbstractGraphicalTask extends AbstractTask {
         * @return string
         */
        public function getTargetFilename() {
-               return $this->targetFile->getOriginalFile()->getNameWithoutExtension()
+               return $this->getSourceFile()->getNameWithoutExtension()
                        . '_' . $this->getConfigurationChecksum()
                        . '.' . $this->getTargetFileExtension();
        }
@@ -94,7 +94,7 @@ abstract class AbstractGraphicalTask extends AbstractTask {
        protected function determineTargetFileExtension() {
                if (!empty($this->configuration['fileExtension'])) {
                        $targetFileExtension = $this->configuration['fileExtension'];
-               } elseif ($this->targetFile->getOriginalFile()->getExtension() === 'jpg') {
+               } elseif ($this->getSourceFile()->getExtension() === 'jpg') {
                        $targetFileExtension = 'jpg';
                } else {
                        $targetFileExtension = 'png';
index 2a7d125..80ac1db 100644 (file)
@@ -50,6 +50,11 @@ abstract class AbstractTask implements TaskInterface {
        protected $targetFile;
 
        /**
+        * @var Resource\File
+        */
+       protected $sourceFile;
+
+       /**
         * @var array
         */
        protected $configuration;
@@ -80,6 +85,7 @@ abstract class AbstractTask implements TaskInterface {
         */
        public function __construct(Resource\ProcessedFile $targetFile, array $configuration) {
                $this->targetFile = $targetFile;
+               $this->sourceFile = $targetFile->getOriginalFile();
                $this->configuration = $configuration;
        }
 
@@ -92,7 +98,7 @@ abstract class AbstractTask implements TaskInterface {
         */
        protected function getChecksumData() {
                return array(
-                       $this->targetFile->getOriginalFile()->getUid(),
+                       $this->getSourceFile()->getUid(),
                        $this->getType() . '.' . $this->getName(),
                        serialize($this->configuration)
                );
@@ -154,6 +160,27 @@ abstract class AbstractTask implements TaskInterface {
        }
 
        /**
+        * @param Resource\ProcessedFile $targetFile
+        */
+       public function setTargetFile(Resource\ProcessedFile $targetFile) {
+               $this->targetFile = $targetFile;
+       }
+
+       /**
+        * @return Resource\File
+        */
+       public function getSourceFile() {
+               return $this->sourceFile;
+       }
+
+       /**
+        * @param Resource\File $sourceFile
+        */
+       public function setSourceFile(Resource\File $sourceFile) {
+               $this->sourceFile = $sourceFile;
+       }
+
+       /**
         * @return array
         */
        public function getConfiguration() {
index 5769fa1..f6e38f3 100644 (file)
@@ -60,8 +60,9 @@ class LocalCropScaleMaskHelper {
        public function process(TaskInterface $task) {
                $result = NULL;
                $targetFile = $task->getTargetFile();
+               $sourceFile = $task->getSourceFile();
 
-               $originalFileName = $targetFile->getOriginalFile()->getForLocalProcessing(FALSE);
+               $originalFileName = $sourceFile->getForLocalProcessing(FALSE);
                /** @var $gifBuilder \TYPO3\CMS\Frontend\Imaging\GifBuilder */
                $gifBuilder = Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Frontend\\Imaging\\GifBuilder');
                $gifBuilder->init();
@@ -88,7 +89,7 @@ class LocalCropScaleMaskHelper {
                                $options
                        );
                } else {
-                       $targetFileName = $this->getFilenameForImageCropScaleMask($targetFile);
+                       $targetFileName = $this->getFilenameForImageCropScaleMask($task);
                        $temporaryFileName = $gifBuilder->tempPath . $targetFileName;
                        $maskImage = $configuration['maskImages']['maskImage'];
                        $maskBackgroundImage = $configuration['maskImages']['backgroundImage'];
@@ -200,21 +201,21 @@ class LocalCropScaleMaskHelper {
        /**
         * Returns the filename for a cropped/scaled/masked file.
         *
-        * @param Resource\ProcessedFile $processedFile
+        * @param TaskInterface $task
         * @return string
         */
-       protected function getFilenameForImageCropScaleMask(Resource\ProcessedFile $processedFile) {
+       protected function getFilenameForImageCropScaleMask(TaskInterface $task) {
 
-               $configuration = $processedFile->getProcessingConfiguration();
-               $targetFileExtension = $processedFile->getOriginalFile()->getExtension();
+               $configuration = $task->getTargetFile()->getProcessingConfiguration();
+               $targetFileExtension = $task->getSourceFile()->getExtension();
                $processedFileExtension = $GLOBALS['TYPO3_CONF_VARS']['GFX']['gdlib_png'] ? 'png' : 'gif';
-               if (is_array($configuration['maskImages']) && $GLOBALS['TYPO3_CONF_VARS']['GFX']['im'] && $processedFile->getOriginalFile()->getExtension() != $processedFileExtension) {
+               if (is_array($configuration['maskImages']) && $GLOBALS['TYPO3_CONF_VARS']['GFX']['im'] && $task->getSourceFile()->getExtension() != $processedFileExtension) {
                        $targetFileExtension = 'jpg';
                } elseif ($configuration['fileExtension']) {
                        $targetFileExtension = $configuration['fileExtension'];
                }
 
-               return $processedFile->generateProcessedFileNameWithoutExtension() . '.' . ltrim(trim($targetFileExtension), '.');
+               return $task->getTargetFile()->generateProcessedFileNameWithoutExtension() . '.' . ltrim(trim($targetFileExtension), '.');
        }
 
        /**
index 523c61d..97ef09a 100644 (file)
@@ -58,21 +58,22 @@ class LocalPreviewHelper {
         */
        public function process(TaskInterface $task) {
                $targetFile = $task->getTargetFile();
+               $sourceFile = $task->getSourceFile();
 
                        // Merge custom configuration with default configuration
                $configuration = array_merge(array('width' => 64, 'height' => 64), $task->getConfiguration());
                $configuration['width'] = Utility\MathUtility::forceIntegerInRange($configuration['width'], 1, 1000);
                $configuration['height'] = Utility\MathUtility::forceIntegerInRange($configuration['height'], 1, 1000);
 
-               $originalFileName = $targetFile->getOriginalFile()->getForLocalProcessing(FALSE);
+               $originalFileName = $sourceFile->getForLocalProcessing(FALSE);
 
                        // Create the thumb filename in typo3temp/preview_....jpg
                $temporaryFileName = Utility\GeneralUtility::tempnam('preview_') . '.' . $task->getTargetFileExtension();
                        // Check file extension
-               if ($targetFile->getOriginalFile()->getType() != Resource\File::FILETYPE_IMAGE &&
-                       !Utility\GeneralUtility::inList($GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext'], $targetFile->getOriginalFile()->getExtension())) {
+               if ($sourceFile->getType() != Resource\File::FILETYPE_IMAGE &&
+                       !Utility\GeneralUtility::inList($GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext'], $sourceFile->getExtension())) {
                                // Create a default image
-                       $this->processor->getTemporaryImageWithText($temporaryFileName, 'Not imagefile!', 'No ext!', $targetFile->getOriginalFile()->getName());
+                       $this->processor->getTemporaryImageWithText($temporaryFileName, 'Not imagefile!', 'No ext!', $sourceFile->getName());
                } else {
                                // Create the temporary file
                        if ($GLOBALS['TYPO3_CONF_VARS']['GFX']['im']) {
@@ -84,7 +85,7 @@ class LocalPreviewHelper {
 
                                if (!file_exists($temporaryFileName)) {
                                                // Create a error gif
-                                       $this->processor->getTemporaryImageWithText($temporaryFileName, 'No thumb', 'generated!', $targetFile->getOriginalFile()->getName());
+                                       $this->processor->getTemporaryImageWithText($temporaryFileName, 'No thumb', 'generated!', $sourceFile->getName());
                                }
                        }
                }
index 3d0d6d1..f512e37 100644 (file)
@@ -70,6 +70,13 @@ interface TaskInterface {
        public function getTargetFile();
 
        /**
+        * Returns the original file this task is based on.
+        *
+        * @return Resource\File
+        */
+       public function getSourceFile();
+
+       /**
         * Returns the configuration for this task.
         *
         * @return array