]> source.dussan.org Git - nextcloud-server.git/commitdiff
fix(comments): Emit CommentsEntityEvent as typed event 39304/head
authorJoas Schilling <coding@schilljs.com>
Tue, 11 Jul 2023 09:06:29 +0000 (11:06 +0200)
committerJoas Schilling <coding@schilljs.com>
Tue, 18 Jul 2023 14:19:01 +0000 (16:19 +0200)
Signed-off-by: Joas Schilling <coding@schilljs.com>
apps/comments/lib/AppInfo/Application.php
apps/dav/lib/Comments/RootCollection.php
apps/dav/lib/RootCollection.php
apps/dav/tests/unit/Comments/RootCollectionTest.php
lib/public/Comments/CommentsEntityEvent.php

index bfd66c43ecd78ed46e6b5a70c561d35bbd9a10a9..db147970a64c6a930238f204ec78fbc3b1d683bf 100644 (file)
@@ -66,7 +66,7 @@ class Application extends App implements IBootstrap {
                        LoadSidebarScripts::class
                );
                $context->registerEventListener(
-                       CommentsEntityEvent::EVENT_ENTITY,
+                       CommentsEntityEvent::class,
                        CommentsEntityEventListener::class
                );
                $context->registerSearchProvider(CommentsSearchProvider::class);
index 39d644b476690735e273f02256d4857c75f38060..956980c900dd7b8b40b2bbddef3e40c580df8508 100644 (file)
@@ -26,6 +26,7 @@ namespace OCA\DAV\Comments;
 
 use OCP\Comments\CommentsEntityEvent;
 use OCP\Comments\ICommentsManager;
+use OCP\EventDispatcher\IEventDispatcher;
 use OCP\IUserManager;
 use OCP\IUserSession;
 use Psr\Log\LoggerInterface;
@@ -33,7 +34,6 @@ use Sabre\DAV\Exception\Forbidden;
 use Sabre\DAV\Exception\NotAuthenticated;
 use Sabre\DAV\Exception\NotFound;
 use Sabre\DAV\ICollection;
-use Symfony\Component\EventDispatcher\EventDispatcherInterface;
 
 class RootCollection implements ICollection {
        /** @var EntityTypeCollection[]|null */
@@ -43,13 +43,13 @@ class RootCollection implements ICollection {
        protected LoggerInterface $logger;
        protected IUserManager $userManager;
        protected IUserSession $userSession;
-       protected EventDispatcherInterface $dispatcher;
+       protected IEventDispatcher $dispatcher;
 
        public function __construct(
                ICommentsManager $commentsManager,
                IUserManager $userManager,
                IUserSession $userSession,
-               EventDispatcherInterface $dispatcher,
+               IEventDispatcher $dispatcher,
                LoggerInterface $logger) {
                $this->commentsManager = $commentsManager;
                $this->logger = $logger;
@@ -74,7 +74,8 @@ class RootCollection implements ICollection {
                        throw new NotAuthenticated();
                }
 
-               $event = new CommentsEntityEvent(CommentsEntityEvent::EVENT_ENTITY);
+               $event = new CommentsEntityEvent();
+               $this->dispatcher->dispatchTyped($event);
                $this->dispatcher->dispatch(CommentsEntityEvent::EVENT_ENTITY, $event);
 
                $this->entityTypeCollections = [];
index 80d96f0d7483f5f6dde0a290755e39b5941c942f..e4fd814ed817b5402276920ac3721e4bbf00fcf1 100644 (file)
@@ -139,7 +139,7 @@ class RootCollection extends SimpleCollection {
                        \OC::$server->getCommentsManager(),
                        $userManager,
                        \OC::$server->getUserSession(),
-                       \OC::$server->getEventDispatcher(),
+                       $dispatcher,
                        $logger
                );
 
index 8e5e4ecad7cb88e0c533d8d4a72572aaffcf3d4b..b985d0b08c68b7e42168a93839f60354f0250f0e 100644 (file)
 namespace OCA\DAV\Tests\unit\Comments;
 
 use OC\EventDispatcher\EventDispatcher;
-use OC\EventDispatcher\SymfonyAdapter;
 use OCA\DAV\Comments\EntityTypeCollection as EntityTypeCollectionImplementation;
 use OCP\Comments\CommentsEntityEvent;
 use OCP\Comments\ICommentsManager;
+use OCP\EventDispatcher\IEventDispatcher;
 use OCP\IUser;
 use OCP\IUserManager;
 use OCP\IUserSession;
 use Psr\Log\LoggerInterface;
-use Symfony\Component\EventDispatcher\EventDispatcherInterface;
 
 class RootCollectionTest extends \Test\TestCase {
 
@@ -48,7 +47,7 @@ class RootCollectionTest extends \Test\TestCase {
        protected $collection;
        /** @var \OCP\IUserSession|\PHPUnit\Framework\MockObject\MockObject */
        protected $userSession;
-       /** @var EventDispatcherInterface */
+       /** @var IEventDispatcher */
        protected $dispatcher;
        /** @var \OCP\IUser|\PHPUnit\Framework\MockObject\MockObject */
        protected $user;
@@ -72,12 +71,9 @@ class RootCollectionTest extends \Test\TestCase {
                $this->logger = $this->getMockBuilder(LoggerInterface::class)
                        ->disableOriginalConstructor()
                        ->getMock();
-               $this->dispatcher = new SymfonyAdapter(
-                       new EventDispatcher(
-                               new \Symfony\Component\EventDispatcher\EventDispatcher(),
-                               \OC::$server,
-                               $this->logger
-                       ),
+               $this->dispatcher = new EventDispatcher(
+                       new \Symfony\Component\EventDispatcher\EventDispatcher(),
+                       \OC::$server,
                        $this->logger
                );
 
@@ -99,7 +95,7 @@ class RootCollectionTest extends \Test\TestCase {
                        ->method('getUser')
                        ->willReturn($this->user);
 
-               $this->dispatcher->addListener(CommentsEntityEvent::EVENT_ENTITY, function (CommentsEntityEvent $event): void {
+               $this->dispatcher->addListener(CommentsEntityEvent::class, function (CommentsEntityEvent $event): void {
                        $event->addEntityCollection('files', function () {
                                return true;
                        });
index e4b4c78f03c07a919514d3c4b12d96841cfed199..3336b80d6b5964311b2bbdc1b6ec2e0cd98a31c9 100644 (file)
@@ -29,26 +29,24 @@ use OCP\EventDispatcher\Event;
  * Class CommentsEntityEvent
  *
  * @since 9.1.0
+ * @since 28.0.0 Dispatched as a typed event
  */
 class CommentsEntityEvent extends Event {
        /**
-        * @deprecated 22.0.0
+        * @deprecated 22.0.0 - Listen to the typed event instead.
         */
        public const EVENT_ENTITY = 'OCP\Comments\ICommentsManager::registerEntity';
 
-       /** @var string */
-       protected $event;
        /** @var \Closure[] */
        protected $collections;
 
        /**
         * DispatcherEvent constructor.
         *
-        * @param string $event
         * @since 9.1.0
         */
-       public function __construct($event) {
-               $this->event = $event;
+       public function __construct() {
+               parent::__construct();
                $this->collections = [];
        }