From d512a5629ec01fecd87944836eb9b02eb11257b8 Mon Sep 17 00:00:00 2001 From: Christoph Wurst Date: Fri, 7 May 2021 10:26:49 +0200 Subject: Remove the \OCA\DAV\CalDAV\CalDavBackend::deleteCalendarObject event Signed-off-by: Christoph Wurst --- apps/dav/lib/CalDAV/CalDavBackend.php | 9 --------- 1 file changed, 9 deletions(-) (limited to 'apps/dav/lib/CalDAV') diff --git a/apps/dav/lib/CalDAV/CalDavBackend.php b/apps/dav/lib/CalDAV/CalDavBackend.php index fb99040dd66..b4782ca6840 100644 --- a/apps/dav/lib/CalDAV/CalDavBackend.php +++ b/apps/dav/lib/CalDAV/CalDavBackend.php @@ -1278,15 +1278,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); -- cgit v1.2.3 From f808267949e5513188961ca5f6fc38d57f6c7fd1 Mon Sep 17 00:00:00 2001 From: Christoph Wurst Date: Fri, 7 May 2021 11:19:45 +0200 Subject: Remove the \OCA\DAV\CalDAV\CalDavBackend::updateCalendarObject event Signed-off-by: Christoph Wurst --- apps/dav/lib/AppInfo/Application.php | 13 ++++++------- apps/dav/lib/CalDAV/CalDavBackend.php | 9 --------- apps/dav/lib/Listener/ActivityUpdaterListener.php | 19 +++++++++++++++++++ .../CalendarObjectReminderUpdaterListener.php | 17 +++++++++++++++++ apps/dav/tests/unit/CalDAV/CalDavBackendTest.php | 9 ++++++--- 5 files changed, 48 insertions(+), 19 deletions(-) (limited to 'apps/dav/lib/CalDAV') diff --git a/apps/dav/lib/AppInfo/Application.php b/apps/dav/lib/AppInfo/Application.php index 8bedb287148..a5444bb20d8 100644 --- a/apps/dav/lib/AppInfo/Application.php +++ b/apps/dav/lib/AppInfo/Application.php @@ -118,8 +118,12 @@ class Application extends App implements IBootstrap { $context->registerEventListener(CalendarDeletedEvent::class, ActivityUpdaterListener::class); $context->registerEventListener(CalendarDeletedEvent::class, CalendarObjectReminderUpdaterListener::class); $context->registerEventListener(CalendarDeletedEvent::class, CalendarDeletionDefaultUpdaterListener::class); + $context->registerEventListener(CalendarObjectCreatedEvent::class, CalendarContactInteractionListener::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); @@ -237,12 +241,8 @@ class Application extends App implements IBootstrap { /** @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; - } $backend->onTouchCalendarObject( - $subject, + Event::SUBJECT_OBJECT_ADD, $event->getArgument('calendarData'), $event->getArgument('shares'), $event->getArgument('objectData') @@ -257,7 +257,6 @@ class Application extends App implements IBootstrap { ); }; $dispatcher->addListener('\OCA\DAV\CalDAV\CalDavBackend::createCalendarObject', $listener); - $dispatcher->addListener('\OCA\DAV\CalDAV\CalDavBackend::updateCalendarObject', $listener); $dispatcher->addListener('OCP\Federation\TrustedServerEvent::remove', function (GenericEvent $event) { @@ -380,4 +379,4 @@ class Application extends App implements IBootstrap { $logger->logException($ex); } } -} +} \ No newline at end of file diff --git a/apps/dav/lib/CalDAV/CalDavBackend.php b/apps/dav/lib/CalDAV/CalDavBackend.php index b4782ca6840..058d4422d63 100644 --- a/apps/dav/lib/CalDAV/CalDavBackend.php +++ b/apps/dav/lib/CalDAV/CalDavBackend.php @@ -1215,15 +1215,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); diff --git a/apps/dav/lib/Listener/ActivityUpdaterListener.php b/apps/dav/lib/Listener/ActivityUpdaterListener.php index 9734a4fead8..962fa239af1 100644 --- a/apps/dav/lib/Listener/ActivityUpdaterListener.php +++ b/apps/dav/lib/Listener/ActivityUpdaterListener.php @@ -28,6 +28,7 @@ namespace OCA\DAV\Listener; use OCA\DAV\CalDAV\Activity\Backend as ActivityBackend; use OCA\DAV\Events\CalendarDeletedEvent; use OCA\DAV\Events\CalendarObjectDeletedEvent; +use OCA\DAV\Events\CalendarObjectUpdatedEvent; use OCP\EventDispatcher\Event; use OCP\EventDispatcher\IEventListener; use Psr\Log\LoggerInterface; @@ -65,6 +66,24 @@ class ActivityUpdaterListener implements IEventListener { '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( diff --git a/apps/dav/lib/Listener/CalendarObjectReminderUpdaterListener.php b/apps/dav/lib/Listener/CalendarObjectReminderUpdaterListener.php index 63fe786cfa2..8261b68af45 100644 --- a/apps/dav/lib/Listener/CalendarObjectReminderUpdaterListener.php +++ b/apps/dav/lib/Listener/CalendarObjectReminderUpdaterListener.php @@ -29,6 +29,7 @@ use OCA\DAV\CalDAV\Reminder\Backend as ReminderBackend; use OCA\DAV\CalDAV\Reminder\ReminderService; use OCA\DAV\Events\CalendarDeletedEvent; use OCA\DAV\Events\CalendarObjectDeletedEvent; +use OCA\DAV\Events\CalendarObjectUpdatedEvent; use OCP\EventDispatcher\Event; use OCP\EventDispatcher\IEventListener; use Psr\Log\LoggerInterface; @@ -70,6 +71,22 @@ class CalendarObjectReminderUpdaterListener implements IEventListener { 'exception' => $e, ]); } + } elseif ($event instanceof CalendarObjectUpdatedEvent) { + try { + $this->reminderService->onTouchCalendarObject( + '\OCA\DAV\CalDAV\CalDavBackend::updateCalendarObject', + $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->onTouchCalendarObject( diff --git a/apps/dav/tests/unit/CalDAV/CalDavBackendTest.php b/apps/dav/tests/unit/CalDAV/CalDavBackendTest.php index 98e1b728f9f..96ae4312fda 100644 --- a/apps/dav/tests/unit/CalDAV/CalDavBackendTest.php +++ b/apps/dav/tests/unit/CalDAV/CalDavBackendTest.php @@ -37,6 +37,7 @@ use DateTimeZone; use OCA\DAV\CalDAV\CalDavBackend; use OCA\DAV\CalDAV\Calendar; use OCA\DAV\Events\CalendarDeletedEvent; +use OCA\DAV\Events\CalendarUpdatedEvent; use OCP\IConfig; use OCP\IL10N; use Sabre\DAV\Exception\NotFound; @@ -270,9 +271,11 @@ 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']); -- cgit v1.2.3 From 257613e6efd429dd1c6cde4abbcbb590d32408e8 Mon Sep 17 00:00:00 2001 From: Christoph Wurst Date: Fri, 7 May 2021 11:36:23 +0200 Subject: Remove the \OCA\DAV\CalDAV\CalDavBackend::createCalendarObject event Signed-off-by: Christoph Wurst --- apps/dav/lib/AppInfo/Application.php | 29 +++------------ apps/dav/lib/CalDAV/CalDavBackend.php | 9 ----- apps/dav/lib/Listener/ActivityUpdaterListener.php | 19 ++++++++++ .../CalendarObjectReminderUpdaterListener.php | 17 +++++++++ .../tests/unit/CalDAV/AbstractCalDavBackend.php | 9 +++-- apps/dav/tests/unit/CalDAV/CalDavBackendTest.php | 41 ++++++++++++++-------- 6 files changed, 72 insertions(+), 52 deletions(-) (limited to 'apps/dav/lib/CalDAV') diff --git a/apps/dav/lib/AppInfo/Application.php b/apps/dav/lib/AppInfo/Application.php index a5444bb20d8..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; @@ -118,9 +117,9 @@ class Application extends App implements IBootstrap { $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); @@ -237,26 +236,6 @@ class Application extends App implements IBootstrap { ); }); - $listener = function (GenericEvent $event, $eventName) use ($container): void { - /** @var Backend $backend */ - $backend = $container->query(Backend::class); - - $backend->onTouchCalendarObject( - Event::SUBJECT_OBJECT_ADD, - $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('OCP\Federation\TrustedServerEvent::remove', function (GenericEvent $event) { @@ -379,4 +358,4 @@ class Application extends App implements IBootstrap { $logger->logException($ex); } } -} \ No newline at end of file +} diff --git a/apps/dav/lib/CalDAV/CalDavBackend.php b/apps/dav/lib/CalDAV/CalDavBackend.php index 058d4422d63..99504c4b5f1 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); diff --git a/apps/dav/lib/Listener/ActivityUpdaterListener.php b/apps/dav/lib/Listener/ActivityUpdaterListener.php index 962fa239af1..8ff65170e3f 100644 --- a/apps/dav/lib/Listener/ActivityUpdaterListener.php +++ b/apps/dav/lib/Listener/ActivityUpdaterListener.php @@ -27,6 +27,7 @@ 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; @@ -66,6 +67,24 @@ class ActivityUpdaterListener implements IEventListener { '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( diff --git a/apps/dav/lib/Listener/CalendarObjectReminderUpdaterListener.php b/apps/dav/lib/Listener/CalendarObjectReminderUpdaterListener.php index 8261b68af45..4c201a19c3a 100644 --- a/apps/dav/lib/Listener/CalendarObjectReminderUpdaterListener.php +++ b/apps/dav/lib/Listener/CalendarObjectReminderUpdaterListener.php @@ -28,6 +28,7 @@ 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; @@ -71,6 +72,22 @@ class CalendarObjectReminderUpdaterListener implements IEventListener { 'exception' => $e, ]); } + } elseif ($event instanceof CalendarObjectCreatedEvent) { + try { + $this->reminderService->onTouchCalendarObject( + '\OCA\DAV\CalDAV\CalDavBackend::createCalendarObject', + $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->onTouchCalendarObject( 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 96ae4312fda..097fbd79fe3 100644 --- a/apps/dav/tests/unit/CalDAV/CalDavBackendTest.php +++ b/apps/dav/tests/unit/CalDAV/CalDavBackendTest.php @@ -37,6 +37,7 @@ 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; @@ -187,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 */ @@ -233,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 @@ -378,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 -- cgit v1.2.3 From f5462650f1480bf23a58285e0e4476957a0720db Mon Sep 17 00:00:00 2001 From: Christoph Wurst Date: Fri, 7 May 2021 11:43:31 +0200 Subject: Clean up reminder actions and call methods directly Signed-off-by: Christoph Wurst --- .../BuildReminderIndexBackgroundJob.php | 2 +- apps/dav/lib/CalDAV/Reminder/ReminderService.php | 38 +++++++--------------- .../CalendarObjectReminderUpdaterListener.php | 9 ++--- .../unit/CalDAV/Reminder/ReminderServiceTest.php | 18 ++++------ 4 files changed, 21 insertions(+), 46 deletions(-) (limited to 'apps/dav/lib/CalDAV') 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/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/CalendarObjectReminderUpdaterListener.php b/apps/dav/lib/Listener/CalendarObjectReminderUpdaterListener.php index 4c201a19c3a..b976ef3ad9d 100644 --- a/apps/dav/lib/Listener/CalendarObjectReminderUpdaterListener.php +++ b/apps/dav/lib/Listener/CalendarObjectReminderUpdaterListener.php @@ -74,8 +74,7 @@ class CalendarObjectReminderUpdaterListener implements IEventListener { } } elseif ($event instanceof CalendarObjectCreatedEvent) { try { - $this->reminderService->onTouchCalendarObject( - '\OCA\DAV\CalDAV\CalDavBackend::createCalendarObject', + $this->reminderService->onCalendarObjectCreate( $event->getObjectData() ); @@ -90,8 +89,7 @@ class CalendarObjectReminderUpdaterListener implements IEventListener { } } elseif ($event instanceof CalendarObjectUpdatedEvent) { try { - $this->reminderService->onTouchCalendarObject( - '\OCA\DAV\CalDAV\CalDavBackend::updateCalendarObject', + $this->reminderService->onCalendarObjectEdit( $event->getObjectData() ); @@ -106,8 +104,7 @@ class CalendarObjectReminderUpdaterListener implements IEventListener { } } elseif ($event instanceof CalendarObjectDeletedEvent) { try { - $this->reminderService->onTouchCalendarObject( - '\OCA\DAV\CalDAV\CalDavBackend::deleteCalendarObject', + $this->reminderService->onCalendarObjectDelete( $event->getObjectData() ); 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 { -- cgit v1.2.3