Add method removeFileByObject
authorJoshua Rüsweg <josh@bastelstu.be>
Thu, 31 Jan 2019 13:19:09 +0000 (14:19 +0100)
committerJoshua Rüsweg <josh@bastelstu.be>
Thu, 31 Jan 2019 13:19:09 +0000 (14:19 +0100)
See #2825

wcfsetup/install/files/lib/system/file/upload/UploadHandler.class.php

index 36f19c026bbc5c109a0bdd39e8ad8c704760b17f..e214508ebbb6f31a484aa12003fb0fe2e8202d92 100644 (file)
@@ -154,6 +154,16 @@ class UploadHandler extends SingletonFactory {
                        return; 
                }               
                
+               $this->removeFileByObject($internalId, $file);
+       }
+       
+       /**
+        * Removes an file by file object. 
+        * 
+        * @param       string          $internalId
+        * @param       UploadFile      $file
+        */
+       private function removeFileByObject($internalId, UploadFile $file) {
                $storage = $this->getStorage();
                
                if ($file->isProcessed()) {
@@ -165,7 +175,7 @@ class UploadHandler extends SingletonFactory {
                
                /** @var UploadFile $storageFile */
                foreach ($storage[$internalId]['files'] as $id => $storageFile) {
-                       if ($storageFile->getUniqueFileId() === $uniqueFileId) {
+                       if ($storageFile->getUniqueFileId() === $file->getUniqueFileId()) {
                                unset($storage[$internalId]['files'][$id]);
                                break;
                        }
@@ -355,7 +365,7 @@ class UploadHandler extends SingletonFactory {
                        /** @var UploadFile $file */
                        foreach ($files as $file) {
                                if (!file_exists($file->getLocation())) {
-                                       $this->removeFile($internalId, $file->getUniqueFileId());
+                                       $this->removeFile($internalId, $file);
                                }
                        }