summaryrefslogtreecommitdiffstats
path: root/apps/dav
diff options
context:
space:
mode:
authorChristoph Wurst <christoph@winzerhof-wurst.at>2021-05-07 11:36:23 +0200
committerChristoph Wurst <christoph@winzerhof-wurst.at>2021-05-07 12:13:45 +0200
commit257613e6efd429dd1c6cde4abbcbb590d32408e8 (patch)
tree104b2ae9487bc1ae17e8f936078abfdb38f1bd8b /apps/dav
parentf808267949e5513188961ca5f6fc38d57f6c7fd1 (diff)
downloadnextcloud-server-257613e6efd429dd1c6cde4abbcbb590d32408e8.tar.gz
nextcloud-server-257613e6efd429dd1c6cde4abbcbb590d32408e8.zip
Remove the \OCA\DAV\CalDAV\CalDavBackend::createCalendarObject event
Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
Diffstat (limited to 'apps/dav')
-rw-r--r--apps/dav/lib/AppInfo/Application.php29
-rw-r--r--apps/dav/lib/CalDAV/CalDavBackend.php9
-rw-r--r--apps/dav/lib/Listener/ActivityUpdaterListener.php19
-rw-r--r--apps/dav/lib/Listener/CalendarObjectReminderUpdaterListener.php17
-rw-r--r--apps/dav/tests/unit/CalDAV/AbstractCalDavBackend.php9
-rw-r--r--apps/dav/tests/unit/CalDAV/CalDavBackendTest.php41
6 files changed, 72 insertions, 52 deletions
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