aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArthur Schiwon <blizzz@arthur-schiwon.de>2024-06-27 12:40:06 +0200
committerGitHub <noreply@github.com>2024-06-27 12:40:06 +0200
commitff499a6baa49916898f01d1cb8573883a87dca3f (patch)
tree1ea884c74bfa7c1c0c55528594e2c377877e1873
parent2482688fa09d7dc477ad0d23049d55b62d5b3d6c (diff)
parent9713dd3fa990c5dabfa07b1049ac1a8a0f1edb27 (diff)
downloadnextcloud-server-ff499a6baa49916898f01d1cb8573883a87dca3f.tar.gz
nextcloud-server-ff499a6baa49916898f01d1cb8573883a87dca3f.zip
Merge pull request #45951 from nextcloud/chore/comments-event-legacy
chore: Move comments event handler to use proper event dispatcher
-rw-r--r--apps/comments/composer/composer/autoload_classmap.php2
-rw-r--r--apps/comments/composer/composer/autoload_static.php2
-rw-r--r--apps/comments/lib/AppInfo/Application.php19
-rw-r--r--apps/comments/lib/Listener/CommentsEventListener.php (renamed from apps/comments/lib/EventHandler.php)24
-rw-r--r--apps/comments/tests/Unit/EventHandlerTest.php6
-rw-r--r--lib/private/Comments/Manager.php3
-rw-r--r--lib/public/Comments/ICommentsEventHandler.php2
-rw-r--r--tests/lib/Comments/ManagerTest.php4
8 files changed, 36 insertions, 26 deletions
diff --git a/apps/comments/composer/composer/autoload_classmap.php b/apps/comments/composer/composer/autoload_classmap.php
index 61def2ecc46..22f95a934d7 100644
--- a/apps/comments/composer/composer/autoload_classmap.php
+++ b/apps/comments/composer/composer/autoload_classmap.php
@@ -15,8 +15,8 @@ return array(
'OCA\\Comments\\Capabilities' => $baseDir . '/../lib/Capabilities.php',
'OCA\\Comments\\Collaboration\\CommentersSorter' => $baseDir . '/../lib/Collaboration/CommentersSorter.php',
'OCA\\Comments\\Controller\\NotificationsController' => $baseDir . '/../lib/Controller/NotificationsController.php',
- 'OCA\\Comments\\EventHandler' => $baseDir . '/../lib/EventHandler.php',
'OCA\\Comments\\Listener\\CommentsEntityEventListener' => $baseDir . '/../lib/Listener/CommentsEntityEventListener.php',
+ 'OCA\\Comments\\Listener\\CommentsEventListener' => $baseDir . '/../lib/Listener/CommentsEventListener.php',
'OCA\\Comments\\Listener\\LoadAdditionalScripts' => $baseDir . '/../lib/Listener/LoadAdditionalScripts.php',
'OCA\\Comments\\Listener\\LoadSidebarScripts' => $baseDir . '/../lib/Listener/LoadSidebarScripts.php',
'OCA\\Comments\\MaxAutoCompleteResultsInitialState' => $baseDir . '/../lib/MaxAutoCompleteResultsInitialState.php',
diff --git a/apps/comments/composer/composer/autoload_static.php b/apps/comments/composer/composer/autoload_static.php
index 091dfce5931..7e553f8e2e2 100644
--- a/apps/comments/composer/composer/autoload_static.php
+++ b/apps/comments/composer/composer/autoload_static.php
@@ -30,8 +30,8 @@ class ComposerStaticInitComments
'OCA\\Comments\\Capabilities' => __DIR__ . '/..' . '/../lib/Capabilities.php',
'OCA\\Comments\\Collaboration\\CommentersSorter' => __DIR__ . '/..' . '/../lib/Collaboration/CommentersSorter.php',
'OCA\\Comments\\Controller\\NotificationsController' => __DIR__ . '/..' . '/../lib/Controller/NotificationsController.php',
- 'OCA\\Comments\\EventHandler' => __DIR__ . '/..' . '/../lib/EventHandler.php',
'OCA\\Comments\\Listener\\CommentsEntityEventListener' => __DIR__ . '/..' . '/../lib/Listener/CommentsEntityEventListener.php',
+ 'OCA\\Comments\\Listener\\CommentsEventListener' => __DIR__ . '/..' . '/../lib/Listener/CommentsEventListener.php',
'OCA\\Comments\\Listener\\LoadAdditionalScripts' => __DIR__ . '/..' . '/../lib/Listener/LoadAdditionalScripts.php',
'OCA\\Comments\\Listener\\LoadSidebarScripts' => __DIR__ . '/..' . '/../lib/Listener/LoadSidebarScripts.php',
'OCA\\Comments\\MaxAutoCompleteResultsInitialState' => __DIR__ . '/..' . '/../lib/MaxAutoCompleteResultsInitialState.php',
diff --git a/apps/comments/lib/AppInfo/Application.php b/apps/comments/lib/AppInfo/Application.php
index 8951387b362..15b576938d2 100644
--- a/apps/comments/lib/AppInfo/Application.php
+++ b/apps/comments/lib/AppInfo/Application.php
@@ -5,10 +5,9 @@
*/
namespace OCA\Comments\AppInfo;
-use Closure;
use OCA\Comments\Capabilities;
-use OCA\Comments\EventHandler;
use OCA\Comments\Listener\CommentsEntityEventListener;
+use OCA\Comments\Listener\CommentsEventListener;
use OCA\Comments\Listener\LoadAdditionalScripts;
use OCA\Comments\Listener\LoadSidebarScripts;
use OCA\Comments\MaxAutoCompleteResultsInitialState;
@@ -22,9 +21,8 @@ use OCP\AppFramework\Bootstrap\IBootContext;
use OCP\AppFramework\Bootstrap\IBootstrap;
use OCP\AppFramework\Bootstrap\IRegistrationContext;
use OCP\Comments\CommentsEntityEvent;
-use OCP\Comments\ICommentsManager;
+use OCP\Comments\CommentsEvent;
use OCP\ISearch;
-use OCP\IServerContainer;
class Application extends App implements IBootstrap {
public const APP_ID = 'comments';
@@ -48,6 +46,11 @@ class Application extends App implements IBootstrap {
CommentsEntityEvent::class,
CommentsEntityEventListener::class
);
+ $context->registerEventListener(
+ CommentsEvent::class,
+ CommentsEventListener::class,
+ );
+
$context->registerSearchProvider(CommentsSearchProvider::class);
$context->registerInitialStateProvider(MaxAutoCompleteResultsInitialState::class);
@@ -56,14 +59,6 @@ class Application extends App implements IBootstrap {
}
public function boot(IBootContext $context): void {
- $context->injectFn(Closure::fromCallable([$this, 'registerCommentsEventHandler']));
-
$context->getServerContainer()->get(ISearch::class)->registerProvider(LegacyProvider::class, ['apps' => ['files']]);
}
-
- protected function registerCommentsEventHandler(IServerContainer $container): void {
- $container->get(ICommentsManager::class)->registerEventHandler(function (): EventHandler {
- return $this->getContainer()->get(EventHandler::class);
- });
- }
}
diff --git a/apps/comments/lib/EventHandler.php b/apps/comments/lib/Listener/CommentsEventListener.php
index 3ad76941444..a1e44995162 100644
--- a/apps/comments/lib/EventHandler.php
+++ b/apps/comments/lib/Listener/CommentsEventListener.php
@@ -1,28 +1,34 @@
<?php
+
+declare(strict_types=1);
+
/**
* SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
-namespace OCA\Comments;
+
+
+namespace OCA\Comments\Listener;
use OCA\Comments\Activity\Listener as ActivityListener;
use OCA\Comments\Notification\Listener as NotificationListener;
use OCP\Comments\CommentsEvent;
-use OCP\Comments\ICommentsEventHandler;
+use OCP\EventDispatcher\Event;
+use OCP\EventDispatcher\IEventListener;
-/**
- * Class EventHandler
- *
- * @package OCA\Comments
- */
-class EventHandler implements ICommentsEventHandler {
+/** @template-implements IEventListener<CommentsEvent|Event> */
+class CommentsEventListener implements IEventListener {
public function __construct(
private ActivityListener $activityListener,
private NotificationListener $notificationListener,
) {
}
- public function handle(CommentsEvent $event): void {
+ public function handle(Event $event): void {
+ if (!$event instanceof CommentsEvent) {
+ return;
+ }
+
if ($event->getComment()->getObjectType() !== 'files') {
// this is a 'files'-specific Handler
return;
diff --git a/apps/comments/tests/Unit/EventHandlerTest.php b/apps/comments/tests/Unit/EventHandlerTest.php
index 6c3277a60b2..fc7890440f3 100644
--- a/apps/comments/tests/Unit/EventHandlerTest.php
+++ b/apps/comments/tests/Unit/EventHandlerTest.php
@@ -6,14 +6,14 @@
namespace OCA\Comments\Tests\Unit\Notification;
use OCA\Comments\Activity\Listener as ActivityListener;
-use OCA\Comments\EventHandler;
+use OCA\Comments\Listener\CommentsEventListener;
use OCA\Comments\Notification\Listener as NotificationListener;
use OCP\Comments\CommentsEvent;
use OCP\Comments\IComment;
use Test\TestCase;
class EventHandlerTest extends TestCase {
- /** @var EventHandler */
+ /** @var CommentsEventListener */
protected $eventHandler;
/** @var ActivityListener|\PHPUnit\Framework\MockObject\MockObject */
@@ -33,7 +33,7 @@ class EventHandlerTest extends TestCase {
->disableOriginalConstructor()
->getMock();
- $this->eventHandler = new EventHandler($this->activityListener, $this->notificationListener);
+ $this->eventHandler = new CommentsEventListener($this->activityListener, $this->notificationListener);
}
public function testNotFiles() {
diff --git a/lib/private/Comments/Manager.php b/lib/private/Comments/Manager.php
index e3d40f2d965..21ff5322f23 100644
--- a/lib/private/Comments/Manager.php
+++ b/lib/private/Comments/Manager.php
@@ -16,6 +16,7 @@ use OCP\Comments\ICommentsEventHandler;
use OCP\Comments\ICommentsManager;
use OCP\Comments\NotFoundException;
use OCP\DB\QueryBuilder\IQueryBuilder;
+use OCP\EventDispatcher\IEventDispatcher;
use OCP\Files\FileInfo;
use OCP\Files\Folder;
use OCP\Files\IRootFolder;
@@ -49,6 +50,7 @@ class Manager implements ICommentsManager {
protected IEmojiHelper $emojiHelper,
protected IInitialStateService $initialStateService,
protected IRootFolder $rootFolder,
+ protected IEventDispatcher $eventDispatcher,
) {
}
@@ -1529,6 +1531,7 @@ class Manager implements ICommentsManager {
foreach ($entities as $entity) {
$entity->handle($event);
}
+ $this->eventDispatcher->dispatchTyped($event);
}
/**
diff --git a/lib/public/Comments/ICommentsEventHandler.php b/lib/public/Comments/ICommentsEventHandler.php
index af36e051b5f..dc0a554ff11 100644
--- a/lib/public/Comments/ICommentsEventHandler.php
+++ b/lib/public/Comments/ICommentsEventHandler.php
@@ -9,11 +9,13 @@ namespace OCP\Comments;
* Interface ICommentsEventHandler
*
* @since 11.0.0
+ * @deprecated 30.0.0 Register a listener for the CommentsEvent through the IEventDispatcher
*/
interface ICommentsEventHandler {
/**
* @param CommentsEvent $event
* @since 11.0.0
+ * @deprecated 30.0.0 Register a listener for the CommentsEvent through the IEventDispatcher
*/
public function handle(CommentsEvent $event);
}
diff --git a/tests/lib/Comments/ManagerTest.php b/tests/lib/Comments/ManagerTest.php
index 88ce2f1438f..359be2696c6 100644
--- a/tests/lib/Comments/ManagerTest.php
+++ b/tests/lib/Comments/ManagerTest.php
@@ -14,6 +14,7 @@ use OCP\Comments\IComment;
use OCP\Comments\ICommentsEventHandler;
use OCP\Comments\ICommentsManager;
use OCP\Comments\NotFoundException;
+use OCP\EventDispatcher\IEventDispatcher;
use OCP\Files\Folder;
use OCP\Files\IRootFolder;
use OCP\IConfig;
@@ -91,6 +92,7 @@ class ManagerTest extends TestCase {
new EmojiHelper($this->connection),
$this->createMock(IInitialStateService::class),
$this->rootFolder,
+ $this->createMock(IEventDispatcher::class),
);
}
@@ -758,6 +760,7 @@ class ManagerTest extends TestCase {
new EmojiHelper($this->connection),
$this->createMock(IInitialStateService::class),
$this->rootFolder,
+ $this->createMock(IEventDispatcher::class)
);
// just to make sure they are really set, with correct actor data
@@ -804,6 +807,7 @@ class ManagerTest extends TestCase {
new EmojiHelper($this->connection),
$this->createMock(IInitialStateService::class),
$this->rootFolder,
+ $this->createMock(IEventDispatcher::class)
);
$deleted = $manager->deleteCommentsExpiredAtObject('files');