From be197bc82bbd2e66c1db2d23ad827c8ff4f23ebe Mon Sep 17 00:00:00 2001 From: Hugo Sales Date: Thu, 23 Dec 2021 14:52:03 +0000 Subject: [PATCH] [ENTITY][LocalUser] Fix LocalUser::setNicknameSanitizedAndCached so it updates the actor nickname and propagates the exceptions --- src/Entity/LocalUser.php | 26 ++++++-------------------- 1 file changed, 6 insertions(+), 20 deletions(-) diff --git a/src/Entity/LocalUser.php b/src/Entity/LocalUser.php index ed7192a46c..7a56e18ba0 100644 --- a/src/Entity/LocalUser.php +++ b/src/Entity/LocalUser.php @@ -29,7 +29,6 @@ use App\Core\Entity; use App\Core\UserRoles; use App\Util\Common; use App\Util\Exception\NicknameEmptyException; -use App\Util\Exception\NicknameException; use App\Util\Exception\NicknameInvalidException; use App\Util\Exception\NicknameNotAllowedException; use App\Util\Exception\NicknameTakenException; @@ -351,7 +350,6 @@ class LocalUser extends Entity implements UserInterface, PasswordAuthenticatedUs * Checks if desired nickname is allowed, and in case it is, it sets Actor's nickname cache to newly set nickname * * @param string $nickname Desired new nickname - * @param int $actor_id Used to cache Actor nickname * * @throws NicknameEmptyException * @throws NicknameInvalidException @@ -361,25 +359,13 @@ class LocalUser extends Entity implements UserInterface, PasswordAuthenticatedUs * * @return $this */ - public function setNicknameSanitizedAndCached(string $nickname, int $actor_id): self + public function setNicknameSanitizedAndCached(string $nickname): self { - try { - $nickname = Nickname::normalize($nickname, check_already_used: false, which: Nickname::CHECK_LOCAL_USER, check_is_allowed: true); - $this->nickname = $nickname; - Cache::set('actor-nickname-id-' . $actor_id, $nickname); - } catch (NicknameEmptyException $e) { - throw new NicknameEmptyException(); - } catch (NicknameInvalidException $e) { - throw new NicknameInvalidException(); - } catch (NicknameNotAllowedException $e) { - throw new NicknameNotAllowedException(); - } catch (NicknameTakenException $e) { - throw new NicknameTakenException(); - } catch (NicknameTooLongException $e) { - throw new NicknameTooLongException(); - } catch (NicknameException $e) { - } - + $nickname = Nickname::normalize($nickname, check_already_used: false, which: Nickname::CHECK_LOCAL_USER, check_is_allowed: true); + $this->setNickname($nickname); + $this->getActor()->setNickname($nickname); + Cache::delete(self::cacheKeys($this->getId())['nickname']); + Cache::delete(Actor::cacheKeys($this->getId())['nickname']); return $this; }