Skip to content

Commit ff07c99

Browse files
authored
Merge pull request #60137 from nextcloud/carl/commnent-event
fix: Dispatch old comment events
2 parents fb67d5d + e6a3b68 commit ff07c99

9 files changed

Lines changed: 52 additions & 6 deletions

File tree

apps/comments/lib/Listener/CommentsEventListener.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,20 @@
1313
use OCA\Comments\Activity\Listener as ActivityListener;
1414
use OCA\Comments\Notification\Listener as NotificationListener;
1515
use OCP\Comments\CommentsEvent;
16+
use OCP\Comments\Events\BeforeCommentUpdatedEvent;
17+
use OCP\Comments\Events\CommentAddedEvent;
18+
use OCP\Comments\Events\CommentDeletedEvent;
19+
use OCP\Comments\Events\CommentUpdatedEvent;
1620
use OCP\EventDispatcher\Event;
21+
use OCP\EventDispatcher\IEventDispatcher;
1722
use OCP\EventDispatcher\IEventListener;
1823

1924
/** @template-implements IEventListener<CommentsEvent|Event> */
2025
class CommentsEventListener implements IEventListener {
2126
public function __construct(
2227
private ActivityListener $activityListener,
2328
private NotificationListener $notificationListener,
29+
private IEventDispatcher $eventDispatcher,
2430
) {
2531
}
2632

@@ -30,6 +36,14 @@ public function handle(Event $event): void {
3036
return;
3137
}
3238

39+
if ($event instanceof CommentAddedEvent
40+
|| $event instanceof CommentUpdatedEvent
41+
|| $event instanceof CommentDeletedEvent
42+
|| $event instanceof BeforeCommentUpdatedEvent) {
43+
// Dispatch the deprecated event name for backward compatibility
44+
$this->eventDispatcher->dispatchTyped(new CommentsEvent($event->getEvent(), $event->getComment()));
45+
}
46+
3347
if ($event->getComment()->getObjectType() !== 'files') {
3448
// this is a 'files'-specific Handler
3549
return;

apps/comments/tests/Unit/Activity/ListenerTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ class ListenerTest extends TestCase {
3535
protected IShareHelper&MockObject $shareHelper;
3636
protected Listener $listener;
3737

38+
#[\Override]
3839
protected function setUp(): void {
3940
parent::setUp();
4041

apps/comments/tests/Unit/AppInfo/ApplicationTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,14 @@
2828
*/
2929
#[\PHPUnit\Framework\Attributes\Group(name: 'DB')]
3030
class ApplicationTest extends TestCase {
31+
#[\Override]
3132
protected function setUp(): void {
3233
parent::setUp();
3334
Server::get(IUserManager::class)->createUser('dummy', '456');
3435
Server::get(IUserSession::class)->setUser(Server::get(IUserManager::class)->get('dummy'));
3536
}
3637

38+
#[\Override]
3739
protected function tearDown(): void {
3840
Server::get(IUserManager::class)->get('dummy')->delete();
3941
parent::tearDown();

apps/comments/tests/Unit/Collaboration/CommentersSorterTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ class CommentersSorterTest extends TestCase {
1616
protected ICommentsManager&MockObject $commentsManager;
1717
protected CommentersSorter $sorter;
1818

19+
#[\Override]
1920
protected function setUp(): void {
2021
parent::setUp();
2122

apps/comments/tests/Unit/Controller/NotificationsTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ class NotificationsTest extends TestCase {
3535
protected IURLGenerator&MockObject $urlGenerator;
3636
protected NotificationsController $notificationsController;
3737

38+
#[\Override]
3839
protected function setUp(): void {
3940
parent::setUp();
4041

apps/comments/tests/Unit/EventHandlerTest.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
use OCP\Comments\Events\CommentDeletedEvent;
1818
use OCP\Comments\Events\CommentUpdatedEvent;
1919
use OCP\Comments\IComment;
20+
use OCP\EventDispatcher\IEventDispatcher;
21+
use PHPUnit\Framework\Attributes\DataProvider;
2022
use PHPUnit\Framework\MockObject\MockObject;
2123
use Test\TestCase;
2224

@@ -25,23 +27,22 @@ class EventHandlerTest extends TestCase {
2527
protected NotificationListener&MockObject $notificationListener;
2628
protected CommentsEventListener $eventHandler;
2729

30+
#[\Override]
2831
protected function setUp(): void {
2932
parent::setUp();
3033

3134
$this->activityListener = $this->createMock(ActivityListener::class);
3235
$this->notificationListener = $this->createMock(NotificationListener::class);
3336

34-
$this->eventHandler = new CommentsEventListener($this->activityListener, $this->notificationListener);
37+
$this->eventHandler = new CommentsEventListener($this->activityListener, $this->notificationListener, $this->createMock(IEventDispatcher::class));
3538
}
3639

3740
public function testNotFiles(): void {
38-
/** @var IComment|MockObject $comment */
3941
$comment = $this->createMock(IComment::class);
4042
$comment->expects($this->once())
4143
->method('getObjectType')
4244
->willReturn('smiles');
4345

44-
/** @var CommentsEvent|MockObject $event */
4546
$event = $this->createMock(CommentsEvent::class);
4647
$event->expects($this->once())
4748
->method('getComment')
@@ -61,9 +62,8 @@ public static function handledProvider(): array {
6162
];
6263
}
6364

64-
#[\PHPUnit\Framework\Attributes\DataProvider(methodName: 'handledProvider')]
65+
#[DataProvider(methodName: 'handledProvider')]
6566
public function testHandled(string $eventType): void {
66-
/** @var IComment|MockObject $comment */
6767
$comment = $this->createMock(IComment::class);
6868
$comment->expects($this->once())
6969
->method('getObjectType')

apps/comments/tests/Unit/Notification/ListenerTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ class ListenerTest extends TestCase {
2626
protected IURLGenerator&MockObject $urlGenerator;
2727
protected Listener $listener;
2828

29+
#[\Override]
2930
protected function setUp(): void {
3031
parent::setUp();
3132

apps/comments/tests/Unit/Notification/NotifierTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ class NotifierTest extends TestCase {
3737
protected Notifier $notifier;
3838
protected string $lc = 'tlh_KX';
3939

40+
#[\Override]
4041
protected function setUp(): void {
4142
parent::setUp();
4243

psalm.xml

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,32 @@
6969
<file name="tests/lib/TestCase.php"/>
7070
<file name="tests/lib/Files/Template/*.php"/>
7171
<ignoreFiles>
72-
<directory name="apps/**/tests"/>
72+
<directory name="apps/admin_audit/tests"/>
73+
<directory name="apps/cloud_federation_api/tests"/>
74+
<directory name="apps/contactsinteraction/tests"/>
75+
<directory name="apps/dashboard/tests"/>
76+
<directory name="apps/dav/tests"/>
77+
<directory name="apps/encryption/tests"/>
78+
<directory name="apps/federatedfilesharing/tests"/>
79+
<directory name="apps/federation/tests"/>
80+
<directory name="apps/files/tests"/>
81+
<directory name="apps/files_external/tests"/>
82+
<directory name="apps/files_sharing/tests"/>
83+
<directory name="apps/files_trashbin/tests"/>
84+
<directory name="apps/files_versions/tests"/>
85+
<directory name="apps/oauth2/tests"/>
86+
<directory name="apps/profile/tests"/>
87+
<directory name="apps/provisioning_api/tests"/>
88+
<directory name="apps/settings/tests"/>
89+
<directory name="apps/sharebymail/tests"/>
90+
<directory name="apps/systemtags/tests"/>
91+
<directory name="apps/theming/tests"/>
92+
<directory name="apps/twofactor_backupcodes/tests"/>
93+
<directory name="apps/updatenotification/tests"/>
94+
<directory name="apps/user_ldap/tests"/>
95+
<directory name="apps/user_status/tests"/>
96+
<directory name="apps/webhook_listeners/tests"/>
97+
<directory name="apps/workflowengine/tests"/>
7398
<directory name="apps/**/composer"/>
7499
<directory name="lib/composer"/>
75100
<directory name="lib/l10n"/>

0 commit comments

Comments
 (0)