[BUGFIX] Resolve correct processed folder when on different storage 52/58452/2
authorHelmut Hummel <typo3@helhum.io>
Thu, 27 Sep 2018 09:34:23 +0000 (11:34 +0200)
committerNicole Cordes <typo3@cordes.co>
Sat, 29 Sep 2018 11:54:44 +0000 (13:54 +0200)
During generation of processed files a wrong processed folder
is evaluated when the processed folder resides on a different storage.

We now ensure to ask the correct storage for the processed folder.

Also ensure that correct storage is used for checking file existence
when original file and processed files are on different storages.

Fixes: #86399
Releases: master, 8.7
Change-Id: I254b9a0bf86a156ae135510a4439e87737ec1a29
Reviewed-on: https://review.typo3.org/58452
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Nicole Cordes <typo3@cordes.co>
Tested-by: Nicole Cordes <typo3@cordes.co>
typo3/sysext/core/Classes/Resource/ProcessedFile.php
typo3/sysext/core/Classes/Resource/ResourceStorage.php

index 7119620..b93d479 100644 (file)
@@ -251,8 +251,8 @@ class ProcessedFile extends AbstractFile
      */
     public function setName($name)
     {
-        // Remove the existing file
-        if ($this->name !== $name && $this->name !== '' && $this->exists()) {
+        // Remove the existing file, but only we actually have a name or the name has changed
+        if (!empty($this->name) && $this->name !== $name && $this->exists()) {
             $this->delete();
         }
 
@@ -263,6 +263,22 @@ class ProcessedFile extends AbstractFile
         $this->updated = true;
     }
 
+    /**
+     * Checks if this file exists.
+     * Since the original file may reside in a different storage
+     * we ask the original file if it exists in case the processed is representing it
+     *
+     * @return bool TRUE if this file physically exists
+     */
+    public function exists()
+    {
+        if ($this->usesOriginalFile()) {
+            return $this->originalFile->exists();
+        }
+
+        return parent::exists();
+    }
+
     /******************
      * SPECIAL METHODS
      ******************/
@@ -404,7 +420,7 @@ class ProcessedFile extends AbstractFile
      */
     public function usesOriginalFile()
     {
-        return $this->identifier == null || $this->identifier === $this->originalFile->getIdentifier();
+        return $this->identifier === null || $this->identifier === $this->originalFile->getIdentifier();
     }
 
     /**
index cdfc48f..7e9783b 100644 (file)
@@ -2922,6 +2922,10 @@ class ResourceStorage implements ResourceStorageInterface
      */
     public function getProcessingFolder(File $file = null)
     {
+        // If a file is given, make sure to return the processing folder of the correct storage
+        if ($file !== null && $file->getStorage()->getUid() !== $this->getUid()) {
+            return $file->getStorage()->getProcessingFolder($file);
+        }
         if (!isset($this->processingFolder)) {
             $processingFolder = self::DEFAULT_ProcessingFolder;
             if (!empty($this->storageRecord['processingfolder'])) {