From e9c7e5706fc21a59a3830f62d478f6e62b62be7f Mon Sep 17 00:00:00 2001 From: Cyperghost Date: Wed, 4 Dec 2024 13:49:04 +0100 Subject: [PATCH] Rename `getCoverPhotoLocation()` to `getLegacyLocation()` and move to `UserCoverPhoto`. --- .../user/cover/photo/UserCoverPhoto.class.php | 25 +++++++++++++ .../user/command/SetCoverPhoto.class.php | 35 ------------------- .../worker/UserRebuildDataWorker.class.php | 14 +++++++- 3 files changed, 38 insertions(+), 36 deletions(-) diff --git a/wcfsetup/install/files/lib/data/user/cover/photo/UserCoverPhoto.class.php b/wcfsetup/install/files/lib/data/user/cover/photo/UserCoverPhoto.class.php index c3848663ad..173573e4c4 100644 --- a/wcfsetup/install/files/lib/data/user/cover/photo/UserCoverPhoto.class.php +++ b/wcfsetup/install/files/lib/data/user/cover/photo/UserCoverPhoto.class.php @@ -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 + ); + } } 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 4b26e6fa4e..2427ea100c 100644 --- a/wcfsetup/install/files/lib/system/user/command/SetCoverPhoto.class.php +++ b/wcfsetup/install/files/lib/system/user/command/SetCoverPhoto.class.php @@ -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 - ); - } } diff --git a/wcfsetup/install/files/lib/system/worker/UserRebuildDataWorker.class.php b/wcfsetup/install/files/lib/system/worker/UserRebuildDataWorker.class.php index b59723afe8..521e59496d 100644 --- a/wcfsetup/install/files/lib/system/worker/UserRebuildDataWorker.class.php +++ b/wcfsetup/install/files/lib/system/worker/UserRebuildDataWorker.class.php @@ -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); + } } } } -- 2.20.1