use wcf\data\file\File;
use wcf\data\file\FileAction;
+use wcf\data\user\User;
/**
* Represents a user's cover photo.
],
];
}
+
+ /**
+ * 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
+ );
+ }
}
(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,
]);
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
- );
- }
}
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;
$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);
+ }
}
}
}