Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/server.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristoph Wurst <ChristophWurst@users.noreply.github.com>2021-05-07 17:47:44 +0300
committerGitHub <noreply@github.com>2021-05-07 17:47:44 +0300
commitf8c519f5f0b52075c5b343233a5e48f9bc8cf3aa (patch)
tree6e780de6cf25cd57642e2929198f7bb7078a7839
parented2d6eee1e45a54167d628eb31fc12b0d019c0d5 (diff)
parentf5462650f1480bf23a58285e0e4476957a0720db (diff)
Merge pull request #26913 from nextcloud/chore/dav-calendar-object-untyped-events
Drop some more untyped events from the dav code
-rw-r--r--apps/dav/composer/composer/autoload_classmap.php4
-rw-r--r--apps/dav/composer/composer/autoload_static.php4
-rw-r--r--apps/dav/lib/AppInfo/Application.php46
-rw-r--r--apps/dav/lib/BackgroundJob/BuildReminderIndexBackgroundJob.php2
-rw-r--r--apps/dav/lib/CalDAV/CalDavBackend.php27
-rw-r--r--apps/dav/lib/CalDAV/Reminder/ReminderService.php38
-rw-r--r--apps/dav/lib/Listener/ActivityUpdaterListener.php126
-rw-r--r--apps/dav/lib/Listener/CalendarDeletionActivityUpdaterListener.php75
-rw-r--r--apps/dav/lib/Listener/CalendarDeletionReminderUpdaterListener.php74
-rw-r--r--apps/dav/lib/Listener/CalendarObjectReminderUpdaterListener.php122
-rw-r--r--apps/dav/tests/unit/CalDAV/AbstractCalDavBackend.php9
-rw-r--r--apps/dav/tests/unit/CalDAV/CalDavBackendTest.php82
-rw-r--r--apps/dav/tests/unit/CalDAV/Reminder/ReminderServiceTest.php18
13 files changed, 340 insertions, 287 deletions
diff --git a/apps/dav/composer/composer/autoload_classmap.php b/apps/dav/composer/composer/autoload_classmap.php
index fe6c6ab3253..5da3526c820 100644
--- a/apps/dav/composer/composer/autoload_classmap.php
+++ b/apps/dav/composer/composer/autoload_classmap.php
@@ -205,10 +205,10 @@ return array(
'OCA\\DAV\\Files\\Sharing\\FilesDropPlugin' => $baseDir . '/../lib/Files/Sharing/FilesDropPlugin.php',
'OCA\\DAV\\Files\\Sharing\\PublicLinkCheckPlugin' => $baseDir . '/../lib/Files/Sharing/PublicLinkCheckPlugin.php',
'OCA\\DAV\\HookManager' => $baseDir . '/../lib/HookManager.php',
+ 'OCA\\DAV\\Listener\\ActivityUpdaterListener' => $baseDir . '/../lib/Listener/ActivityUpdaterListener.php',
'OCA\\DAV\\Listener\\CalendarContactInteractionListener' => $baseDir . '/../lib/Listener/CalendarContactInteractionListener.php',
- 'OCA\\DAV\\Listener\\CalendarDeletionActivityUpdaterListener' => $baseDir . '/../lib/Listener/CalendarDeletionActivityUpdaterListener.php',
'OCA\\DAV\\Listener\\CalendarDeletionDefaultUpdaterListener' => $baseDir . '/../lib/Listener/CalendarDeletionDefaultUpdaterListener.php',
- 'OCA\\DAV\\Listener\\CalendarDeletionReminderUpdaterListener' => $baseDir . '/../lib/Listener/CalendarDeletionReminderUpdaterListener.php',
+ 'OCA\\DAV\\Listener\\CalendarObjectReminderUpdaterListener' => $baseDir . '/../lib/Listener/CalendarObjectReminderUpdaterListener.php',
'OCA\\DAV\\Migration\\BuildCalendarSearchIndex' => $baseDir . '/../lib/Migration/BuildCalendarSearchIndex.php',
'OCA\\DAV\\Migration\\BuildCalendarSearchIndexBackgroundJob' => $baseDir . '/../lib/Migration/BuildCalendarSearchIndexBackgroundJob.php',
'OCA\\DAV\\Migration\\BuildSocialSearchIndex' => $baseDir . '/../lib/Migration/BuildSocialSearchIndex.php',
diff --git a/apps/dav/composer/composer/autoload_static.php b/apps/dav/composer/composer/autoload_static.php
index 48e453b72f7..60162ba5554 100644
--- a/apps/dav/composer/composer/autoload_static.php
+++ b/apps/dav/composer/composer/autoload_static.php
@@ -220,10 +220,10 @@ class ComposerStaticInitDAV
'OCA\\DAV\\Files\\Sharing\\FilesDropPlugin' => __DIR__ . '/..' . '/../lib/Files/Sharing/FilesDropPlugin.php',
'OCA\\DAV\\Files\\Sharing\\PublicLinkCheckPlugin' => __DIR__ . '/..' . '/../lib/Files/Sharing/PublicLinkCheckPlugin.php',
'OCA\\DAV\\HookManager' => __DIR__ . '/..' . '/../lib/HookManager.php',
+ 'OCA\\DAV\\Listener\\ActivityUpdaterListener' => __DIR__ . '/..' . '/../lib/Listener/ActivityUpdaterListener.php',
'OCA\\DAV\\Listener\\CalendarContactInteractionListener' => __DIR__ . '/..' . '/../lib/Listener/CalendarContactInteractionListener.php',
- 'OCA\\DAV\\Listener\\CalendarDeletionActivityUpdaterListener' => __DIR__ . '/..' . '/../lib/Listener/CalendarDeletionActivityUpdaterListener.php',
'OCA\\DAV\\Listener\\CalendarDeletionDefaultUpdaterListener' => __DIR__ . '/..' . '/../lib/Listener/CalendarDeletionDefaultUpdaterListener.php',
- 'OCA\\DAV\\Listener\\CalendarDeletionReminderUpdaterListener' => __DIR__ . '/..' . '/../lib/Listener/CalendarDeletionReminderUpdaterListener.php',
+ 'OCA\\DAV\\Listener\\CalendarObjectReminderUpdaterListener' => __DIR__ . '/..' . '/../lib/Listener/CalendarObjectReminderUpdaterListener.php',
'OCA\\DAV\\Migration\\BuildCalendarSearchIndex' => __DIR__ . '/..' . '/../lib/Migration/BuildCalendarSearchIndex.php',
'OCA\\DAV\\Migration\\BuildCalendarSearchIndexBackgroundJob' => __DIR__ . '/..' . '/../lib/Migration/BuildCalendarSearchIndexBackgroundJob.php',
'OCA\\DAV\\Migration\\BuildSocialSearchIndex' => __DIR__ . '/..' . '/../lib/Migration/BuildSocialSearchIndex.php',
diff --git a/apps/dav/lib/AppInfo/Application.php b/apps/dav/lib/AppInfo/Application.php
index 8298a9dd6f7..19c360e708a 100644
--- a/apps/dav/lib/AppInfo/Application.php
+++ b/apps/dav/lib/AppInfo/Application.php
@@ -36,7 +36,6 @@ namespace OCA\DAV\AppInfo;
use Exception;
use OCA\DAV\BackgroundJob\UpdateCalendarResourcesRoomsBackgroundJob;
use OCA\DAV\CalDAV\Activity\Backend;
-use OCA\DAV\CalDAV\Activity\Provider\Event;
use OCA\DAV\CalDAV\BirthdayService;
use OCA\DAV\CalDAV\CalDavBackend;
use OCA\DAV\CalDAV\CalendarManager;
@@ -45,7 +44,7 @@ use OCA\DAV\CalDAV\Reminder\NotificationProvider\EmailProvider;
use OCA\DAV\CalDAV\Reminder\NotificationProvider\PushProvider;
use OCA\DAV\CalDAV\Reminder\NotificationProviderManager;
use OCA\DAV\CalDAV\Reminder\Notifier;
-use OCA\DAV\CalDAV\Reminder\ReminderService;
+
use OCA\DAV\CalDAV\WebcalCaching\RefreshWebcalService;
use OCA\DAV\Capabilities;
use OCA\DAV\CardDAV\CardDavBackend;
@@ -54,13 +53,14 @@ use OCA\DAV\CardDAV\PhotoCache;
use OCA\DAV\CardDAV\SyncService;
use OCA\DAV\Events\CalendarDeletedEvent;
use OCA\DAV\Events\CalendarObjectCreatedEvent;
+use OCA\DAV\Events\CalendarObjectDeletedEvent;
use OCA\DAV\Events\CalendarObjectUpdatedEvent;
use OCA\DAV\Events\CalendarShareUpdatedEvent;
use OCA\DAV\HookManager;
+use OCA\DAV\Listener\ActivityUpdaterListener;
use OCA\DAV\Listener\CalendarContactInteractionListener;
-use OCA\DAV\Listener\CalendarDeletionActivityUpdaterListener;
use OCA\DAV\Listener\CalendarDeletionDefaultUpdaterListener;
-use OCA\DAV\Listener\CalendarDeletionReminderUpdaterListener;
+use OCA\DAV\Listener\CalendarObjectReminderUpdaterListener;
use OCA\DAV\Search\ContactsSearchProvider;
use OCA\DAV\Search\EventsSearchProvider;
use OCA\DAV\Search\TasksSearchProvider;
@@ -114,11 +114,17 @@ class Application extends App implements IBootstrap {
/**
* Register event listeners
*/
- $context->registerEventListener(CalendarDeletedEvent::class, CalendarDeletionActivityUpdaterListener::class);
- $context->registerEventListener(CalendarDeletedEvent::class, CalendarDeletionReminderUpdaterListener::class);
+ $context->registerEventListener(CalendarDeletedEvent::class, ActivityUpdaterListener::class);
+ $context->registerEventListener(CalendarDeletedEvent::class, CalendarObjectReminderUpdaterListener::class);
$context->registerEventListener(CalendarDeletedEvent::class, CalendarDeletionDefaultUpdaterListener::class);
+ $context->registerEventListener(CalendarObjectCreatedEvent::class, ActivityUpdaterListener::class);
$context->registerEventListener(CalendarObjectCreatedEvent::class, CalendarContactInteractionListener::class);
+ $context->registerEventListener(CalendarObjectCreatedEvent::class, CalendarObjectReminderUpdaterListener::class);
+ $context->registerEventListener(CalendarObjectUpdatedEvent::class, ActivityUpdaterListener::class);
$context->registerEventListener(CalendarObjectUpdatedEvent::class, CalendarContactInteractionListener::class);
+ $context->registerEventListener(CalendarObjectUpdatedEvent::class, CalendarObjectReminderUpdaterListener::class);
+ $context->registerEventListener(CalendarObjectDeletedEvent::class, ActivityUpdaterListener::class);
+ $context->registerEventListener(CalendarObjectDeletedEvent::class, CalendarObjectReminderUpdaterListener::class);
$context->registerEventListener(CalendarShareUpdatedEvent::class, CalendarContactInteractionListener::class);
$context->registerNotifierService(Notifier::class);
@@ -230,34 +236,6 @@ class Application extends App implements IBootstrap {
);
});
- $listener = function (GenericEvent $event, $eventName) use ($container): void {
- /** @var Backend $backend */
- $backend = $container->query(Backend::class);
-
- $subject = Event::SUBJECT_OBJECT_ADD;
- if ($eventName === '\OCA\DAV\CalDAV\CalDavBackend::updateCalendarObject') {
- $subject = Event::SUBJECT_OBJECT_UPDATE;
- } elseif ($eventName === '\OCA\DAV\CalDAV\CalDavBackend::deleteCalendarObject') {
- $subject = Event::SUBJECT_OBJECT_DELETE;
- }
- $backend->onTouchCalendarObject(
- $subject,
- $event->getArgument('calendarData'),
- $event->getArgument('shares'),
- $event->getArgument('objectData')
- );
-
- /** @var ReminderService $reminderBackend */
- $reminderService = $container->query(ReminderService::class);
-
- $reminderService->onTouchCalendarObject(
- $eventName,
- $event->getArgument('objectData')
- );
- };
- $dispatcher->addListener('\OCA\DAV\CalDAV\CalDavBackend::createCalendarObject', $listener);
- $dispatcher->addListener('\OCA\DAV\CalDAV\CalDavBackend::updateCalendarObject', $listener);
- $dispatcher->addListener('\OCA\DAV\CalDAV\CalDavBackend::deleteCalendarObject', $listener);
$dispatcher->addListener('OCP\Federation\TrustedServerEvent::remove',
function (GenericEvent $event) {
diff --git a/apps/dav/lib/BackgroundJob/BuildReminderIndexBackgroundJob.php b/apps/dav/lib/BackgroundJob/BuildReminderIndexBackgroundJob.php
index ad5bf7736ab..badfc2ca041 100644
--- a/apps/dav/lib/BackgroundJob/BuildReminderIndexBackgroundJob.php
+++ b/apps/dav/lib/BackgroundJob/BuildReminderIndexBackgroundJob.php
@@ -125,7 +125,7 @@ class BuildReminderIndexBackgroundJob extends QueuedJob {
$row['component'] = $row['componenttype'];
try {
- $this->reminderService->onTouchCalendarObject('\OCA\DAV\CalDAV\CalDavBackend::createCalendarObject', $row);
+ $this->reminderService->onCalendarObjectCreate($row);
} catch (\Exception $ex) {
$this->logger->logException($ex);
}
diff --git a/apps/dav/lib/CalDAV/CalDavBackend.php b/apps/dav/lib/CalDAV/CalDavBackend.php
index 138bb9b4828..e14c0ec6b45 100644
--- a/apps/dav/lib/CalDAV/CalDavBackend.php
+++ b/apps/dav/lib/CalDAV/CalDavBackend.php
@@ -1141,15 +1141,6 @@ class CalDavBackend extends AbstractBackend implements SyncSupport, Subscription
$shares = $this->getShares($calendarId);
$this->dispatcher->dispatchTyped(new CalendarObjectCreatedEvent((int)$calendarId, $calendarRow, $shares, $objectRow));
- $this->legacyDispatcher->dispatch('\OCA\DAV\CalDAV\CalDavBackend::createCalendarObject', new GenericEvent(
- '\OCA\DAV\CalDAV\CalDavBackend::createCalendarObject',
- [
- 'calendarId' => $calendarId,
- 'calendarData' => $calendarRow,
- 'shares' => $shares,
- 'objectData' => $objectRow,
- ]
- ));
} else {
$subscriptionRow = $this->getSubscriptionById($calendarId);
@@ -1215,15 +1206,6 @@ class CalDavBackend extends AbstractBackend implements SyncSupport, Subscription
$shares = $this->getShares($calendarId);
$this->dispatcher->dispatchTyped(new CalendarObjectUpdatedEvent((int)$calendarId, $calendarRow, $shares, $objectRow));
- $this->legacyDispatcher->dispatch('\OCA\DAV\CalDAV\CalDavBackend::updateCalendarObject', new GenericEvent(
- '\OCA\DAV\CalDAV\CalDavBackend::updateCalendarObject',
- [
- 'calendarId' => $calendarId,
- 'calendarData' => $calendarRow,
- 'shares' => $shares,
- 'objectData' => $objectRow,
- ]
- ));
} else {
$subscriptionRow = $this->getSubscriptionById($calendarId);
@@ -1278,15 +1260,6 @@ class CalDavBackend extends AbstractBackend implements SyncSupport, Subscription
$shares = $this->getShares($calendarId);
$this->dispatcher->dispatchTyped(new CalendarObjectDeletedEvent((int)$calendarId, $calendarRow, $shares, $data));
- $this->legacyDispatcher->dispatch('\OCA\DAV\CalDAV\CalDavBackend::deleteCalendarObject', new GenericEvent(
- '\OCA\DAV\CalDAV\CalDavBackend::deleteCalendarObject',
- [
- 'calendarId' => $calendarId,
- 'calendarData' => $calendarRow,
- 'shares' => $shares,
- 'objectData' => $data,
- ]
- ));
} else {
$subscriptionRow = $this->getSubscriptionById($calendarId);
diff --git a/apps/dav/lib/CalDAV/Reminder/ReminderService.php b/apps/dav/lib/CalDAV/Reminder/ReminderService.php
index 9c27231cb8a..83fe413c0ee 100644
--- a/apps/dav/lib/CalDAV/Reminder/ReminderService.php
+++ b/apps/dav/lib/CalDAV/Reminder/ReminderService.php
@@ -44,6 +44,7 @@ use Sabre\VObject\InvalidDataException;
use Sabre\VObject\ParseException;
use Sabre\VObject\Recur\EventIterator;
use Sabre\VObject\Recur\NoInstancesException;
+use function strcasecmp;
class ReminderService {
@@ -154,39 +155,15 @@ class ReminderService {
}
/**
- * @param string $action
* @param array $objectData
* @throws VObject\InvalidDataException
*/
- public function onTouchCalendarObject(string $action,
- array $objectData):void {
+ public function onCalendarObjectCreate(array $objectData):void {
// We only support VEvents for now
if (strcasecmp($objectData['component'], 'vevent') !== 0) {
return;
}
- switch ($action) {
- case '\OCA\DAV\CalDAV\CalDavBackend::createCalendarObject':
- $this->onCalendarObjectCreate($objectData);
- break;
-
- case '\OCA\DAV\CalDAV\CalDavBackend::updateCalendarObject':
- $this->onCalendarObjectEdit($objectData);
- break;
-
- case '\OCA\DAV\CalDAV\CalDavBackend::deleteCalendarObject':
- $this->onCalendarObjectDelete($objectData);
- break;
-
- default:
- break;
- }
- }
-
- /**
- * @param array $objectData
- */
- private function onCalendarObjectCreate(array $objectData):void {
$calendarData = is_resource($objectData['calendardata'])
? stream_get_contents($objectData['calendardata'])
: $objectData['calendardata'];
@@ -307,8 +284,9 @@ class ReminderService {
/**
* @param array $objectData
+ * @throws VObject\InvalidDataException
*/
- private function onCalendarObjectEdit(array $objectData):void {
+ public function onCalendarObjectEdit(array $objectData):void {
// TODO - this can be vastly improved
// - get cached reminders
// - ...
@@ -319,8 +297,14 @@ class ReminderService {
/**
* @param array $objectData
+ * @throws VObject\InvalidDataException
*/
- private function onCalendarObjectDelete(array $objectData):void {
+ public function onCalendarObjectDelete(array $objectData):void {
+ // We only support VEvents for now
+ if (strcasecmp($objectData['component'], 'vevent') !== 0) {
+ return;
+ }
+
$this->backend->cleanRemindersForEvent((int) $objectData['id']);
}
diff --git a/apps/dav/lib/Listener/ActivityUpdaterListener.php b/apps/dav/lib/Listener/ActivityUpdaterListener.php
new file mode 100644
index 00000000000..8ff65170e3f
--- /dev/null
+++ b/apps/dav/lib/Listener/ActivityUpdaterListener.php
@@ -0,0 +1,126 @@
+<?php
+
+declare(strict_types=1);
+
+/*
+ * @copyright 2021 Christoph Wurst <christoph@winzerhof-wurst.at>
+ *
+ * @author 2021 Christoph Wurst <christoph@winzerhof-wurst.at>
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+namespace OCA\DAV\Listener;
+
+use OCA\DAV\CalDAV\Activity\Backend as ActivityBackend;
+use OCA\DAV\Events\CalendarDeletedEvent;
+use OCA\DAV\Events\CalendarObjectCreatedEvent;
+use OCA\DAV\Events\CalendarObjectDeletedEvent;
+use OCA\DAV\Events\CalendarObjectUpdatedEvent;
+use OCP\EventDispatcher\Event;
+use OCP\EventDispatcher\IEventListener;
+use Psr\Log\LoggerInterface;
+use Throwable;
+use function sprintf;
+
+class ActivityUpdaterListener implements IEventListener {
+
+ /** @var ActivityBackend */
+ private $activityBackend;
+
+ /** @var LoggerInterface */
+ private $logger;
+
+ public function __construct(ActivityBackend $activityBackend,
+ LoggerInterface $logger) {
+ $this->activityBackend = $activityBackend;
+ $this->logger = $logger;
+ }
+
+ public function handle(Event $event): void {
+ if ($event instanceof CalendarDeletedEvent) {
+ try {
+ $this->activityBackend->onCalendarDelete(
+ $event->getCalendarData(),
+ $event->getShares()
+ );
+
+ $this->logger->debug(
+ sprintf('Activity generated for deleted calendar %d', $event->getCalendarId())
+ );
+ } catch (Throwable $e) {
+ // Any error with activities shouldn't abort the calendar deletion, so we just log it
+ $this->logger->error('Error generating activities for a deleted calendar: ' . $e->getMessage(), [
+ 'exception' => $e,
+ ]);
+ }
+ } elseif ($event instanceof CalendarObjectCreatedEvent) {
+ try {
+ $this->activityBackend->onTouchCalendarObject(
+ \OCA\DAV\CalDAV\Activity\Provider\Event::SUBJECT_OBJECT_ADD,
+ $event->getCalendarData(),
+ $event->getShares(),
+ $event->getObjectData()
+ );
+
+ $this->logger->debug(
+ sprintf('Activity generated for new calendar object in calendar %d', $event->getCalendarId())
+ );
+ } catch (Throwable $e) {
+ // Any error with activities shouldn't abort the calendar object creation, so we just log it
+ $this->logger->error('Error generating activity for a new calendar object: ' . $e->getMessage(), [
+ 'exception' => $e,
+ ]);
+ }
+ } elseif ($event instanceof CalendarObjectUpdatedEvent) {
+ try {
+ $this->activityBackend->onTouchCalendarObject(
+ \OCA\DAV\CalDAV\Activity\Provider\Event::SUBJECT_OBJECT_UPDATE,
+ $event->getCalendarData(),
+ $event->getShares(),
+ $event->getObjectData()
+ );
+
+ $this->logger->debug(
+ sprintf('Activity generated for deleted calendar object %d', $event->getCalendarId())
+ );
+ } catch (Throwable $e) {
+ // Any error with activities shouldn't abort the calendar deletion, so we just log it
+ $this->logger->error('Error generating activity for a deleted calendar object: ' . $e->getMessage(), [
+ 'exception' => $e,
+ ]);
+ }
+ } elseif ($event instanceof CalendarObjectDeletedEvent) {
+ try {
+ $this->activityBackend->onTouchCalendarObject(
+ \OCA\DAV\CalDAV\Activity\Provider\Event::SUBJECT_OBJECT_DELETE,
+ $event->getCalendarData(),
+ $event->getShares(),
+ $event->getObjectData()
+ );
+
+ $this->logger->debug(
+ sprintf('Activity generated for deleted calendar object %d', $event->getCalendarId())
+ );
+ } catch (Throwable $e) {
+ // Any error with activities shouldn't abort the calendar deletion, so we just log it
+ $this->logger->error('Error generating activity for a deleted calendar object: ' . $e->getMessage(), [
+ 'exception' => $e,
+ ]);
+ }
+ }
+ }
+}
diff --git a/apps/dav/lib/Listener/CalendarDeletionActivityUpdaterListener.php b/apps/dav/lib/Listener/CalendarDeletionActivityUpdaterListener.php
deleted file mode 100644
index 4139aba226e..00000000000
--- a/apps/dav/lib/Listener/CalendarDeletionActivityUpdaterListener.php
+++ /dev/null
@@ -1,75 +0,0 @@
-<?php
-
-declare(strict_types=1);
-
-/*
- * @copyright 2021 Christoph Wurst <christoph@winzerhof-wurst.at>
- *
- * @author 2021 Christoph Wurst <christoph@winzerhof-wurst.at>
- *
- * @license GNU AGPL version 3 or any later version
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-namespace OCA\DAV\Listener;
-
-use OCA\DAV\CalDAV\Activity\Backend as ActivityBackend;
-use OCA\DAV\Events\CalendarDeletedEvent;
-use OCP\EventDispatcher\Event;
-use OCP\EventDispatcher\IEventListener;
-use Psr\Log\LoggerInterface;
-use Throwable;
-use function sprintf;
-
-/**
- * @template-implements IEventListener<\OCA\DAV\Events\CalendarDeletedEvent>
- */
-class CalendarDeletionActivityUpdaterListener implements IEventListener {
-
- /** @var ActivityBackend */
- private $activityBackend;
-
- /** @var LoggerInterface */
- private $logger;
-
- public function __construct(ActivityBackend $activityBackend,
- LoggerInterface $logger) {
- $this->activityBackend = $activityBackend;
- $this->logger = $logger;
- }
-
- public function handle(Event $event): void {
- if (!($event instanceof CalendarDeletedEvent)) {
- // Not what we subscribed to
- return;
- }
-
- try {
- $this->activityBackend->onCalendarDelete(
- $event->getCalendarData(),
- $event->getShares()
- );
-
- $this->logger->debug(
- sprintf('Activity generated for deleted calendar %d', $event->getCalendarId())
- );
- } catch (Throwable $e) {
- // Any error with activities shouldn't abort the calendar deletion, so we just log it
- $this->logger->error('Error generating activities for a deleted calendar: ' . $e->getMessage(), [
- 'exception' => $e,
- ]);
- }
- }
-}
diff --git a/apps/dav/lib/Listener/CalendarDeletionReminderUpdaterListener.php b/apps/dav/lib/Listener/CalendarDeletionReminderUpdaterListener.php
deleted file mode 100644
index 3beecc8ff05..00000000000
--- a/apps/dav/lib/Listener/CalendarDeletionReminderUpdaterListener.php
+++ /dev/null
@@ -1,74 +0,0 @@
-<?php
-
-declare(strict_types=1);
-
-/*
- * @copyright 2021 Christoph Wurst <christoph@winzerhof-wurst.at>
- *
- * @author 2021 Christoph Wurst <christoph@winzerhof-wurst.at>
- *
- * @license GNU AGPL version 3 or any later version
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-namespace OCA\DAV\Listener;
-
-use OCA\DAV\CalDAV\Reminder\Backend as ReminderBackend;
-use OCA\DAV\Events\CalendarDeletedEvent;
-use OCP\EventDispatcher\Event;
-use OCP\EventDispatcher\IEventListener;
-use Psr\Log\LoggerInterface;
-use Throwable;
-use function sprintf;
-
-/**
- * @template-implements IEventListener<\OCA\DAV\Events\CalendarDeletedEvent>
- */
-class CalendarDeletionReminderUpdaterListener implements IEventListener {
-
- /** @var ReminderBackend */
- private $reminderBackend;
-
- /** @var LoggerInterface */
- private $logger;
-
- public function __construct(ReminderBackend $reminderBackend,
- LoggerInterface $logger) {
- $this->reminderBackend = $reminderBackend;
- $this->logger = $logger;
- }
-
- public function handle(Event $event): void {
- if (!($event instanceof CalendarDeletedEvent)) {
- // Not what we subscribed to
- return;
- }
-
- try {
- $this->reminderBackend->cleanRemindersForCalendar(
- $event->getCalendarId()
- );
-
- $this->logger->debug(
- sprintf('Reminders of calendar %d cleaned up', $event->getCalendarId())
- );
- } catch (Throwable $e) {
- // Any error with activities shouldn't abort the calendar deletion, so we just log it
- $this->logger->error('Error cleaning up reminders of a deleted calendar: ' . $e->getMessage(), [
- 'exception' => $e,
- ]);
- }
- }
-}
diff --git a/apps/dav/lib/Listener/CalendarObjectReminderUpdaterListener.php b/apps/dav/lib/Listener/CalendarObjectReminderUpdaterListener.php
new file mode 100644
index 00000000000..b976ef3ad9d
--- /dev/null
+++ b/apps/dav/lib/Listener/CalendarObjectReminderUpdaterListener.php
@@ -0,0 +1,122 @@
+<?php
+
+declare(strict_types=1);
+
+/*
+ * @copyright 2021 Christoph Wurst <christoph@winzerhof-wurst.at>
+ *
+ * @author 2021 Christoph Wurst <christoph@winzerhof-wurst.at>
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+namespace OCA\DAV\Listener;
+
+use OCA\DAV\CalDAV\Reminder\Backend as ReminderBackend;
+use OCA\DAV\CalDAV\Reminder\ReminderService;
+use OCA\DAV\Events\CalendarDeletedEvent;
+use OCA\DAV\Events\CalendarObjectCreatedEvent;
+use OCA\DAV\Events\CalendarObjectDeletedEvent;
+use OCA\DAV\Events\CalendarObjectUpdatedEvent;
+use OCP\EventDispatcher\Event;
+use OCP\EventDispatcher\IEventListener;
+use Psr\Log\LoggerInterface;
+use Throwable;
+use function sprintf;
+
+class CalendarObjectReminderUpdaterListener implements IEventListener {
+
+ /** @var ReminderBackend */
+ private $reminderBackend;
+
+ /** @var ReminderService */
+ private $reminderService;
+
+ /** @var LoggerInterface */
+ private $logger;
+
+ public function __construct(ReminderBackend $reminderBackend,
+ ReminderService $reminderService,
+ LoggerInterface $logger) {
+ $this->reminderBackend = $reminderBackend;
+ $this->reminderService = $reminderService;
+ $this->logger = $logger;
+ }
+
+ public function handle(Event $event): void {
+ if ($event instanceof CalendarDeletedEvent) {
+ try {
+ $this->reminderBackend->cleanRemindersForCalendar(
+ $event->getCalendarId()
+ );
+
+ $this->logger->debug(
+ sprintf('Reminders of calendar %d cleaned up', $event->getCalendarId())
+ );
+ } catch (Throwable $e) {
+ // Any error with activities shouldn't abort the calendar deletion, so we just log it
+ $this->logger->error('Error cleaning up reminders of a deleted calendar: ' . $e->getMessage(), [
+ 'exception' => $e,
+ ]);
+ }
+ } elseif ($event instanceof CalendarObjectCreatedEvent) {
+ try {
+ $this->reminderService->onCalendarObjectCreate(
+ $event->getObjectData()
+ );
+
+ $this->logger->debug(
+ sprintf('Reminders of calendar object of calendar %d created', $event->getCalendarId())
+ );
+ } catch (Throwable $e) {
+ // Any error with reminders shouldn't abort the calendar object creation, so we just log it
+ $this->logger->error('Error creating reminders of a calendar object: ' . $e->getMessage(), [
+ 'exception' => $e,
+ ]);
+ }
+ } elseif ($event instanceof CalendarObjectUpdatedEvent) {
+ try {
+ $this->reminderService->onCalendarObjectEdit(
+ $event->getObjectData()
+ );
+
+ $this->logger->debug(
+ sprintf('Reminders of calendar object of calendar %d cleaned up', $event->getCalendarId())
+ );
+ } catch (Throwable $e) {
+ // Any error with activities shouldn't abort the calendar object deletion, so we just log it
+ $this->logger->error('Error cleaning up reminders of a calendar object: ' . $e->getMessage(), [
+ 'exception' => $e,
+ ]);
+ }
+ } elseif ($event instanceof CalendarObjectDeletedEvent) {
+ try {
+ $this->reminderService->onCalendarObjectDelete(
+ $event->getObjectData()
+ );
+
+ $this->logger->debug(
+ sprintf('Reminders of calendar object of calendar %d cleaned up', $event->getCalendarId())
+ );
+ } catch (Throwable $e) {
+ // Any error with activities shouldn't abort the calendar object deletion, so we just log it
+ $this->logger->error('Error cleaning up reminders of a deleted calendar object: ' . $e->getMessage(), [
+ 'exception' => $e,
+ ]);
+ }
+ }
+ }
+}
diff --git a/apps/dav/tests/unit/CalDAV/AbstractCalDavBackend.php b/apps/dav/tests/unit/CalDAV/AbstractCalDavBackend.php
index b512847a7e8..17ac839b5f2 100644
--- a/apps/dav/tests/unit/CalDAV/AbstractCalDavBackend.php
+++ b/apps/dav/tests/unit/CalDAV/AbstractCalDavBackend.php
@@ -32,6 +32,7 @@ use OCA\DAV\CalDAV\CalDavBackend;
use OCA\DAV\CalDAV\Proxy\ProxyMapper;
use OCA\DAV\Connector\Sabre\Principal;
use OCA\DAV\Events\CalendarDeletedEvent;
+use OCA\DAV\Events\CalendarObjectCreatedEvent;
use OCP\App\IAppManager;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\IConfig;
@@ -206,9 +207,11 @@ END:VCALENDAR
EOD;
$uri0 = $this->getUniqueID('event');
- $this->legacyDispatcher->expects($this->at(0))
- ->method('dispatch')
- ->with('\OCA\DAV\CalDAV\CalDavBackend::createCalendarObject');
+ $this->dispatcher->expects(self::once())
+ ->method('dispatchTyped')
+ ->with(self::callback(function ($event) {
+ return $event instanceof CalendarObjectCreatedEvent;
+ }));
$this->backend->createCalendarObject($calendarId, $uri0, $calData);
diff --git a/apps/dav/tests/unit/CalDAV/CalDavBackendTest.php b/apps/dav/tests/unit/CalDAV/CalDavBackendTest.php
index 25966aa5c95..097fbd79fe3 100644
--- a/apps/dav/tests/unit/CalDAV/CalDavBackendTest.php
+++ b/apps/dav/tests/unit/CalDAV/CalDavBackendTest.php
@@ -37,6 +37,8 @@ use DateTimeZone;
use OCA\DAV\CalDAV\CalDavBackend;
use OCA\DAV\CalDAV\Calendar;
use OCA\DAV\Events\CalendarDeletedEvent;
+use OCA\DAV\Events\CalendarObjectCreatedEvent;
+use OCA\DAV\Events\CalendarUpdatedEvent;
use OCP\IConfig;
use OCP\IL10N;
use Sabre\DAV\Exception\NotFound;
@@ -186,9 +188,11 @@ END:VEVENT
END:VCALENDAR
EOD;
- $this->legacyDispatcher->expects($this->at(0))
- ->method('dispatch')
- ->with('\OCA\DAV\CalDAV\CalDavBackend::createCalendarObject');
+ $this->dispatcher->expects(self::once())
+ ->method('dispatchTyped')
+ ->with(self::callback(function ($event) {
+ return $event instanceof CalendarObjectCreatedEvent;
+ }));
$this->backend->createCalendarObject($calendarId, $uri, $calData);
/** @var IACL $child */
@@ -232,9 +236,11 @@ END:VEVENT
END:VCALENDAR
EOD;
- $this->legacyDispatcher->expects($this->at(0))
- ->method('dispatch')
- ->with('\OCA\DAV\CalDAV\CalDavBackend::createCalendarObject');
+ $this->dispatcher->expects(self::once())
+ ->method('dispatchTyped')
+ ->with(self::callback(function ($event) {
+ return $event instanceof CalendarObjectCreatedEvent;
+ }));
$this->backend->createCalendarObject($calendarId, $uri, $calData);
// get all the cards
@@ -270,17 +276,21 @@ DTEND;VALUE=DATE-TIME:20130912T140000Z
END:VEVENT
END:VCALENDAR
EOD;
- $this->legacyDispatcher->expects($this->at(0))
- ->method('dispatch')
- ->with('\OCA\DAV\CalDAV\CalDavBackend::updateCalendarObject');
+ $this->dispatcher->expects(self::once())
+ ->method('dispatchTyped')
+ ->with(self::callback(function ($event) {
+ return $event instanceof CalendarUpdatedEvent;
+ }));
$this->backend->updateCalendarObject($calendarId, $uri, $calData);
$calendarObject = $this->backend->getCalendarObject($calendarId, $uri);
$this->assertEquals($calData, $calendarObject['calendardata']);
// delete the card
- $this->legacyDispatcher->expects($this->at(0))
- ->method('dispatch')
- ->with('\OCA\DAV\CalDAV\CalDavBackend::deleteCalendarObject');
+ $this->dispatcher->expects(self::once())
+ ->method('dispatchTyped')
+ ->with(self::callback(function ($event) {
+ return $event instanceof CalendarDeletedEvent;
+ }));
$this->backend->deleteCalendarObject($calendarId, $uri);
$calendarObjects = $this->backend->getCalendarObjects($calendarId);
$this->assertCount(0, $calendarObjects);
@@ -373,19 +383,25 @@ END:VCALENDAR
EOD;
$uri0 = static::getUniqueID('card');
- $this->legacyDispatcher->expects($this->at(0))
- ->method('dispatch')
- ->with('\OCA\DAV\CalDAV\CalDavBackend::createCalendarObject');
+ $this->dispatcher->expects(self::once())
+ ->method('dispatchTyped')
+ ->with(self::callback(function ($event) {
+ return $event instanceof CalendarObjectCreatedEvent;
+ }));
$this->backend->createCalendarObject($calendarId, $uri0, $calData[0]);
$uri1 = static::getUniqueID('card');
- $this->legacyDispatcher->expects($this->at(0))
- ->method('dispatch')
- ->with('\OCA\DAV\CalDAV\CalDavBackend::createCalendarObject');
+ $this->dispatcher->expects(self::once())
+ ->method('dispatchTyped')
+ ->with(self::callback(function ($event) {
+ return $event instanceof CalendarObjectCreatedEvent;
+ }));
$this->backend->createCalendarObject($calendarId, $uri1, $calData[1]);
$uri2 = static::getUniqueID('card');
- $this->legacyDispatcher->expects($this->at(0))
- ->method('dispatch')
- ->with('\OCA\DAV\CalDAV\CalDavBackend::createCalendarObject');
+ $this->dispatcher->expects(self::once())
+ ->method('dispatchTyped')
+ ->with(self::callback(function ($event) {
+ return $event instanceof CalendarObjectCreatedEvent;
+ }));
$this->backend->createCalendarObject($calendarId, $uri2, $calData[2]);
// get all the cards
@@ -412,17 +428,23 @@ EOD;
$this->assertEquals($calData[2], $calendarObjects[1]['calendardata']);
// delete the card
- $this->legacyDispatcher->expects($this->at(0))
- ->method('dispatch')
- ->with('\OCA\DAV\CalDAV\CalDavBackend::deleteCalendarObject');
+ $this->dispatcher->expects(self::once())
+ ->method('dispatchTyped')
+ ->with(self::callback(function ($event) {
+ return $event instanceof CalendarDeletedEvent;
+ }));
$this->backend->deleteCalendarObject($calendarId, $uri0);
- $this->legacyDispatcher->expects($this->at(0))
- ->method('dispatch')
- ->with('\OCA\DAV\CalDAV\CalDavBackend::deleteCalendarObject');
+ $this->dispatcher->expects(self::once())
+ ->method('dispatchTyped')
+ ->with(self::callback(function ($event) {
+ return $event instanceof CalendarDeletedEvent;
+ }));
$this->backend->deleteCalendarObject($calendarId, $uri1);
- $this->legacyDispatcher->expects($this->at(0))
- ->method('dispatch')
- ->with('\OCA\DAV\CalDAV\CalDavBackend::deleteCalendarObject');
+ $this->dispatcher->expects(self::once())
+ ->method('dispatchTyped')
+ ->with(self::callback(function ($event) {
+ return $event instanceof CalendarDeletedEvent;
+ }));
$this->backend->deleteCalendarObject($calendarId, $uri2);
$calendarObjects = $this->backend->getCalendarObjects($calendarId);
$this->assertCount(0, $calendarObjects);
diff --git a/apps/dav/tests/unit/CalDAV/Reminder/ReminderServiceTest.php b/apps/dav/tests/unit/CalDAV/Reminder/ReminderServiceTest.php
index 2d4cbfd0c8c..ce5b5acdd69 100644
--- a/apps/dav/tests/unit/CalDAV/Reminder/ReminderServiceTest.php
+++ b/apps/dav/tests/unit/CalDAV/Reminder/ReminderServiceTest.php
@@ -211,17 +211,15 @@ EOD;
->method('cleanRemindersForEvent')
->with(44);
- $action = '\OCA\DAV\CalDAV\CalDavBackend::deleteCalendarObject';
$objectData = [
'id' => '44',
'component' => 'vevent',
];
- $this->reminderService->onTouchCalendarObject($action, $objectData);
+ $this->reminderService->onCalendarObjectDelete($objectData);
}
public function testOnCalendarObjectCreateSingleEntry():void {
- $action = '\OCA\DAV\CalDAV\CalDavBackend::createCalendarObject';
$objectData = [
'calendardata' => self::CALENDAR_DATA,
'id' => '42',
@@ -242,11 +240,10 @@ EOD;
->with()
->willReturn(\DateTime::createFromFormat(\DateTime::ATOM, '2016-06-08T00:00:00+00:00'));
- $this->reminderService->onTouchCalendarObject($action, $objectData);
+ $this->reminderService->onCalendarObjectCreate($objectData);
}
public function testOnCalendarObjectCreateSingleEntryWithRepeat(): void {
- $action = '\OCA\DAV\CalDAV\CalDavBackend::createCalendarObject';
$objectData = [
'calendardata' => self::CALENDAR_DATA_REPEAT,
'id' => '42',
@@ -270,11 +267,10 @@ EOD;
->with()
->willReturn(\DateTime::createFromFormat(\DateTime::ATOM, '2016-06-08T00:00:00+00:00'));
- $this->reminderService->onTouchCalendarObject($action, $objectData);
+ $this->reminderService->onCalendarObjectCreate($objectData);
}
public function testOnCalendarObjectCreateRecurringEntry(): void {
- $action = '\OCA\DAV\CalDAV\CalDavBackend::createCalendarObject';
$objectData = [
'calendardata' => self::CALENDAR_DATA_RECURRING,
'id' => '42',
@@ -295,11 +291,10 @@ EOD;
->with()
->willReturn(\DateTime::createFromFormat(\DateTime::ATOM, '2016-06-29T00:00:00+00:00'));
- $this->reminderService->onTouchCalendarObject($action, $objectData);
+ $this->reminderService->onCalendarObjectCreate($objectData);
}
public function testOnCalendarObjectCreateEmpty():void {
- $action = '\OCA\DAV\CalDAV\CalDavBackend::createCalendarObject';
$objectData = [
'calendardata' => self::CALENDAR_DATA_NO_ALARM,
'id' => '42',
@@ -310,11 +305,10 @@ EOD;
$this->backend->expects($this->never())
->method('insertReminder');
- $this->reminderService->onTouchCalendarObject($action, $objectData);
+ $this->reminderService->onCalendarObjectCreate($objectData);
}
public function testOnCalendarObjectCreateRecurringEntryWithRepeat():void {
- $action = '\OCA\DAV\CalDAV\CalDavBackend::createCalendarObject';
$objectData = [
'calendardata' => self::CALENDAR_DATA_RECURRING_REPEAT,
'id' => '42',
@@ -339,7 +333,7 @@ EOD;
->with()
->willReturn(\DateTime::createFromFormat(\DateTime::ATOM, '2016-06-29T00:00:00+00:00'));
- $this->reminderService->onTouchCalendarObject($action, $objectData);
+ $this->reminderService->onCalendarObjectCreate($objectData);
}
public function testProcessReminders():void {