mirror of
https://github.com/flarum/framework.git
synced 2025-02-06 04:09:46 +08:00
Fix AvatarChanged event (#2197)
* Fix AvatarChanged event not being dispatched when changing avatar Also fix the uploader to trigger the event only once
This commit is contained in:
parent
b3c2672634
commit
2261f4f220
|
@ -36,13 +36,18 @@ class AvatarUploader
|
|||
|
||||
$avatarPath = Str::random().'.png';
|
||||
|
||||
$this->remove($user);
|
||||
$this->removeFileAfterSave($user);
|
||||
$user->changeAvatarPath($avatarPath);
|
||||
|
||||
$this->uploadDir->put($avatarPath, $encodedImage);
|
||||
}
|
||||
|
||||
public function remove(User $user)
|
||||
/**
|
||||
* Handle the removal of the old avatar file after a successful user save
|
||||
* We don't place this in remove() because otherwise we would call changeAvatarPath 2 times when uploading.
|
||||
* @param User $user
|
||||
*/
|
||||
protected function removeFileAfterSave(User $user)
|
||||
{
|
||||
$avatarPath = $user->getOriginal('avatar_url');
|
||||
|
||||
|
@ -51,6 +56,14 @@ class AvatarUploader
|
|||
$this->uploadDir->delete($avatarPath);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @param User $user
|
||||
*/
|
||||
public function remove(User $user)
|
||||
{
|
||||
$this->removeFileAfterSave($user);
|
||||
|
||||
$user->changeAvatarPath(null);
|
||||
}
|
||||
|
|
|
@ -80,6 +80,8 @@ class UploadAvatarHandler
|
|||
|
||||
$user->save();
|
||||
|
||||
$this->dispatchEventsFor($user, $actor);
|
||||
|
||||
return $user;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user