From: Matthias Schmidt Date: Wed, 12 May 2021 08:31:10 +0000 (+0200) Subject: Do not delete media files if file is replaced with itself X-Git-Tag: 5.4.0_Alpha_3~5^2~8 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=086af835b2e1d8059736a700859cca2d0d4c9ce5;p=GitHub%2FWoltLab%2FWCF.git Do not delete media files if file is replaced with itself --- 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;