Skip to content

Commit 1c5fc03

Browse files
committed
Move every event to listeners and remove all uses of legacy dispatcher
Signed-off-by: Thomas Citharel <tcit@tcit.fr>
1 parent 2764e17 commit 1c5fc03

File tree

10 files changed

+218
-75
lines changed

10 files changed

+218
-75
lines changed

apps/dav/composer/composer/autoload_classmap.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,9 @@
235235
'OCA\\DAV\\Listener\\CalendarContactInteractionListener' => $baseDir . '/../lib/Listener/CalendarContactInteractionListener.php',
236236
'OCA\\DAV\\Listener\\CalendarDeletionDefaultUpdaterListener' => $baseDir . '/../lib/Listener/CalendarDeletionDefaultUpdaterListener.php',
237237
'OCA\\DAV\\Listener\\CalendarObjectReminderUpdaterListener' => $baseDir . '/../lib/Listener/CalendarObjectReminderUpdaterListener.php',
238+
'OCA\\DAV\\Listener\\CalendarPublicationListener' => $baseDir . '/../lib/Listener/CalendarPublicationListener.php',
239+
'OCA\\DAV\\Listener\\CalendarShareUpdateListener' => $baseDir . '/../lib/Listener/CalendarShareUpdateListener.php',
240+
'OCA\\DAV\\Listener\\CalendarUnpublicationListener' => $baseDir . '/../lib/Listener/CalendarUnpublicationListener.php',
238241
'OCA\\DAV\\Listener\\CardListener' => $baseDir . '/../lib/Listener/CardListener.php',
239242
'OCA\\DAV\\Listener\\SubscriptionCreationListener' => $baseDir . '/../lib/Listener/SubscriptionCreationListener.php',
240243
'OCA\\DAV\\Listener\\SubscriptionDeletionListener' => $baseDir . '/../lib/Listener/SubscriptionDeletionListener.php',

apps/dav/composer/composer/autoload_static.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,9 @@ class ComposerStaticInitDAV
250250
'OCA\\DAV\\Listener\\CalendarContactInteractionListener' => __DIR__ . '/..' . '/../lib/Listener/CalendarContactInteractionListener.php',
251251
'OCA\\DAV\\Listener\\CalendarDeletionDefaultUpdaterListener' => __DIR__ . '/..' . '/../lib/Listener/CalendarDeletionDefaultUpdaterListener.php',
252252
'OCA\\DAV\\Listener\\CalendarObjectReminderUpdaterListener' => __DIR__ . '/..' . '/../lib/Listener/CalendarObjectReminderUpdaterListener.php',
253+
'OCA\\DAV\\Listener\\CalendarPublicationListener' => __DIR__ . '/..' . '/../lib/Listener/CalendarPublicationListener.php',
254+
'OCA\\DAV\\Listener\\CalendarShareUpdateListener' => __DIR__ . '/..' . '/../lib/Listener/CalendarShareUpdateListener.php',
255+
'OCA\\DAV\\Listener\\CalendarUnpublicationListener' => __DIR__ . '/..' . '/../lib/Listener/CalendarUnpublicationListener.php',
253256
'OCA\\DAV\\Listener\\CardListener' => __DIR__ . '/..' . '/../lib/Listener/CardListener.php',
254257
'OCA\\DAV\\Listener\\SubscriptionCreationListener' => __DIR__ . '/..' . '/../lib/Listener/SubscriptionCreationListener.php',
255258
'OCA\\DAV\\Listener\\SubscriptionDeletionListener' => __DIR__ . '/..' . '/../lib/Listener/SubscriptionDeletionListener.php',

