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

Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
This commit is contained in:
Christoph Wurst 2021-05-07 11:36:23 +02:00
parent f808267949
commit 257613e6ef
No known key found for this signature in database
GPG Key ID: CC42AC2A7F0E56D8
6 changed files with 72 additions and 52 deletions

View File

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

View File

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

View File

@ -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(

View File

@ -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(

View File

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

View File

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