From 3ef6a099a3d3a3a9baaa48188d316c8295067974 Mon Sep 17 00:00:00 2001 From: Christoph Wurst Date: Wed, 3 Nov 2021 12:19:47 +0100 Subject: [PATCH] Add IManager::getCalendarsForPrincipal API The Calendar app needs to access calendars of a given principal in the back-end. The new calendar providers were not accessible for apps before this patch. Now they can access the ICalendar objects on demand. Signed-off-by: Christoph Wurst --- lib/private/Calendar/Manager.php | 17 ++++++++++++----- lib/public/Calendar/ICalendarProvider.php | 4 ++-- lib/public/Calendar/IManager.php | 11 ++++++++++- 3 files changed, 24 insertions(+), 8 deletions(-) diff --git a/lib/private/Calendar/Manager.php b/lib/private/Calendar/Manager.php index 3fa4b55d1eaac..16e142264aa48 100644 --- a/lib/private/Calendar/Manager.php +++ b/lib/private/Calendar/Manager.php @@ -167,15 +167,14 @@ private function loadCalendars() { $this->calendarLoaders = []; } - public function searchForPrincipal(ICalendarQuery $query): array { + public function getCalendarsForPrincipal(string $principalUri, array $calendarUris = []): array { $context = $this->coordinator->getRegistrationContext(); if ($context === null) { return []; } - /** @var CalendarQuery $query */ - $calendars = array_merge( - ...array_map(function ($registration) use ($query) { + return array_merge( + ...array_map(function ($registration) use ($principalUri, $calendarUris) { try { /** @var ICalendarProvider $provider */ $provider = $this->container->get($registration->getService()); @@ -186,9 +185,17 @@ public function searchForPrincipal(ICalendarQuery $query): array { return []; } - return $provider->getCalendars($query->getPrincipalUri(), $query->getCalendarUris()); + return $provider->getCalendars($principalUri, $calendarUris); }, $context->getCalendarProviders()) ); + } + + public function searchForPrincipal(ICalendarQuery $query): array { + /** @var CalendarQuery $query */ + $calendars = $this->getCalendarsForPrincipal( + $query->getPrincipalUri(), + $query->getCalendarUris(), + ); $results = []; /** @var ICalendar $calendar */ diff --git a/lib/public/Calendar/ICalendarProvider.php b/lib/public/Calendar/ICalendarProvider.php index d135910b08c87..14ef644e5805e 100644 --- a/lib/public/Calendar/ICalendarProvider.php +++ b/lib/public/Calendar/ICalendarProvider.php @@ -36,8 +36,8 @@ interface ICalendarProvider { /** - * @param string $principalUri - * @param string[] $calendarUris + * @param string $principalUri URI of the principal + * @param string[] $calendarUris optionally specify which calendars to load, or all if this array is empty * @return ICalendar[] * @since 23.0.0 */ diff --git a/lib/public/Calendar/IManager.php b/lib/public/Calendar/IManager.php index eb4113bba9966..7f0eec8091031 100644 --- a/lib/public/Calendar/IManager.php +++ b/lib/public/Calendar/IManager.php @@ -118,7 +118,7 @@ public function register(\Closure $callable); /** * @return ICalendar[] * @since 13.0.0 - * @deprecated 23.0.0 + * @deprecated 23.0.0 use \OCP\Calendar\IManager::getCalendarsForPrincipal */ public function getCalendars(); @@ -131,6 +131,15 @@ public function getCalendars(); */ public function clear(); + /** + * @param string $principalUri URI of the principal + * @param string[] $calendarUris optionally specify which calendars to load, or all if this array is empty + * + * @return ICalendar[] + * @since 23.0.0 + */ + public function getCalendarsForPrincipal(string $principalUri, array $calendarUris = []): array; + /** * Query a principals calendar(s) *