Merge pull request #26915 from nextcloud/chore/dav-calendar-untyped-events
Drop even more untyped events from the dav code
This commit is contained in:
commit
0ac4563ae4
|
@ -51,11 +51,13 @@ use OCA\DAV\CardDAV\CardDavBackend;
|
||||||
use OCA\DAV\CardDAV\ContactsManager;
|
use OCA\DAV\CardDAV\ContactsManager;
|
||||||
use OCA\DAV\CardDAV\PhotoCache;
|
use OCA\DAV\CardDAV\PhotoCache;
|
||||||
use OCA\DAV\CardDAV\SyncService;
|
use OCA\DAV\CardDAV\SyncService;
|
||||||
|
use OCA\DAV\Events\CalendarCreatedEvent;
|
||||||
use OCA\DAV\Events\CalendarDeletedEvent;
|
use OCA\DAV\Events\CalendarDeletedEvent;
|
||||||
use OCA\DAV\Events\CalendarObjectCreatedEvent;
|
use OCA\DAV\Events\CalendarObjectCreatedEvent;
|
||||||
use OCA\DAV\Events\CalendarObjectDeletedEvent;
|
use OCA\DAV\Events\CalendarObjectDeletedEvent;
|
||||||
use OCA\DAV\Events\CalendarObjectUpdatedEvent;
|
use OCA\DAV\Events\CalendarObjectUpdatedEvent;
|
||||||
use OCA\DAV\Events\CalendarShareUpdatedEvent;
|
use OCA\DAV\Events\CalendarShareUpdatedEvent;
|
||||||
|
use OCA\DAV\Events\CalendarUpdatedEvent;
|
||||||
use OCA\DAV\HookManager;
|
use OCA\DAV\HookManager;
|
||||||
use OCA\DAV\Listener\ActivityUpdaterListener;
|
use OCA\DAV\Listener\ActivityUpdaterListener;
|
||||||
use OCA\DAV\Listener\CalendarContactInteractionListener;
|
use OCA\DAV\Listener\CalendarContactInteractionListener;
|
||||||
|
@ -114,9 +116,11 @@ class Application extends App implements IBootstrap {
|
||||||
/**
|
/**
|
||||||
* Register event listeners
|
* Register event listeners
|
||||||
*/
|
*/
|
||||||
|
$context->registerEventListener(CalendarCreatedEvent::class, ActivityUpdaterListener::class);
|
||||||
$context->registerEventListener(CalendarDeletedEvent::class, ActivityUpdaterListener::class);
|
$context->registerEventListener(CalendarDeletedEvent::class, ActivityUpdaterListener::class);
|
||||||
$context->registerEventListener(CalendarDeletedEvent::class, CalendarObjectReminderUpdaterListener::class);
|
$context->registerEventListener(CalendarDeletedEvent::class, CalendarObjectReminderUpdaterListener::class);
|
||||||
$context->registerEventListener(CalendarDeletedEvent::class, CalendarDeletionDefaultUpdaterListener::class);
|
$context->registerEventListener(CalendarDeletedEvent::class, CalendarDeletionDefaultUpdaterListener::class);
|
||||||
|
$context->registerEventListener(CalendarUpdatedEvent::class, ActivityUpdaterListener::class);
|
||||||
$context->registerEventListener(CalendarObjectCreatedEvent::class, ActivityUpdaterListener::class);
|
$context->registerEventListener(CalendarObjectCreatedEvent::class, ActivityUpdaterListener::class);
|
||||||
$context->registerEventListener(CalendarObjectCreatedEvent::class, CalendarContactInteractionListener::class);
|
$context->registerEventListener(CalendarObjectCreatedEvent::class, CalendarContactInteractionListener::class);
|
||||||
$context->registerEventListener(CalendarObjectCreatedEvent::class, CalendarObjectReminderUpdaterListener::class);
|
$context->registerEventListener(CalendarObjectCreatedEvent::class, CalendarObjectReminderUpdaterListener::class);
|
||||||
|
@ -198,22 +202,6 @@ class Application extends App implements IBootstrap {
|
||||||
$syncService->updateUser($user);
|
$syncService->updateUser($user);
|
||||||
});
|
});
|
||||||
|
|
||||||
$dispatcher->addListener('\OCA\DAV\CalDAV\CalDavBackend::createCalendar', function (GenericEvent $event) use ($container) {
|
|
||||||
/** @var Backend $backend */
|
|
||||||
$backend = $container->query(Backend::class);
|
|
||||||
$backend->onCalendarAdd(
|
|
||||||
$event->getArgument('calendarData')
|
|
||||||
);
|
|
||||||
});
|
|
||||||
$dispatcher->addListener('\OCA\DAV\CalDAV\CalDavBackend::updateCalendar', function (GenericEvent $event) use ($container) {
|
|
||||||
/** @var Backend $backend */
|
|
||||||
$backend = $container->query(Backend::class);
|
|
||||||
$backend->onCalendarUpdate(
|
|
||||||
$event->getArgument('calendarData'),
|
|
||||||
$event->getArgument('shares'),
|
|
||||||
$event->getArgument('propertyMutations')
|
|
||||||
);
|
|
||||||
});
|
|
||||||
$dispatcher->addListener('\OCA\DAV\CalDAV\CalDavBackend::updateShares', function (GenericEvent $event) use ($container) {
|
$dispatcher->addListener('\OCA\DAV\CalDAV\CalDavBackend::updateShares', function (GenericEvent $event) use ($container) {
|
||||||
/** @var Backend $backend */
|
/** @var Backend $backend */
|
||||||
$backend = $container->query(Backend::class);
|
$backend = $container->query(Backend::class);
|
||||||
|
|
|
@ -810,12 +810,6 @@ class CalDavBackend extends AbstractBackend implements SyncSupport, Subscription
|
||||||
|
|
||||||
$calendarData = $this->getCalendarById($calendarId);
|
$calendarData = $this->getCalendarById($calendarId);
|
||||||
$this->dispatcher->dispatchTyped(new CalendarCreatedEvent((int)$calendarId, $calendarData));
|
$this->dispatcher->dispatchTyped(new CalendarCreatedEvent((int)$calendarId, $calendarData));
|
||||||
$this->legacyDispatcher->dispatch('\OCA\DAV\CalDAV\CalDavBackend::createCalendar', new GenericEvent(
|
|
||||||
'\OCA\DAV\CalDAV\CalDavBackend::createCalendar',
|
|
||||||
[
|
|
||||||
'calendarId' => $calendarId,
|
|
||||||
'calendarData' => $calendarData,
|
|
||||||
]));
|
|
||||||
|
|
||||||
return $calendarId;
|
return $calendarId;
|
||||||
}
|
}
|
||||||
|
@ -867,14 +861,6 @@ class CalDavBackend extends AbstractBackend implements SyncSupport, Subscription
|
||||||
$calendarData = $this->getCalendarById($calendarId);
|
$calendarData = $this->getCalendarById($calendarId);
|
||||||
$shares = $this->getShares($calendarId);
|
$shares = $this->getShares($calendarId);
|
||||||
$this->dispatcher->dispatchTyped(new CalendarUpdatedEvent((int)$calendarId, $calendarData, $shares, $mutations));
|
$this->dispatcher->dispatchTyped(new CalendarUpdatedEvent((int)$calendarId, $calendarData, $shares, $mutations));
|
||||||
$this->legacyDispatcher->dispatch('\OCA\DAV\CalDAV\CalDavBackend::updateCalendar', new GenericEvent(
|
|
||||||
'\OCA\DAV\CalDAV\CalDavBackend::updateCalendar',
|
|
||||||
[
|
|
||||||
'calendarId' => $calendarId,
|
|
||||||
'calendarData' => $calendarData,
|
|
||||||
'shares' => $shares,
|
|
||||||
'propertyMutations' => $mutations,
|
|
||||||
]));
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
|
|
|
@ -26,10 +26,12 @@ declare(strict_types=1);
|
||||||
namespace OCA\DAV\Listener;
|
namespace OCA\DAV\Listener;
|
||||||
|
|
||||||
use OCA\DAV\CalDAV\Activity\Backend as ActivityBackend;
|
use OCA\DAV\CalDAV\Activity\Backend as ActivityBackend;
|
||||||
|
use OCA\DAV\Events\CalendarCreatedEvent;
|
||||||
use OCA\DAV\Events\CalendarDeletedEvent;
|
use OCA\DAV\Events\CalendarDeletedEvent;
|
||||||
use OCA\DAV\Events\CalendarObjectCreatedEvent;
|
use OCA\DAV\Events\CalendarObjectCreatedEvent;
|
||||||
use OCA\DAV\Events\CalendarObjectDeletedEvent;
|
use OCA\DAV\Events\CalendarObjectDeletedEvent;
|
||||||
use OCA\DAV\Events\CalendarObjectUpdatedEvent;
|
use OCA\DAV\Events\CalendarObjectUpdatedEvent;
|
||||||
|
use OCA\DAV\Events\CalendarUpdatedEvent;
|
||||||
use OCP\EventDispatcher\Event;
|
use OCP\EventDispatcher\Event;
|
||||||
use OCP\EventDispatcher\IEventListener;
|
use OCP\EventDispatcher\IEventListener;
|
||||||
use Psr\Log\LoggerInterface;
|
use Psr\Log\LoggerInterface;
|
||||||
|
@ -51,7 +53,39 @@ class ActivityUpdaterListener implements IEventListener {
|
||||||
}
|
}
|
||||||
|
|
||||||
public function handle(Event $event): void {
|
public function handle(Event $event): void {
|
||||||
if ($event instanceof CalendarDeletedEvent) {
|
if ($event instanceof CalendarCreatedEvent) {
|
||||||
|
try {
|
||||||
|
$this->activityBackend->onCalendarAdd(
|
||||||
|
$event->getCalendarData()
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->logger->debug(
|
||||||
|
sprintf('Activity generated for new calendar %d', $event->getCalendarId())
|
||||||
|
);
|
||||||
|
} catch (Throwable $e) {
|
||||||
|
// Any error with activities shouldn't abort the calendar creation, so we just log it
|
||||||
|
$this->logger->error('Error generating activities for a new calendar: ' . $e->getMessage(), [
|
||||||
|
'exception' => $e,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
} elseif ($event instanceof CalendarUpdatedEvent) {
|
||||||
|
try {
|
||||||
|
$this->activityBackend->onCalendarUpdate(
|
||||||
|
$event->getCalendarData(),
|
||||||
|
$event->getShares(),
|
||||||
|
$event->getMutations()
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->logger->debug(
|
||||||
|
sprintf('Activity generated for changed calendar %d', $event->getCalendarId())
|
||||||
|
);
|
||||||
|
} catch (Throwable $e) {
|
||||||
|
// Any error with activities shouldn't abort the calendar update, so we just log it
|
||||||
|
$this->logger->error('Error generating activities for changed calendar: ' . $e->getMessage(), [
|
||||||
|
'exception' => $e,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
} elseif ($event instanceof CalendarDeletedEvent) {
|
||||||
try {
|
try {
|
||||||
$this->activityBackend->onCalendarDelete(
|
$this->activityBackend->onCalendarDelete(
|
||||||
$event->getCalendarData(),
|
$event->getCalendarData(),
|
||||||
|
|
|
@ -31,6 +31,7 @@ use OC\KnownUser\KnownUserService;
|
||||||
use OCA\DAV\CalDAV\CalDavBackend;
|
use OCA\DAV\CalDAV\CalDavBackend;
|
||||||
use OCA\DAV\CalDAV\Proxy\ProxyMapper;
|
use OCA\DAV\CalDAV\Proxy\ProxyMapper;
|
||||||
use OCA\DAV\Connector\Sabre\Principal;
|
use OCA\DAV\Connector\Sabre\Principal;
|
||||||
|
use OCA\DAV\Events\CalendarCreatedEvent;
|
||||||
use OCA\DAV\Events\CalendarDeletedEvent;
|
use OCA\DAV\Events\CalendarDeletedEvent;
|
||||||
use OCA\DAV\Events\CalendarObjectCreatedEvent;
|
use OCA\DAV\Events\CalendarObjectCreatedEvent;
|
||||||
use OCP\App\IAppManager;
|
use OCP\App\IAppManager;
|
||||||
|
@ -150,9 +151,11 @@ abstract class AbstractCalDavBackend extends TestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function createTestCalendar() {
|
protected function createTestCalendar() {
|
||||||
$this->legacyDispatcher->expects($this->at(0))
|
$this->dispatcher->expects(self::once())
|
||||||
->method('dispatch')
|
->method('dispatchTyped')
|
||||||
->with('\OCA\DAV\CalDAV\CalDavBackend::createCalendar');
|
->with(self::callback(function ($event) {
|
||||||
|
return $event instanceof CalendarCreatedEvent;
|
||||||
|
}));
|
||||||
|
|
||||||
$this->backend->createCalendar(self::UNIT_TEST_USER, 'Example', [
|
$this->backend->createCalendar(self::UNIT_TEST_USER, 'Example', [
|
||||||
'{http://apple.com/ns/ical/}calendar-color' => '#1C4587FF'
|
'{http://apple.com/ns/ical/}calendar-color' => '#1C4587FF'
|
||||||
|
|
|
@ -36,6 +36,7 @@ use DateTime;
|
||||||
use DateTimeZone;
|
use DateTimeZone;
|
||||||
use OCA\DAV\CalDAV\CalDavBackend;
|
use OCA\DAV\CalDAV\CalDavBackend;
|
||||||
use OCA\DAV\CalDAV\Calendar;
|
use OCA\DAV\CalDAV\Calendar;
|
||||||
|
use OCA\DAV\Events\CalendarCreatedEvent;
|
||||||
use OCA\DAV\Events\CalendarDeletedEvent;
|
use OCA\DAV\Events\CalendarDeletedEvent;
|
||||||
use OCA\DAV\Events\CalendarObjectCreatedEvent;
|
use OCA\DAV\Events\CalendarObjectCreatedEvent;
|
||||||
use OCA\DAV\Events\CalendarUpdatedEvent;
|
use OCA\DAV\Events\CalendarUpdatedEvent;
|
||||||
|
@ -62,9 +63,11 @@ class CalDavBackendTest extends AbstractCalDavBackend {
|
||||||
'{DAV:}displayname' => 'Unit test',
|
'{DAV:}displayname' => 'Unit test',
|
||||||
'{urn:ietf:params:xml:ns:caldav}calendar-description' => 'Calendar used for unit testing'
|
'{urn:ietf:params:xml:ns:caldav}calendar-description' => 'Calendar used for unit testing'
|
||||||
]);
|
]);
|
||||||
$this->legacyDispatcher->expects($this->at(0))
|
$this->dispatcher->expects(self::once())
|
||||||
->method('dispatch')
|
->method('dispatchTyped')
|
||||||
->with('\OCA\DAV\CalDAV\CalDavBackend::updateCalendar');
|
->with(self::callback(function ($event) {
|
||||||
|
return $event instanceof CalendarUpdatedEvent;
|
||||||
|
}));
|
||||||
$this->backend->updateCalendar($calendarId, $patch);
|
$this->backend->updateCalendar($calendarId, $patch);
|
||||||
$patch->commit();
|
$patch->commit();
|
||||||
$this->assertEquals(1, $this->backend->getCalendarsForUserCount(self::UNIT_TEST_USER));
|
$this->assertEquals(1, $this->backend->getCalendarsForUserCount(self::UNIT_TEST_USER));
|
||||||
|
@ -527,9 +530,11 @@ EOD;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testPublications() {
|
public function testPublications() {
|
||||||
$this->legacyDispatcher->expects($this->at(0))
|
$this->dispatcher->expects(self::once())
|
||||||
->method('dispatch')
|
->method('dispatchTyped')
|
||||||
->with('\OCA\DAV\CalDAV\CalDavBackend::createCalendar');
|
->with(self::callback(function ($event) {
|
||||||
|
return $event instanceof CalendarCreatedEvent;
|
||||||
|
}));
|
||||||
|
|
||||||
$this->backend->createCalendar(self::UNIT_TEST_USER, 'Example', []);
|
$this->backend->createCalendar(self::UNIT_TEST_USER, 'Example', []);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue