[BUGFIX] LocalImageProcessor cannot reuse remote files 05/46905/4
authorAndreas Wolf <dev@a-w.io>
Fri, 26 Feb 2016 09:46:39 +0000 (10:46 +0100)
committerBenni Mack <benni@typo3.org>
Sat, 5 Mar 2016 23:53:06 +0000 (00:53 +0100)
The LocalImageProcessor had a check for the storage type, to only do a
check for existing files on local storages, as it needed to fetch an
existing file from the storage to get metadata from it.

This check is now replaced by a proper usage of the FAL API: Fetch the
generated file for local (read-only) processing, which in case of a
local storage means the file is not moved at all. Then, the image
metadata can be extracted from the local file and the file index record
of the processed file can be updated accordingly.

Change-Id: I9fca326fe1d1743cd53a0a85c674ff81e5a051b9
Releases: master, 7.6
Resolves: #67126
Reviewed-on: https://review.typo3.org/46905
Reviewed-by: Jan Helke <typo3@helke.de>
Tested-by: Jan Helke <typo3@helke.de>
Reviewed-by: Benni Mack <benni@typo3.org>
Tested-by: Benni Mack <benni@typo3.org>
typo3/sysext/core/Classes/Resource/Processing/LocalImageProcessor.php

index 5370ef3..458f591 100644 (file)
@@ -106,26 +106,26 @@ class LocalImageProcessor implements ProcessorInterface
      */
     protected function checkForExistingTargetFile(TaskInterface $task)
     {
-        $processingFolder = $task->getTargetFile()->getStorage()->getProcessingFolder();
+        // the storage of the processed file, not of the original file!
         $storage = $task->getTargetFile()->getStorage();
-        // @todo: make proper use of the FAL API, see https://forge.typo3.org/issues/67126
-        if ($processingFolder->hasFile($task->getTargetFileName()) && $storage->getDriverType() === 'Local') {
-            $processedFileIdentifier = rtrim($processingFolder->getIdentifier(), '/') . '/' . $task->getTargetFileName();
-            $configuration = $storage->getConfiguration();
-            if ($configuration['pathType'] === 'relative') {
-                $absoluteBasePath = PATH_site . $configuration['basePath'];
-            } else {
-                $absoluteBasePath = $configuration['basePath'];
-            }
-            $targetFile = $absoluteBasePath . ltrim($processedFileIdentifier, '/');
+        $processingFolder = $storage->getProcessingFolder();
+
+        // explicitly check for the raw filename here, as we check for files that existed before we even started
+        // processing, i.e. that were processed earlier
+        if ($processingFolder->hasFile($task->getTargetFileName())) {
+            // If the processed file already exists, fetch it and update its properties to reflect the actual file.
+            $processedFile = $storage->getFileInFolder($task->getTargetFileName(), $processingFolder);
+            // If the processed file is stored on a remote server, we must fetch a local copy of the file, as we
+            // have no API for fetching file metadata from a remote file.
+            $localProcessedFile = $storage->getFileForLocalProcessing($processedFile, false);
 
             $task->setExecuted(true);
-            $imageDimensions = $this->getGraphicalFunctionsObject()->getImageDimensions($targetFile);
+            $imageDimensions = $this->getGraphicalFunctionsObject()->getImageDimensions($localProcessedFile);
             $task->getTargetFile()->setName($task->getTargetFileName());
             $properties = array(
                 'width' => $imageDimensions[0],
                 'height' => $imageDimensions[1],
-                'size' => filesize($targetFile),
+                'size' => filesize($localProcessedFile),
                 'checksum' => $task->getConfigurationChecksum()
             );
             $task->getTargetFile()->updateProperties($properties);