diff --git a/apps/dav/lib/CalDAV/CalendarProvider.php b/apps/dav/lib/CalDAV/CalendarProvider.php index f81d5d37460..da8f6819bdf 100644 --- a/apps/dav/lib/CalDAV/CalendarProvider.php +++ b/apps/dav/lib/CalDAV/CalendarProvider.php @@ -37,7 +37,7 @@ class CalendarProvider implements ICalendarProvider { } $additionalProperties = $this->getAdditionalPropertiesForCalendars($calendarInfos); - + $iCalendars = []; foreach ($calendarInfos as $calendarInfo) { $user = str_replace('principals/users/', '', $calendarInfo['principaluri']); $path = 'calendars/' . $user . '/' . $calendarInfo['uri']; @@ -56,37 +56,35 @@ class CalendarProvider implements ICalendarProvider { /** * @param array{ - * principalUri: string, + * principaluri: string, * uri: string, * }[] $uris * @return array> */ private function getAdditionalPropertiesForCalendars(array $uris): array { - $users = []; + $calendars = []; foreach ($uris as $uri) { + /** @var string $user */ $user = str_replace('principals/users/', '', $uri['principaluri']); - if (!array_key_exists($user, $users)) { - $users[$user] = []; + if (!array_key_exists($user, $calendars)) { + $calendars[$user] = []; } - $users[$user][] = 'calendars/' . $user . '/' . $uri['uri']; + $calendars[$user][] = 'calendars/' . $user . '/' . $uri['uri']; } + $properties = $this->propertyMapper->findPropertiesByPaths($calendars); + $list = []; - foreach ($users as $user => $calendars) { - $properties = $this->propertyMapper->findPropertiesByPaths($user, $calendars); - - $list = []; - foreach ($properties as $property) { - if ($property instanceof Property) { - if (!isset($list[$property->getPropertypath()])) { - $list[$property->getPropertypath()] = []; - } - - $list[$property->getPropertypath()][$property->getPropertyname()] = match ($property->getPropertyname()) { - '{http://owncloud.org/ns}calendar-enabled' => (bool)$property->getPropertyvalue(), - default => $property->getPropertyvalue() - }; + foreach ($properties as $property) { + if ($property instanceof Property) { + if (!isset($list[$property->getPropertypath()])) { + $list[$property->getPropertypath()] = []; } + + $list[$property->getPropertypath()][$property->getPropertyname()] = match ($property->getPropertyname()) { + '{http://owncloud.org/ns}calendar-enabled' => (bool)$property->getPropertyvalue(), + default => $property->getPropertyvalue() + }; } } diff --git a/apps/dav/lib/Db/PropertyMapper.php b/apps/dav/lib/Db/PropertyMapper.php index e509c684347..86db8cfdbe6 100644 --- a/apps/dav/lib/Db/PropertyMapper.php +++ b/apps/dav/lib/Db/PropertyMapper.php @@ -40,19 +40,21 @@ class PropertyMapper extends QBMapper { } /** - * @param string $userId - * @param string[] $paths + * @param array $calendars * @return Property[] * @throws \OCP\DB\Exception */ - public function findPropertiesByPaths(string $userId, array $paths): array { + public function findPropertiesByPaths(array $calendars): array { $selectQb = $this->db->getQueryBuilder(); $selectQb->select('*') - ->from(self::TABLE_NAME) - ->where( - $selectQb->expr()->eq('userid', $selectQb->createNamedParameter($userId)), + ->from(self::TABLE_NAME); + + foreach ($calendars as $user => $paths) { + $selectQb->andWhere( + $selectQb->expr()->eq('userid', $selectQb->createNamedParameter($user)), $selectQb->expr()->in('propertypath', $selectQb->createNamedParameter($paths, IQueryBuilder::PARAM_STR_ARRAY)), ); + } return $this->findEntities($selectQb); } }