diff options
author | Joas Schilling <coding@schilljs.com> | 2023-07-25 21:45:07 +0200 |
---|---|---|
committer | Joas Schilling <coding@schilljs.com> | 2023-07-27 23:13:37 +0200 |
commit | ad12a740cb619d701de332eedda91dcbb1f53047 (patch) | |
tree | 3bb0fcd87424e72ca0f259e94232c361e7e695c1 /lib/private | |
parent | b93f101d6209905d22b90816bf6a0cfe89a38a8b (diff) | |
download | nextcloud-server-ad12a740cb619d701de332eedda91dcbb1f53047.tar.gz nextcloud-server-ad12a740cb619d701de332eedda91dcbb1f53047.zip |
fix!: Remove symfony EventDispatcherInterface from User
Signed-off-by: Joas Schilling <coding@schilljs.com>
Diffstat (limited to 'lib/private')
-rw-r--r-- | lib/private/Collaboration/Resources/Listener.php | 6 | ||||
-rw-r--r-- | lib/private/Server.php | 17 | ||||
-rw-r--r-- | lib/private/User/Manager.php | 8 | ||||
-rw-r--r-- | lib/private/User/User.php | 29 |
4 files changed, 13 insertions, 47 deletions
diff --git a/lib/private/Collaboration/Resources/Listener.php b/lib/private/Collaboration/Resources/Listener.php index d3b2f012a29..2263f5d3b1a 100644 --- a/lib/private/Collaboration/Resources/Listener.php +++ b/lib/private/Collaboration/Resources/Listener.php @@ -32,6 +32,7 @@ use OCP\Collaboration\Resources\LoadAdditionalScriptsEvent; use OCP\EventDispatcher\IEventDispatcher; use OCP\IGroup; use OCP\IUser; +use OCP\User\Events\UserDeletedEvent; use Symfony\Component\EventDispatcher\GenericEvent; class Listener { @@ -47,9 +48,8 @@ class Listener { $symfonyDispatcher->addListener(IGroup::class . '::postAddUser', $listener); $symfonyDispatcher->addListener(IGroup::class . '::postRemoveUser', $listener); - $symfonyDispatcher->addListener(IUser::class . '::postDelete', function (GenericEvent $event) { - /** @var IUser $user */ - $user = $event->getSubject(); + $eventDispatcher->addListener(UserDeletedEvent::class, function (UserDeletedEvent $event) { + $user = $event->getUser(); /** @var IManager $resourceManager */ $resourceManager = \OCP\Server::get(IManager::class); diff --git a/lib/private/Server.php b/lib/private/Server.php index 86f5192a39d..6c7dcb730eb 100644 --- a/lib/private/Server.php +++ b/lib/private/Server.php @@ -566,8 +566,6 @@ class Server extends ServerContainer implements IServerContainer { $provider = null; } - $legacyDispatcher = $c->get(SymfonyAdapter::class); - $userSession = new \OC\User\Session( $manager, $session, @@ -589,10 +587,9 @@ class Server extends ServerContainer implements IServerContainer { \OC_Hook::emit('OC_User', 'post_createUser', ['uid' => $user->getUID(), 'password' => $password]); }); /** @deprecated 21.0.0 use BeforeUserDeletedEvent event with the IEventDispatcher instead */ - $userSession->listen('\OC\User', 'preDelete', function ($user) use ($legacyDispatcher) { + $userSession->listen('\OC\User', 'preDelete', function ($user) { /** @var \OC\User\User $user */ \OC_Hook::emit('OC_User', 'pre_deleteUser', ['run' => true, 'uid' => $user->getUID()]); - $legacyDispatcher->dispatch('OCP\IUser::preDelete', new GenericEvent($user)); }); /** @deprecated 21.0.0 use UserDeletedEvent event with the IEventDispatcher instead */ $userSession->listen('\OC\User', 'postDelete', function ($user) { @@ -602,18 +599,10 @@ class Server extends ServerContainer implements IServerContainer { $userSession->listen('\OC\User', 'preSetPassword', function ($user, $password, $recoveryPassword) { /** @var \OC\User\User $user */ \OC_Hook::emit('OC_User', 'pre_setPassword', ['run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword]); - - /** @var IEventDispatcher $dispatcher */ - $dispatcher = $this->get(IEventDispatcher::class); - $dispatcher->dispatchTyped(new BeforePasswordUpdatedEvent($user, $password, $recoveryPassword)); }); $userSession->listen('\OC\User', 'postSetPassword', function ($user, $password, $recoveryPassword) { /** @var \OC\User\User $user */ \OC_Hook::emit('OC_User', 'post_setPassword', ['run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword]); - - /** @var IEventDispatcher $dispatcher */ - $dispatcher = $this->get(IEventDispatcher::class); - $dispatcher->dispatchTyped(new PasswordUpdatedEvent($user, $password, $recoveryPassword)); }); $userSession->listen('\OC\User', 'preLogin', function ($uid, $password) { \OC_Hook::emit('OC_User', 'pre_login', ['run' => true, 'uid' => $uid, 'password' => $password]); @@ -658,10 +647,6 @@ class Server extends ServerContainer implements IServerContainer { $userSession->listen('\OC\User', 'changeUser', function ($user, $feature, $value, $oldValue) { /** @var \OC\User\User $user */ \OC_Hook::emit('OC_User', 'changeUser', ['run' => true, 'user' => $user, 'feature' => $feature, 'value' => $value, 'old_value' => $oldValue]); - - /** @var IEventDispatcher $dispatcher */ - $dispatcher = $this->get(IEventDispatcher::class); - $dispatcher->dispatchTyped(new UserChangedEvent($user, $feature, $value, $oldValue)); }); return $userSession; }); diff --git a/lib/private/User/Manager.php b/lib/private/User/Manager.php index 60059d5badd..fb1afb65825 100644 --- a/lib/private/User/Manager.php +++ b/lib/private/User/Manager.php @@ -55,7 +55,6 @@ use OCP\User\Backend\ICountUsersBackend; use OCP\User\Events\BeforeUserCreatedEvent; use OCP\User\Events\UserCreatedEvent; use OCP\UserInterface; -use Symfony\Component\EventDispatcher\EventDispatcherInterface; /** * Class Manager @@ -88,9 +87,6 @@ class Manager extends PublicEmitter implements IUserManager { /** @var IConfig */ private $config; - /** @var EventDispatcherInterface */ - private $dispatcher; - /** @var ICache */ private $cache; @@ -100,11 +96,9 @@ class Manager extends PublicEmitter implements IUserManager { private DisplayNameCache $displayNameCache; public function __construct(IConfig $config, - EventDispatcherInterface $oldDispatcher, ICacheFactory $cacheFactory, IEventDispatcher $eventDispatcher) { $this->config = $config; - $this->dispatcher = $oldDispatcher; $this->cache = new WithLocalCache($cacheFactory->createDistributed('user_backend_map')); $cachedUsers = &$this->cachedUsers; $this->listen('\OC\User', 'postDelete', function ($user) use (&$cachedUsers) { @@ -211,7 +205,7 @@ class Manager extends PublicEmitter implements IUserManager { return $this->cachedUsers[$uid]; } - $user = new User($uid, $backend, $this->dispatcher, $this, $this->config); + $user = new User($uid, $backend, $this->eventDispatcher, $this, $this->config); if ($cacheUser) { $this->cachedUsers[$uid] = $user; } diff --git a/lib/private/User/User.php b/lib/private/User/User.php index 2530173bea4..d1185e17aef 100644 --- a/lib/private/User/User.php +++ b/lib/private/User/User.php @@ -49,7 +49,10 @@ use OCP\IImage; use OCP\IURLGenerator; use OCP\IUser; use OCP\IUserBackend; +use OCP\User\Events\BeforePasswordUpdatedEvent; use OCP\User\Events\BeforeUserDeletedEvent; +use OCP\User\Events\PasswordUpdatedEvent; +use OCP\User\Events\UserChangedEvent; use OCP\User\Events\UserDeletedEvent; use OCP\User\GetQuotaEvent; use OCP\User\Backend\ISetDisplayNameBackend; @@ -58,8 +61,6 @@ use OCP\User\Backend\IProvideAvatarBackend; use OCP\User\Backend\IProvideEnabledStateBackend; use OCP\User\Backend\IGetHomeBackend; use OCP\UserInterface; -use Symfony\Component\EventDispatcher\EventDispatcherInterface; -use Symfony\Component\EventDispatcher\GenericEvent; use function json_decode; use function json_encode; @@ -76,8 +77,6 @@ class User implements IUser { /** @var UserInterface|null */ private $backend; - /** @var EventDispatcherInterface */ - private $legacyDispatcher; /** @var IEventDispatcher */ private $dispatcher; @@ -103,10 +102,9 @@ class User implements IUser { /** @var IURLGenerator */ private $urlGenerator; - public function __construct(string $uid, ?UserInterface $backend, EventDispatcherInterface $dispatcher, $emitter = null, IConfig $config = null, $urlGenerator = null) { + public function __construct(string $uid, ?UserInterface $backend, IEventDispatcher $dispatcher, $emitter = null, IConfig $config = null, $urlGenerator = null) { $this->uid = $uid; $this->backend = $backend; - $this->legacyDispatcher = $dispatcher; $this->emitter = $emitter; if (is_null($config)) { $config = \OC::$server->getConfig(); @@ -116,8 +114,7 @@ class User implements IUser { if (is_null($this->urlGenerator)) { $this->urlGenerator = \OC::$server->getURLGenerator(); } - // TODO: inject - $this->dispatcher = \OCP\Server::get(IEventDispatcher::class); + $this->dispatcher = $dispatcher; } /** @@ -325,10 +322,7 @@ class User implements IUser { * @return bool */ public function setPassword($password, $recoveryPassword = null) { - $this->legacyDispatcher->dispatch(IUser::class . '::preSetPassword', new GenericEvent($this, [ - 'password' => $password, - 'recoveryPassword' => $recoveryPassword, - ])); + $this->dispatcher->dispatchTyped(new BeforePasswordUpdatedEvent($this, $password, $recoveryPassword)); if ($this->emitter) { $this->emitter->emit('\OC\User', 'preSetPassword', [$this, $password, $recoveryPassword]); } @@ -338,10 +332,7 @@ class User implements IUser { $result = $backend->setPassword($this->uid, $password); if ($result !== false) { - $this->legacyDispatcher->dispatch(IUser::class . '::postSetPassword', new GenericEvent($this, [ - 'password' => $password, - 'recoveryPassword' => $recoveryPassword, - ])); + $this->dispatcher->dispatchTyped(new PasswordUpdatedEvent($this, $password, $recoveryPassword)); if ($this->emitter) { $this->emitter->emit('\OC\User', 'postSetPassword', [$this, $password, $recoveryPassword]); } @@ -622,11 +613,7 @@ class User implements IUser { } public function triggerChange($feature, $value = null, $oldValue = null) { - $this->legacyDispatcher->dispatch(IUser::class . '::changeUser', new GenericEvent($this, [ - 'feature' => $feature, - 'value' => $value, - 'oldValue' => $oldValue, - ])); + $this->dispatcher->dispatchTyped(new UserChangedEvent($this, $feature, $value, $oldValue)); if ($this->emitter) { $this->emitter->emit('\OC\User', 'changeUser', [$this, $feature, $value, $oldValue]); } |