]> source.dussan.org Git - nextcloud-server.git/commitdiff
fix(dispatcher): Move remaining simple cases in apps/ folder to IEventDispatcher 39485/head
authorJoas Schilling <coding@schilljs.com>
Wed, 19 Jul 2023 19:56:34 +0000 (21:56 +0200)
committerJoas Schilling <coding@schilljs.com>
Tue, 25 Jul 2023 09:19:26 +0000 (11:19 +0200)
Signed-off-by: Joas Schilling <coding@schilljs.com>
apps/dav/lib/RootCollection.php
apps/dav/lib/SystemTag/SystemTagsRelationsCollection.php
apps/files/lib/Collaboration/Resources/Listener.php
apps/files/tests/Controller/ViewControllerTest.php
apps/files_external/tests/Controller/StoragesControllerTest.php
apps/files_sharing/lib/AppInfo/Application.php
apps/files_sharing/tests/ApplicationTest.php
apps/user_ldap/lib/AppInfo/Application.php
apps/workflowengine/tests/ManagerTest.php
lib/public/SystemTag/SystemTagsEntityEvent.php

index e4fd814ed817b5402276920ac3721e4bbf00fcf1..90be581a2a939e1ea08031394379a3a09129ad50 100644 (file)
@@ -132,7 +132,7 @@ class RootCollection extends SimpleCollection {
                        \OC::$server->getSystemTagObjectMapper(),
                        \OC::$server->getUserSession(),
                        $groupManager,
-                       \OC::$server->getEventDispatcher()
+                       $dispatcher
                );
                $systemTagInUseCollection = \OCP\Server::get(SystemTag\SystemTagsInUseCollection::class);
                $commentsCollection = new Comments\RootCollection(
index 4c179d5f0f6618f3e2793c17162d9be394bc2709..6c44713cb05660bd8d240911a5032a533835a565 100644 (file)
@@ -26,6 +26,7 @@
  */
 namespace OCA\DAV\SystemTag;
 
+use OCP\EventDispatcher\IEventDispatcher;
 use OCP\IGroupManager;
 use OCP\IUserSession;
 use OCP\SystemTag\ISystemTagManager;
@@ -33,25 +34,14 @@ use OCP\SystemTag\ISystemTagObjectMapper;
 use OCP\SystemTag\SystemTagsEntityEvent;
 use Sabre\DAV\Exception\Forbidden;
 use Sabre\DAV\SimpleCollection;
-use Symfony\Component\EventDispatcher\EventDispatcherInterface;
 
 class SystemTagsRelationsCollection extends SimpleCollection {
-
-       /**
-        * SystemTagsRelationsCollection constructor.
-        *
-        * @param ISystemTagManager $tagManager
-        * @param ISystemTagObjectMapper $tagMapper
-        * @param IUserSession $userSession
-        * @param IGroupManager $groupManager
-        * @param EventDispatcherInterface $dispatcher
-        */
        public function __construct(
                ISystemTagManager $tagManager,
                ISystemTagObjectMapper $tagMapper,
                IUserSession $userSession,
                IGroupManager $groupManager,
-               EventDispatcherInterface $dispatcher
+               IEventDispatcher $dispatcher,
        ) {
                $children = [
                        new SystemTagsObjectTypeCollection(
@@ -67,8 +57,9 @@ class SystemTagsRelationsCollection extends SimpleCollection {
                        ),
                ];
 
-               $event = new SystemTagsEntityEvent(SystemTagsEntityEvent::EVENT_ENTITY);
+               $event = new SystemTagsEntityEvent();
                $dispatcher->dispatch(SystemTagsEntityEvent::EVENT_ENTITY, $event);
+               $dispatcher->dispatchTyped($event);
 
                foreach ($event->getEntityCollections() as $entity => $entityExistsFunction) {
                        $children[] = new SystemTagsObjectTypeCollection(
index 64dd693a4da4e4b80c2cf43d959b1e85c0ba8623..28ce5f8789704c6d494a08e3f80301ce56e3c1a4 100644 (file)
@@ -25,12 +25,12 @@ declare(strict_types=1);
  */
 namespace OCA\Files\Collaboration\Resources;
 
+use OCP\EventDispatcher\IEventDispatcher;
 use OCP\Server;
 use OCP\Collaboration\Resources\IManager;
-use Symfony\Component\EventDispatcher\EventDispatcherInterface;
 
 class Listener {
-       public static function register(EventDispatcherInterface $dispatcher): void {
+       public static function register(IEventDispatcher $dispatcher): void {
                $dispatcher->addListener('OCP\Share::postShare', [self::class, 'shareModification']);
                $dispatcher->addListener('OCP\Share::postUnshare', [self::class, 'shareModification']);
                $dispatcher->addListener('OCP\Share::postUnshareFromSelf', [self::class, 'shareModification']);
index 05f35f32f0a61a643145698b91cbe2fc2ef45ec3..2fa98be9fcd9c18d7109b6434acbcdea4f5cedcc 100644 (file)
@@ -52,7 +52,6 @@ use OCP\IUser;
 use OCP\IUserSession;
 use OCP\Share\IManager;
 use OCP\Template;
-use Symfony\Component\EventDispatcher\EventDispatcherInterface;
 use Test\TestCase;
 
 /**
@@ -69,7 +68,7 @@ class ViewControllerTest extends TestCase {
        private $l10n;
        /** @var IConfig|\PHPUnit\Framework\MockObject\MockObject */
        private $config;
-       /** @var EventDispatcherInterface */
+       /** @var IEventDispatcher */
        private $eventDispatcher;
        /** @var ViewController|\PHPUnit\Framework\MockObject\MockObject */
        private $viewController;
index bb9be2f2d4a80e2be8ae23a27d6e54c161241fd3..5b3eb6d79833a2170d11ded35fbebbdeeda752f4 100644 (file)
@@ -34,7 +34,9 @@ use OCA\Files_External\Lib\Backend\Backend;
 use OCA\Files_External\Lib\StorageConfig;
 use OCA\Files_External\NotFoundException;
 use OCA\Files_External\Service\GlobalStoragesService;
+use OCA\Files_External\Service\UserStoragesService;
 use OCP\AppFramework\Http;
+use PHPUnit\Framework\MockObject\MockObject;
 
 abstract class StoragesControllerTest extends \Test\TestCase {
 
@@ -44,7 +46,7 @@ abstract class StoragesControllerTest extends \Test\TestCase {
        protected $controller;
 
        /**
-        * @var GlobalStoragesService
+        * @var GlobalStoragesService|UserStoragesService|MockObject
         */
        protected $service;
 
@@ -57,7 +59,7 @@ abstract class StoragesControllerTest extends \Test\TestCase {
        }
 
        /**
-        * @return \OCA\Files_External\Lib\Backend\Backend
+        * @return \OCA\Files_External\Lib\Backend\Backend|MockObject
         */
        protected function getBackendMock($class = '\OCA\Files_External\Lib\Backend\SMB', $storageClass = '\OCA\Files_External\Lib\Storage\SMB') {
                $backend = $this->getMockBuilder(Backend::class)
@@ -73,7 +75,7 @@ abstract class StoragesControllerTest extends \Test\TestCase {
        }
 
        /**
-        * @return \OCA\Files_External\Lib\Auth\AuthMechanism
+        * @return \OCA\Files_External\Lib\Auth\AuthMechanism|MockObject
         */
        protected function getAuthMechMock($scheme = 'null', $class = '\OCA\Files_External\Lib\Auth\NullMechanism') {
                $authMech = $this->getMockBuilder(AuthMechanism::class)
index 946d82a3df7facd93d514f6df3f0915cf8d74a26..65197e9b27040041077f6a13ac0db447d1a2f062 100644 (file)
@@ -51,7 +51,6 @@ use OCA\Files_Sharing\Notification\Listener;
 use OCA\Files_Sharing\Notification\Notifier;
 use OCA\Files\Event\LoadAdditionalScriptsEvent;
 use OCA\Files\Event\LoadSidebar;
-use OCP\Files\Event\BeforeDirectGetEvent;
 use OCA\Files_Sharing\ShareBackend\File;
 use OCA\Files_Sharing\ShareBackend\Folder;
 use OCA\Files_Sharing\ViewOnly;
@@ -61,7 +60,6 @@ use OCP\AppFramework\Bootstrap\IBootstrap;
 use OCP\AppFramework\Bootstrap\IRegistrationContext;
 use OCP\Collaboration\Resources\LoadAdditionalScriptsEvent as ResourcesLoadAdditionalScriptsEvent;
 use OCP\EventDispatcher\IEventDispatcher;
-use OCP\EventDispatcher\GenericEvent;
 use OCP\Federation\ICloudIdManager;
 use OCP\Files\Config\IMountProviderCollection;
 use OCP\Files\Events\BeforeDirectFileDownloadEvent;
@@ -72,13 +70,10 @@ use OCP\Group\Events\UserAddedEvent;
 use OCP\IDBConnection;
 use OCP\IGroup;
 use OCP\IUserSession;
-use OCP\L10N\IFactory;
 use OCP\Share\Events\ShareCreatedEvent;
-use OCP\Share\IManager;
 use OCP\User\Events\UserChangedEvent;
 use OCP\Util;
 use Psr\Container\ContainerInterface;
-use Symfony\Component\EventDispatcher\EventDispatcherInterface;
 use Symfony\Component\EventDispatcher\GenericEvent as OldGenericEvent;
 
 class Application extends App implements IBootstrap {
@@ -135,7 +130,7 @@ class Application extends App implements IBootstrap {
                $mountProviderCollection->registerProvider($externalMountProvider);
        }
 
-       public function registerEventsScripts(IEventDispatcher $dispatcher, EventDispatcherInterface $oldDispatcher): void {
+       public function registerEventsScripts(IEventDispatcher $dispatcher): void {
                // sidebar and files scripts
                $dispatcher->addServiceListener(LoadAdditionalScriptsEvent::class, LoadAdditionalListener::class);
                $dispatcher->addServiceListener(BeforeTemplateRenderedEvent::class, LegacyBeforeTemplateRenderedListener::class);
@@ -148,12 +143,18 @@ class Application extends App implements IBootstrap {
                });
 
                // notifications api to accept incoming user shares
-               $oldDispatcher->addListener('OCP\Share::postShare', function (OldGenericEvent $event) {
+               $dispatcher->addListener('OCP\Share::postShare', function ($event) {
+                       if (!$event instanceof OldGenericEvent) {
+                               return;
+                       }
                        /** @var Listener $listener */
                        $listener = $this->getContainer()->query(Listener::class);
                        $listener->shareNotification($event);
                });
-               $oldDispatcher->addListener(IGroup::class . '::postAddUser', function (OldGenericEvent $event) {
+               $dispatcher->addListener(IGroup::class . '::postAddUser', function ($event) {
+                       if (!$event instanceof OldGenericEvent) {
+                               return;
+                       }
                        /** @var Listener $listener */
                        $listener = $this->getContainer()->query(Listener::class);
                        $listener->userAddedToGroup($event);
index 11c8137c398c57ec6473538eed63d125fa82dde2..d16aed61bf7e5cf3d13a5b6e0c1aaa74601a67ae 100644 (file)
@@ -25,16 +25,11 @@ namespace OCA\Files_Sharing\Tests;
 use OCP\Files\Events\BeforeDirectFileDownloadEvent;
 use OCP\Files\Events\BeforeZipCreatedEvent;
 use Psr\Log\LoggerInterface;
-use OC\Share20\LegacyHooks;
 use OC\Share20\Manager;
 use OC\EventDispatcher\EventDispatcher;
 use OCA\Files_Sharing\AppInfo\Application;
 use OCA\Files_Sharing\SharedStorage;
-use OCP\Constants;
-use OCP\EventDispatcher\GenericEvent;
 use OCP\EventDispatcher\IEventDispatcher;
-use OCP\Files\Cache\ICacheEntry;
-use OCP\Files\Event\BeforeDirectGetEvent;
 use OCP\Files\File;
 use OCP\Files\Folder;
 use OCP\Files\IRootFolder;
@@ -57,7 +52,8 @@ class ApplicationTest extends TestCase {
        /** @var IRootFolder */
        private $rootFolder;
 
-       /** @var Manager */ private $manager;
+       /** @var Manager */
+       private $manager;
 
        protected function setUp(): void {
                parent::setUp();
index 757ac141d3d0e06d38265a809e3d680a4c085b68..d6fb062a0285a08c4148410ac6cab67b7469af37 100644 (file)
@@ -59,7 +59,6 @@ use OCP\Notification\IManager as INotificationManager;
 use OCP\Share\IManager as IShareManager;
 use Psr\Container\ContainerInterface;
 use Psr\Log\LoggerInterface;
-use Symfony\Component\EventDispatcher\EventDispatcherInterface;
 
 class Application extends App implements IBootstrap {
        public function __construct() {
@@ -120,7 +119,6 @@ class Application extends App implements IBootstrap {
                $context->injectFn(function (
                        INotificationManager $notificationManager,
                        IAppContainer $appContainer,
-                       EventDispatcherInterface $legacyDispatcher,
                        IEventDispatcher $dispatcher,
                        IGroupManager $groupManager,
                        User_Proxy $userBackend,
@@ -136,7 +134,7 @@ class Application extends App implements IBootstrap {
                                $groupManager->addBackend($groupBackend);
 
                                $userBackendRegisteredEvent = new UserBackendRegistered($userBackend, $userPluginManager);
-                               $legacyDispatcher->dispatch('OCA\\User_LDAP\\User\\User::postLDAPBackendAdded', $userBackendRegisteredEvent);
+                               $dispatcher->dispatch('OCA\\User_LDAP\\User\\User::postLDAPBackendAdded', $userBackendRegisteredEvent);
                                $dispatcher->dispatchTyped($userBackendRegisteredEvent);
                                $groupBackendRegisteredEvent = new GroupBackendRegistered($groupBackend, $groupPluginManager);
                                $dispatcher->dispatchTyped($groupBackendRegisteredEvent);
@@ -153,7 +151,7 @@ class Application extends App implements IBootstrap {
                );
        }
 
-       private function registerBackendDependents(IAppContainer $appContainer, EventDispatcherInterface $dispatcher) {
+       private function registerBackendDependents(IAppContainer $appContainer, IEventDispatcher $dispatcher) {
                $dispatcher->addListener(
                        'OCA\\Files_External::loadAdditionalBackends',
                        function () use ($appContainer) {
index dee6b5084543985faf6ec60e3ff241b0f59d59ed..213daf49415f2b527f3349a38b5677efbed85bdd 100644 (file)
@@ -52,7 +52,6 @@ use OCP\WorkflowEngine\IEntityEvent;
 use OCP\WorkflowEngine\IManager;
 use OCP\WorkflowEngine\IOperation;
 use PHPUnit\Framework\MockObject\MockObject;
-use Symfony\Component\EventDispatcher\EventDispatcherInterface;
 use Test\TestCase;
 
 /**
index 4360d924c23e613d0724804c78ea3f720faf0412..0ce679a3a43a92ad3640141879c4b5c5f297728c 100644 (file)
@@ -33,26 +33,22 @@ use OCP\EventDispatcher\Event;
  * Class SystemTagsEntityEvent
  *
  * @since 9.1.0
+ * @since 28.0.0 Dispatched as a typed event
  */
 class SystemTagsEntityEvent extends Event {
        /**
-        * @deprecated 22.0.0
+        * @deprecated 22.0.0 Listen to the typed event instead
         */
        public const EVENT_ENTITY = 'OCP\SystemTag\ISystemTagManager::registerEntity';
 
-       /** @var string */
-       protected $event;
        /** @var \Closure[] */
        protected $collections;
 
        /**
-        * SystemTagsEntityEvent constructor.
-        *
-        * @param string $event
         * @since 9.1.0
         */
-       public function __construct(string $event) {
-               $this->event = $event;
+       public function __construct() {
+               parent::__construct();
                $this->collections = [];
        }