From 8cd6ef552ebefb358bf0d4b64f4428a07032fded Mon Sep 17 00:00:00 2001 From: Cyperghost Date: Fri, 29 Nov 2024 14:05:22 +0100 Subject: [PATCH] Check if `coverPhotoHash` or `coverPhotoExtension` is set --- .../user/command/SetCoverPhoto.class.php | 20 ++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/wcfsetup/install/files/lib/system/user/command/SetCoverPhoto.class.php b/wcfsetup/install/files/lib/system/user/command/SetCoverPhoto.class.php index d3e50117bb..39898ec146 100644 --- a/wcfsetup/install/files/lib/system/user/command/SetCoverPhoto.class.php +++ b/wcfsetup/install/files/lib/system/user/command/SetCoverPhoto.class.php @@ -31,12 +31,14 @@ final class SetCoverPhoto } // Delete the old cover photo if it exists. - if (\file_exists($this->getCoverPhotoLocation($this->user, false))) { - @\unlink($this->getCoverPhotoLocation($this->user, false)); - } + $oldCoverPhotoLocation = self::getCoverPhotoLocation($this->user, false); + $oldCoverPhotoWebPLocation = self::getCoverPhotoLocation($this->user, true); - if (\file_exists($this->getCoverPhotoLocation($this->user, true))) { - @\unlink($this->getCoverPhotoLocation($this->user, true)); + if ($oldCoverPhotoLocation && \file_exists($oldCoverPhotoLocation)) { + @\unlink($oldCoverPhotoLocation); + } + if ($oldCoverPhotoWebPLocation && \file_exists($oldCoverPhotoWebPLocation)) { + @\unlink($oldCoverPhotoWebPLocation); } (new UserEditor($this->user))->update([ @@ -48,9 +50,13 @@ final class SetCoverPhoto UserProfileRuntimeCache::getInstance()->removeObject($this->user->userID); } - public static function getCoverPhotoLocation(User $user, bool $forceWebP): string + /** @noinspection PhpUndefinedFieldInspection */ + public static function getCoverPhotoLocation(User $user, bool $forceWebP): ?string { - /** @noinspection PhpUndefinedFieldInspection */ + if (!$user->coverPhotoHash || !$user->coverPhotoExtension) { + return null; + } + return \sprintf( '%simages/coverPhotos/%s/%d-%s.%s', WCF_DIR, -- 2.20.1