From 086af835b2e1d8059736a700859cca2d0d4c9ce5 Mon Sep 17 00:00:00 2001 From: Matthias Schmidt Date: Wed, 12 May 2021 10:31:10 +0200 Subject: [PATCH] Do not delete media files if file is replaced with itself --- .../install/files/lib/data/media/MediaAction.class.php | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/wcfsetup/install/files/lib/data/media/MediaAction.class.php b/wcfsetup/install/files/lib/data/media/MediaAction.class.php index 11e5e2402b..b8c7e935f5 100644 --- a/wcfsetup/install/files/lib/data/media/MediaAction.class.php +++ b/wcfsetup/install/files/lib/data/media/MediaAction.class.php @@ -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; -- 2.20.1