Check if `coverPhotoHash` or `coverPhotoExtension` is set
authorCyperghost <olaf_schmitz_1@t-online.de>
Fri, 29 Nov 2024 13:05:22 +0000 (14:05 +0100)
committerCyperghost <olaf_schmitz_1@t-online.de>
Fri, 29 Nov 2024 13:05:22 +0000 (14:05 +0100)
wcfsetup/install/files/lib/system/user/command/SetCoverPhoto.class.php

index d3e50117bb58bd6886639bb7557a2a375a522ffb..39898ec1464fc22c6b513c98d8cbbc8382b258ed 100644 (file)
@@ -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,