summaryrefslogtreecommitdiffstats
path: root/apps/dav
diff options
context:
space:
mode:
authorChristoph Wurst <christoph@winzerhof-wurst.at>2021-05-07 10:26:49 +0200
committerChristoph Wurst <christoph@winzerhof-wurst.at>2021-05-07 10:53:45 +0200
commitd512a5629ec01fecd87944836eb9b02eb11257b8 (patch)
treec874b8f099c9b5bf65056a5aa2de438ae8852957 /apps/dav
parentdf685b4b594a006e983c9cd41498d60ded254776 (diff)
downloadnextcloud-server-d512a5629ec01fecd87944836eb9b02eb11257b8.tar.gz
nextcloud-server-d512a5629ec01fecd87944836eb9b02eb11257b8.zip
Remove the \OCA\DAV\CalDAV\CalDavBackend::deleteCalendarObject event
Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
Diffstat (limited to 'apps/dav')
-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.php14
-rw-r--r--apps/dav/lib/CalDAV/CalDavBackend.php9
-rw-r--r--apps/dav/lib/Listener/ActivityUpdaterListener.php (renamed from apps/dav/lib/Listener/CalendarDeletionActivityUpdaterListener.php)55
-rw-r--r--apps/dav/lib/Listener/CalendarObjectReminderUpdaterListener.php (renamed from apps/dav/lib/Listener/CalendarDeletionReminderUpdaterListener.php)57
-rw-r--r--apps/dav/tests/unit/CalDAV/CalDavBackendTest.php32
7 files changed, 102 insertions, 73 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..8bedb287148 100644
--- a/apps/dav/lib/AppInfo/Application.php
+++ b/apps/dav/lib/AppInfo/Application.php
@@ -54,13 +54,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 +115,13 @@ 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, CalendarContactInteractionListener::class);
$context->registerEventListener(CalendarObjectUpdatedEvent::class, CalendarContactInteractionListener::class);
+ $context->registerEventListener(CalendarObjectDeletedEvent::class, ActivityUpdaterListener::class);
+ $context->registerEventListener(CalendarObjectDeletedEvent::class, CalendarObjectReminderUpdaterListener::class);
$context->registerEventListener(CalendarShareUpdatedEvent::class, CalendarContactInteractionListener::class);
$context->registerNotifierService(Notifier::class);
@@ -237,8 +240,6 @@ class Application extends App implements IBootstrap {
$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,
@@ -257,7 +258,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('\OCA\DAV\CalDAV\CalDavBackend::deleteCalendarObject', $listener);
$dispatcher->addListener('OCP\Federation\TrustedServerEvent::remove',
function (GenericEvent $event) {
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);
diff --git a/apps/dav/lib/Listener/CalendarDeletionActivityUpdaterListener.php b/apps/dav/lib/Listener/ActivityUpdaterListener.php
index 4139aba226e..9734a4fead8 100644
--- a/apps/dav/lib/Listener/CalendarDeletionActivityUpdaterListener.php
+++ b/apps/dav/lib/Listener/ActivityUpdaterListener.php
@@ -27,16 +27,14 @@ namespace OCA\DAV\Listener;
use OCA\DAV\CalDAV\Activity\Backend as ActivityBackend;
use OCA\DAV\Events\CalendarDeletedEvent;
+use OCA\DAV\Events\CalendarObjectDeletedEvent;
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 {
+class ActivityUpdaterListener implements IEventListener {
/** @var ActivityBackend */
private $activityBackend;
@@ -51,25 +49,40 @@ class CalendarDeletionActivityUpdaterListener implements IEventListener {
}
public function handle(Event $event): void {
- if (!($event instanceof CalendarDeletedEvent)) {
- // Not what we subscribed to
- return;
- }
+ if ($event instanceof CalendarDeletedEvent) {
+ try {
+ $this->activityBackend->onCalendarDelete(
+ $event->getCalendarData(),
+ $event->getShares()
+ );
- 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 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 %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,
- ]);
+ $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/CalendarDeletionReminderUpdaterListener.php b/apps/dav/lib/Listener/CalendarObjectReminderUpdaterListener.php
index 3beecc8ff05..63fe786cfa2 100644
--- a/apps/dav/lib/Listener/CalendarDeletionReminderUpdaterListener.php
+++ b/apps/dav/lib/Listener/CalendarObjectReminderUpdaterListener.php
@@ -26,49 +26,66 @@ declare(strict_types=1);
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\CalendarObjectDeletedEvent;
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 {
+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)) {
- // Not what we subscribed to
- return;
- }
+ if ($event instanceof CalendarDeletedEvent) {
+ try {
+ $this->reminderBackend->cleanRemindersForCalendar(
+ $event->getCalendarId()
+ );
- 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 CalendarObjectDeletedEvent) {
+ try {
+ $this->reminderService->onTouchCalendarObject(
+ '\OCA\DAV\CalDAV\CalDavBackend::deleteCalendarObject',
+ $event->getObjectData()
+ );
- $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,
- ]);
+ $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/CalDavBackendTest.php b/apps/dav/tests/unit/CalDAV/CalDavBackendTest.php
index 25966aa5c95..98e1b728f9f 100644
--- a/apps/dav/tests/unit/CalDAV/CalDavBackendTest.php
+++ b/apps/dav/tests/unit/CalDAV/CalDavBackendTest.php
@@ -278,9 +278,11 @@ EOD;
$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);
@@ -412,17 +414,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);