Do not delete media files if file is replaced with itself
authorMatthias Schmidt <gravatronics@live.com>
Wed, 12 May 2021 08:31:10 +0000 (10:31 +0200)
committerMatthias Schmidt <gravatronics@live.com>
Wed, 12 May 2021 08:31:10 +0000 (10:31 +0200)
wcfsetup/install/files/lib/data/media/MediaAction.class.php

index 11e5e2402b53b21c08ca27817736fb24823bb79d..b8c7e935f5da8bb559daa3ea3345afa11164c3b4 100644 (file)
@@ -763,9 +763,13 @@ class MediaAction extends AbstractDatabaseObjectAction implements ISearchAction,
                        }
                }
                
-               // Delete *old* files using the non-updated local media editor object.
-               if (empty($result['errors'])) {
-                       $this->getSingleObject()->deleteFiles();
+               $outdatedMediaFile = $this->getSingleObject();
+               $updatedMediaFile = new Media($this->getSingleObject()->mediaID);
+               
+               // Delete *old* files using the non-updated local media editor object if the new file is
+               // stored in a different location.
+               if (empty($result['errors']) && $updatedMediaFile->getLocation() !== $outdatedMediaFile->getLocation()) {
+                       $outdatedMediaFile->deleteFiles();
                }
                
                return $result;