diff options
author | Joas Schilling <coding@schilljs.com> | 2023-07-27 23:01:40 +0200 |
---|---|---|
committer | Joas Schilling <coding@schilljs.com> | 2023-07-28 14:11:21 +0200 |
commit | 0c5d0c2127d570768453eeb8799b01aecb455228 (patch) | |
tree | ee6e7463066ea2397b6263ec6f098010b9ee6f73 /lib | |
parent | ead47610c1283b09daf63f3d59170988d4f29693 (diff) | |
download | nextcloud-server-0c5d0c2127d570768453eeb8799b01aecb455228.tar.gz nextcloud-server-0c5d0c2127d570768453eeb8799b01aecb455228.zip |
fix: Migrate collaboration listener and remove legacy adapter
Signed-off-by: Joas Schilling <coding@schilljs.com>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/base.php | 3 | ||||
-rw-r--r-- | lib/private/Collaboration/Resources/Listener.php | 50 |
2 files changed, 17 insertions, 36 deletions
diff --git a/lib/base.php b/lib/base.php index ed62494ab30..2dd9a4d59f0 100644 --- a/lib/base.php +++ b/lib/base.php @@ -67,7 +67,6 @@ declare(strict_types=1); */ use OC\Encryption\HookManager; -use OC\EventDispatcher\SymfonyAdapter; use OC\Share20\Hooks; use OCP\EventDispatcher\IEventDispatcher; use OCP\Group\Events\UserRemovedEvent; @@ -939,7 +938,7 @@ class OC { } private static function registerResourceCollectionHooks(): void { - \OC\Collaboration\Resources\Listener::register(Server::get(SymfonyAdapter::class), Server::get(IEventDispatcher::class)); + \OC\Collaboration\Resources\Listener::register(Server::get(IEventDispatcher::class)); } private static function registerFileReferenceEventListener(): void { diff --git a/lib/private/Collaboration/Resources/Listener.php b/lib/private/Collaboration/Resources/Listener.php index 2263f5d3b1a..4330f3570bc 100644 --- a/lib/private/Collaboration/Resources/Listener.php +++ b/lib/private/Collaboration/Resources/Listener.php @@ -26,27 +26,29 @@ declare(strict_types=1); */ namespace OC\Collaboration\Resources; -use OC\EventDispatcher\SymfonyAdapter; use OCP\Collaboration\Resources\IManager; -use OCP\Collaboration\Resources\LoadAdditionalScriptsEvent; use OCP\EventDispatcher\IEventDispatcher; -use OCP\IGroup; -use OCP\IUser; +use OCP\Group\Events\BeforeGroupDeletedEvent; +use OCP\Group\Events\UserAddedEvent; +use OCP\Group\Events\UserRemovedEvent; use OCP\User\Events\UserDeletedEvent; -use Symfony\Component\EventDispatcher\GenericEvent; class Listener { - public static function register(SymfonyAdapter $symfonyDispatcher, IEventDispatcher $eventDispatcher): void { - $listener = function (GenericEvent $event) { - /** @var IUser $user */ - $user = $event->getArgument('user'); + public static function register(IEventDispatcher $eventDispatcher): void { + $eventDispatcher->addListener(UserAddedEvent::class, function (UserAddedEvent $event) { + $user = $event->getUser(); /** @var IManager $resourceManager */ $resourceManager = \OCP\Server::get(IManager::class); $resourceManager->invalidateAccessCacheForUser($user); - }; - $symfonyDispatcher->addListener(IGroup::class . '::postAddUser', $listener); - $symfonyDispatcher->addListener(IGroup::class . '::postRemoveUser', $listener); + }); + $eventDispatcher->addListener(UserRemovedEvent::class, function (UserRemovedEvent $event) { + $user = $event->getUser(); + /** @var IManager $resourceManager */ + $resourceManager = \OCP\Server::get(IManager::class); + + $resourceManager->invalidateAccessCacheForUser($user); + }); $eventDispatcher->addListener(UserDeletedEvent::class, function (UserDeletedEvent $event) { $user = $event->getUser(); @@ -56,9 +58,8 @@ class Listener { $resourceManager->invalidateAccessCacheForUser($user); }); - $symfonyDispatcher->addListener(IGroup::class . '::preDelete', function (GenericEvent $event) { - /** @var IGroup $group */ - $group = $event->getSubject(); + $eventDispatcher->addListener(BeforeGroupDeletedEvent::class, function (BeforeGroupDeletedEvent $event) { + $group = $event->getGroup(); /** @var IManager $resourceManager */ $resourceManager = \OCP\Server::get(IManager::class); @@ -66,24 +67,5 @@ class Listener { $resourceManager->invalidateAccessCacheForUser($user); } }); - - // Stay backward compatible with the legacy event for now - $fallbackEventRunning = false; - $symfonyDispatcher->addListener('\OCP\Collaboration\Resources::loadAdditionalScripts', function () use ($eventDispatcher, &$fallbackEventRunning) { - if ($fallbackEventRunning) { - return; - } - $fallbackEventRunning = true; - $eventDispatcher->dispatchTyped(new LoadAdditionalScriptsEvent()); - $fallbackEventRunning = false; - }); - $eventDispatcher->addListener(LoadAdditionalScriptsEvent::class, static function () use ($symfonyDispatcher, &$fallbackEventRunning) { - if ($fallbackEventRunning) { - return; - } - $fallbackEventRunning = true; - $symfonyDispatcher->dispatch('\OCP\Collaboration\Resources::loadAdditionalScripts'); - $fallbackEventRunning = false; - }); } } |