apps/dav/lib/AppInfo/Application.php

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,10 @@
6161
use OCA\DAV\Events\CalendarObjectMovedToTrashEvent;
6262
use OCA\DAV\Events\CalendarObjectRestoredEvent;
6363
use OCA\DAV\Events\CalendarObjectUpdatedEvent;
64+
use OCA\DAV\Events\CalendarPublishedEvent;
6465
use OCA\DAV\Events\CalendarRestoredEvent;
6566
use OCA\DAV\Events\CalendarShareUpdatedEvent;
67+
use OCA\DAV\Events\CalendarUnpublishedEvent;
6668
use OCA\DAV\Events\CalendarUpdatedEvent;
6769
use OCA\DAV\Events\CardCreatedEvent;
6870
use OCA\DAV\Events\CardDeletedEvent;
@@ -75,6 +77,9 @@
7577
use OCA\DAV\Listener\CalendarContactInteractionListener;
7678
use OCA\DAV\Listener\CalendarDeletionDefaultUpdaterListener;
7779
use OCA\DAV\Listener\CalendarObjectReminderUpdaterListener;
80+
use OCA\DAV\Listener\CalendarPublicationListener;
81+
use OCA\DAV\Listener\CalendarShareUpdateListener;
82+
use OCA\DAV\Listener\CalendarUnpublicationListener;
7883
use OCA\DAV\Listener\CardListener;
7984
use OCA\DAV\Listener\SubscriptionCreationListener;
8085
use OCA\DAV\Listener\SubscriptionDeletionListener;
@@ -153,6 +158,9 @@ public function register(IRegistrationContext $context): void {
153158
$context->registerEventListener(CalendarObjectRestoredEvent::class, ActivityUpdaterListener::class);
154159
$context->registerEventListener(CalendarObjectRestoredEvent::class, CalendarObjectReminderUpdaterListener::class);
155160
$context->registerEventListener(CalendarShareUpdatedEvent::class, CalendarContactInteractionListener::class);
161+
$context->registerEventListener(CalendarPublishedEvent::class, CalendarPublicationListener::class);
162+
$context->registerEventListener(CalendarUnpublishedEvent::class, CalendarUnpublicationListener::class);
163+
$context->registerEventListener(CalendarShareUpdatedEvent::class, CalendarShareUpdateListener::class);
156164

157165
$context->registerEventListener(SubscriptionCreatedEvent::class, SubscriptionCreationListener::class);
158166
$context->registerEventListener(SubscriptionDeletedEvent::class, SubscriptionDeletionListener::class);
@@ -253,16 +261,6 @@ public function registerHooks(HookManager $hm,
253261
// Here we should recalculate if reminders should be sent to new or old sharees
254262
});
255263

