*/
final class UserAvatarFileProcessor extends AbstractFileProcessor
{
+ private const SESSION_VARIABLE = 'wcf_user_avatar_processor_%d';
+
#[\Override]
public function getObjectTypeName(): string
{
return;
}
+ // Save the `fileID` in the session variable so that the current user can delete it the old avatar
+ if ($user->avatarFileID !== null) {
+ WCF::getSession()->register(\sprintf(self::SESSION_VARIABLE, $$user->avatarFileID), TIME_NOW);
+ WCF::getSession()->update();
+ }
+
(new UserEditor($user))->update([
'avatarFileID' => $file->fileID,
]);
{
$user = $this->getUserByFile($file);
if ($user === null) {
- return false;
+ return WCF::getSession()->getVar(
+ \sprintf(self::SESSION_VARIABLE, $file->fileID)
+ ) !== null;
}
return $this->canEditAvatar($user);
#[\Override]
public function delete(array $fileIDs, array $thumbnailIDs): void
{
+ \array_map(
+ static fn(int $fileID) => WCF::getSession()->unregister(
+ \sprintf(self::SESSION_VARIABLE, $fileID)
+ ),
+ $fileIDs
+ );
+
$conditionBuilder = new PreparedStatementConditionBuilder();
$conditionBuilder->add('avatarFileID IN (?)', [$fileIDs]);