Remove the \OCA\DAV\CalDAV\CalDavBackend::deleteCalendarObject event

Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
This commit is contained in:
Christoph Wurst 2021-05-07 10:26:49 +02:00
parent df685b4b59
commit d512a5629e
No known key found for this signature in database
GPG Key ID: CC42AC2A7F0E56D8
7 changed files with 102 additions and 73 deletions

View File

@ -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',

View File

@ -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',

View File

@ -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) {

View File

@ -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);

View File

@ -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,
]);
}
}
}
}

View File

@ -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,
]);
}
}
}
}

View File

@ -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);