From: Cyperghost Date: Fri, 29 Nov 2024 13:05:22 +0000 (+0100) Subject: Check if `coverPhotoHash` or `coverPhotoExtension` is set X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=8cd6ef552ebefb358bf0d4b64f4428a07032fded;p=GitHub%2FWoltLab%2FWCF.git Check if `coverPhotoHash` or `coverPhotoExtension` is set --- 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,