256-
$dispatcher->addListener('\OCA\DAV\CalDAV\CalDavBackend::publishCalendar', function (GenericEvent $event) use ($container) {
257-
/** @var Backend $backend */
258-
$backend = $container->query(Backend::class);
259-
$backend->onCalendarPublication(
260-
$event->getArgument('calendarData'),
261-
$event->getArgument('public')
262-
);
263-
});
264-
265-
266264
$dispatcher->addListener('OCP\Federation\TrustedServerEvent::remove',
267265
function (GenericEvent $event) {
268266
/** @var CardDavBackend $cardDavBackend */

apps/dav/lib/CalDAV/Activity/Backend.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ public function onCalendarDelete(array $calendarData, array $shares): void {
119119
* @param array $calendarData
120120
* @param bool $publishStatus
121121
*/
122-
public function onCalendarPublication(array $calendarData, $publishStatus) {
122+
public function onCalendarPublication(array $calendarData, bool $publishStatus): void {
123123
$this->triggerCalendarActivity($publishStatus ? Calendar::SUBJECT_PUBLISH : Calendar::SUBJECT_UNPUBLISH, $calendarData);
124124
}
125125

apps/dav/lib/CalDAV/CalDavBackend.php

Lines changed: 0 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,6 @@
9595
use Sabre\VObject\Reader;
9696
use Sabre\VObject\Recur\EventIterator;
9797
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
98-
use Symfony\Component\EventDispatcher\GenericEvent;
9998
use function array_merge;
10099
use function array_values;
101100
use function explode;
@@ -246,7 +245,6 @@ class CalDavBackend extends AbstractBackend implements SyncSupport, Subscription
246245
* @param ISecureRandom $random
247246
* @param ILogger $logger
248247
* @param IEventDispatcher $dispatcher
249-
* @param EventDispatcherInterface $legacyDispatcher
250248
* @param bool $legacyEndpoint
251249
*/
252250
public function __construct(IDBConnection $db,
@@ -256,7 +254,6 @@ public function __construct(IDBConnection $db,
256254
ISecureRandom $random,
257255
ILogger $logger,
258256
IEventDispatcher $dispatcher,
259-
EventDispatcherInterface $legacyDispatcher,
260257
IConfig $config,
261258
bool $legacyEndpoint = false) {
262259
$this->db = $db;
@@ -266,7 +263,6 @@ public function __construct(IDBConnection $db,
266263
$this->random = $random;
267264
$this->logger = $logger;
268265
$this->dispatcher = $dispatcher;
269-
$this->legacyDispatcher = $legacyDispatcher;
270266
$this->config = $config;
271267
$this->legacyEndpoint = $legacyEndpoint;
272268
}
@@ -1335,15 +1331,6 @@ public function createCalendarObject($calendarId, $objectUri, $calendarData, $ca
13351331
$subscriptionRow = $this->getSubscriptionById($calendarId);
13361332

13371333
$this->dispatcher->dispatchTyped(new CachedCalendarObjectCreatedEvent((int)$calendarId, $subscriptionRow, [], $objectRow));
1338-
$this->legacyDispatcher->dispatch('\OCA\DAV\CalDAV\CalDavBackend::createCachedCalendarObject', new GenericEvent(
1339-
'\OCA\DAV\CalDAV\CalDavBackend::createCachedCalendarObject',
1340-
[
1341-
'subscriptionId' => $calendarId,
1342-
'calendarData' => $subscriptionRow,
1343-
'shares' => [],
1344-
'objectData' => $objectRow,
1345-
]
1346-
));
13471334
}
13481335

13491336
return '"' . $extraData['etag'] . '"';
@@ -1400,15 +1387,6 @@ public function updateCalendarObject($calendarId, $objectUri, $calendarData, $ca
14001387
$subscriptionRow = $this->getSubscriptionById($calendarId);
14011388

14021389
$this->dispatcher->dispatchTyped(new CachedCalendarObjectUpdatedEvent((int)$calendarId, $subscriptionRow, [], $objectRow));
1403-
$this->legacyDispatcher->dispatch('\OCA\DAV\CalDAV\CalDavBackend::updateCachedCalendarObject', new GenericEvent(
1404-
'\OCA\DAV\CalDAV\CalDavBackend::updateCachedCalendarObject',
1405-
[
1406-
'subscriptionId' => $calendarId,
1407-
'calendarData' => $subscriptionRow,
1408-
'shares' => [],
1409-
'objectData' => $objectRow,
1410-
]
1411-
));
14121390
}
14131391
}
14141392

@@ -1466,15 +1444,6 @@ public function deleteCalendarObject($calendarId, $objectUri, $calendarType = se
14661444
$subscriptionRow = $this->getSubscriptionById($calendarId);
14671445

14681446
$this->dispatcher->dispatchTyped(new CachedCalendarObjectDeletedEvent((int)$calendarId, $subscriptionRow, [], $data));
1469-
$this->legacyDispatcher->dispatch('\OCA\DAV\CalDAV\CalDavBackend::deleteCachedCalendarObject', new GenericEvent(
1470-
'\OCA\DAV\CalDAV\CalDavBackend::deleteCachedCalendarObject',
1471-
[
1472-
'subscriptionId' => $calendarId,
1473-
'calendarData' => $subscriptionRow,
1474-
'shares' => [],
1475-
'objectData' => $data,
1476-
]
1477-
));
14781447
}
14791448
} else {
14801449
$pathInfo = pathinfo($data['uri']);
@@ -2538,13 +2507,6 @@ public function updateSubscription($subscriptionId, PropPatch $propPatch) {
25382507

25392508
$subscriptionRow = $this->getSubscriptionById($subscriptionId);
25402509
$this->dispatcher->dispatchTyped(new SubscriptionUpdatedEvent((int)$subscriptionId, $subscriptionRow, [], $mutations));
2541-
$this->legacyDispatcher->dispatch('\OCA\DAV\CalDAV\CalDavBackend::updateSubscription', new GenericEvent(
2542-
'\OCA\DAV\CalDAV\CalDavBackend::updateSubscription',
2543-
[
2544-
'subscriptionId' => $subscriptionId,
2545-
'subscriptionData' => $subscriptionRow,
2546-
'propertyMutations' => $mutations,
2547-
]));
25482510

25492511
return true;
25502512
});
@@ -2856,15 +2818,6 @@ public function updateShares($shareable, $add, $remove) {
28562818
$calendarRow = $this->getCalendarById($calendarId);
28572819
$oldShares = $this->getShares($calendarId);
28582820

2859-
$this->legacyDispatcher->dispatch('\OCA\DAV\CalDAV\CalDavBackend::updateShares', new GenericEvent(
2860-
'\OCA\DAV\CalDAV\CalDavBackend::updateShares',
2861-
[
2862-
'calendarId' => $calendarId,
2863-
'calendarData' => $calendarRow,
2864-
'shares' => $oldShares,
2865-
'add' => $add,
2866-
'remove' => $remove,
2867-
]));
28682821
$this->calendarSharingBackend->updateShares($shareable, $add, $remove);
28692822

28702823
$this->dispatcher->dispatchTyped(new CalendarShareUpdatedEvent((int)$calendarId, $calendarRow, $oldShares, $add, $remove));
@@ -2886,13 +2839,6 @@ public function getShares($resourceId) {
28862839
public function setPublishStatus($value, $calendar) {
28872840
$calendarId = $calendar->getResourceId();
28882841
$calendarData = $this->getCalendarById($calendarId);
2889-
$this->legacyDispatcher->dispatch('\OCA\DAV\CalDAV\CalDavBackend::publishCalendar', new GenericEvent(
2890-
'\OCA\DAV\CalDAV\CalDavBackend::updateShares',
2891-
[
2892-
'calendarId' => $calendarId,
2893-
'calendarData' => $calendarData,
2894-
'public' => $value,
2895-
]));
28962842

28972843
$query = $this->db->getQueryBuilder();
28982844
if ($value) {
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* @copyright 2021 Thomas Citharel <nextcloud@tcit.fr>
7+
*
8+
* @author Thomas Citharel <nextcloud@tcit.fr>
9+
*
10+
* @license GNU AGPL version 3 or any later version
11+
*
12+
* This program is free software: you can redistribute it and/or modify
13+
* it under the terms of the GNU Affero General Public License as
14+
* published by the Free Software Foundation, either version 3 of the
15+
* License, or (at your option) any later version.
16+
*
17+
* This program is distributed in the hope that it will be useful,
18+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
19+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20+
* GNU Affero General Public License for more details.
21+
*
22+
* You should have received a copy of the GNU Affero General Public License
23+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
24+
*
25+
*/
26+
namespace OCA\DAV\Listener;
27+
28+
use OCA\DAV\CalDAV\Activity\Backend;
29+
use OCA\DAV\Events\CalendarPublishedEvent;
30+
use OCP\EventDispatcher\Event;
31+
use OCP\EventDispatcher\IEventListener;
32+
use Psr\Log\LoggerInterface;
33+
34+
/**
35+
* @template-implements IEventListener<\OCA\DAV\Events\CalendarPublishedEvent>
36+
*/
37+
class CalendarPublicationListener implements IEventListener {
38+
39+
/** @var Backend */
40+
private $activityBackend;
41+
42+
/** @var LoggerInterface */
43+
private $logger;
44+
45+
public function __construct(Backend $activityBackend,
46+
LoggerInterface $logger) {
47+
$this->activityBackend = $activityBackend;
48+
$this->logger = $logger;
49+
}
50+
51+
/**
52+
* In case the user has set their default calendar to the deleted one
53+
*/
54+
public function handle(Event $event): void {
55+
if (!($event instanceof CalendarPublishedEvent)) {
56+
// Not what we subscribed to
57+
return;
58+
}
59+
60+
$this->logger->debug('Creating activity for Calendar being published');
61+
62+
$this->activityBackend->onCalendarPublication(
63+
$event->getCalendarData(),
64+
true
65+
);
66+
}
67+
}
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* @copyright 2021 Thomas Citharel <nextcloud@tcit.fr>
7+
*
8+
* @author Thomas Citharel <nextcloud@tcit.fr>
9+
*
10+
* @license GNU AGPL version 3 or any later version
11+
*
12+
* This program is free software: you can redistribute it and/or modify
13+
* it under the terms of the GNU Affero General Public License as
14+
* published by the Free Software Foundation, either version 3 of the
15+
* License, or (at your option) any later version.
16+
*
17+
* This program is distributed in the hope that it will be useful,
18+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
19+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20+
* GNU Affero General Public License for more details.
21+
*
22+
* You should have received a copy of the GNU Affero General Public License
23+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
24+
*
25+
*/
26+
namespace OCA\DAV\Listener;
27+
28+
use OCA\DAV\CalDAV\Activity\Backend;
29+
use OCA\DAV\Events\CalendarShareUpdatedEvent;
30+
use OCP\EventDispatcher\Event;
31+
use OCP\EventDispatcher\IEventListener;
32+
use Psr\Log\LoggerInterface;
33+
34+
/**
35+
* @template-implements IEventListener<\OCA\DAV\Events\CalendarShareUpdatedEvent>
36+
*/
37+
class CalendarShareUpdateListener implements IEventListener {
38+
39+
/** @var Backend */
40+
private $activityBackend;
41+
42+
/** @var LoggerInterface */
43+
private $logger;
44+
45+
public function __construct(Backend $activityBackend,
46+
LoggerInterface $logger) {
47+
$this->activityBackend = $activityBackend;
48+
$this->logger = $logger;
49+
}
50+
51+
/**
52+
* In case the user has set their default calendar to the deleted one
53+
*/
54+
public function handle(Event $event): void {
55+
if (!($event instanceof CalendarShareUpdatedEvent)) {
56+
// Not what we subscribed to
57+
return;
58+
}
59+
60+
$this->logger->debug("Creating activity for Calendar having it's shares updated");
61+
62+
$this->activityBackend->onCalendarUpdateShares(
63+
$event->getCalendarData(),
64+
$event->getOldShares(),
65+
$event->getAdded(),
66+
$event->getRemoved()
67+
);
68+
}
69+
}

0 commit comments

Comments
 (0)