Rename `getCoverPhotoLocation()` to `getLegacyLocation()` and move to `UserCoverPhoto`.
authorCyperghost <olaf_schmitz_1@t-online.de>
Wed, 4 Dec 2024 12:49:04 +0000 (13:49 +0100)
committerCyperghost <olaf_schmitz_1@t-online.de>
Wed, 4 Dec 2024 12:49:04 +0000 (13:49 +0100)
wcfsetup/install/files/lib/data/user/cover/photo/UserCoverPhoto.class.php
wcfsetup/install/files/lib/system/user/command/SetCoverPhoto.class.php
wcfsetup/install/files/lib/system/worker/UserRebuildDataWorker.class.php

index c3848663ad41ce5249fd6adb1dd9fb0343126b2e..173573e4c4c19f9cb4bb6cc13d434e7b688cde99 100644 (file)
@@ -4,6 +4,7 @@ namespace wcf\data\user\cover\photo;
 
 use wcf\data\file\File;
 use wcf\data\file\FileAction;
+use wcf\data\user\User;
 
 /**
  * Represents a user's cover photo.
@@ -71,4 +72,28 @@ final class UserCoverPhoto implements IUserCoverPhoto
             ],
         ];
     }
+
+    /**
+     * Returns the location of a user's cover photo before WCF6.2.
+     */
+    /** @noinspection PhpUndefinedFieldInspection */
+    public static function getLegacyLocation(User $user, bool $forceWebP): ?string
+    {
+        if (!$user->coverPhotoHash || !$user->coverPhotoExtension) {
+            return null;
+        }
+
+        return \sprintf(
+            '%simages/coverPhotos/%s/%d-%s.%s',
+            WCF_DIR,
+            \substr(
+                $user->coverPhotoHash,
+                0,
+                2
+            ),
+            $user->userID,
+            $user->coverPhotoHash,
+            $forceWebP ? 'webp' : $user->coverPhotoExtension
+        );
+    }
 }
index 4b26e6fa4e5ad510ea924d2fc94ade82bb706c11..2427ea100c99b471f610e637fab6181d0f6c42a4 100644 (file)
@@ -30,17 +30,6 @@ final class SetCoverPhoto
             (new FileAction([$this->user->coverPhotoFileID], 'delete'))->executeAction();
         }
 
-        // Delete the old cover photo if it exists.
-        $oldCoverPhotoLocation = self::getCoverPhotoLocation($this->user, false);
-        $oldCoverPhotoWebPLocation = self::getCoverPhotoLocation($this->user, true);
-
-        if ($oldCoverPhotoLocation && \file_exists($oldCoverPhotoLocation)) {
-            @\unlink($oldCoverPhotoLocation);
-        }
-        if ($oldCoverPhotoWebPLocation && \file_exists($oldCoverPhotoWebPLocation)) {
-            @\unlink($oldCoverPhotoWebPLocation);
-        }
-
         (new UserEditor($this->user))->update([
             'coverPhotoFileID' => $this->file?->fileID,
             'coverPhotoHash' => null,
@@ -49,28 +38,4 @@ final class SetCoverPhoto
         ]);
         UserProfileRuntimeCache::getInstance()->removeObject($this->user->userID);
     }
-
-    /**
-     * Returns the location of a user's cover photo before WCF6.2.
-     */
-    /** @noinspection PhpUndefinedFieldInspection */
-    public static function getCoverPhotoLocation(User $user, bool $forceWebP): ?string
-    {
-        if (!$user->coverPhotoHash || !$user->coverPhotoExtension) {
-            return null;
-        }
-
-        return \sprintf(
-            '%simages/coverPhotos/%s/%d-%s.%s',
-            WCF_DIR,
-            \substr(
-                $user->coverPhotoHash,
-                0,
-                2
-            ),
-            $user->userID,
-            $user->coverPhotoHash,
-            $forceWebP ? 'webp' : $user->coverPhotoExtension
-        );
-    }
 }
index b59723afe843666aa54c002b7c2fd850d6c52f89..521e59496db01ed6966b7f269c31349bb948ce44 100644 (file)
@@ -7,6 +7,7 @@ use wcf\data\reaction\type\ReactionTypeCache;
 use wcf\data\user\avatar\UserAvatar;
 use wcf\data\user\avatar\UserAvatarEditor;
 use wcf\data\user\avatar\UserAvatarList;
+use wcf\data\user\cover\photo\UserCoverPhoto;
 use wcf\data\user\User;
 use wcf\data\user\UserEditor;
 use wcf\data\user\UserList;
@@ -295,12 +296,23 @@ final class UserRebuildDataWorker extends AbstractLinearRebuildDataWorker
             $userProfiles->readObjects();
             foreach ($userProfiles as $user) {
                 $file = FileEditor::createFromExistingFile(
-                    SetCoverPhoto::getCoverPhotoLocation($user, false),
+                    UserCoverPhoto::getLegacyLocation($user, false),
                     $user->coverPhotoHash . '.' . $user->coverPhotoExtension,
                     'com.woltlab.wcf.user.coverPhoto',
                 );
 
                 (new SetCoverPhoto($user, $file))();
+
+                // Delete the old cover photo files.
+                $oldCoverPhotoLocation = UserCoverPhoto::getLegacyLocation($user, false);
+                $oldCoverPhotoWebPLocation = UserCoverPhoto::getLegacyLocation($user, true);
+
+                if ($oldCoverPhotoLocation && \file_exists($oldCoverPhotoLocation)) {
+                    @\unlink($oldCoverPhotoLocation);
+                }
+                if ($oldCoverPhotoWebPLocation && \file_exists($oldCoverPhotoWebPLocation)) {
+                    @\unlink($oldCoverPhotoWebPLocation);
+                }
             }
         }
     }