Skip to content

Commit 2e8cf44

Browse files
Carefully filter out non matching time ranges for CalDAV search
When we search for CalDAV objects in the DB we take the first and last occurence into account. For recurring events that is when they take place the very first time and the very last time. Searching in a more specific time range will still match this condition, because the recurring event starts before the end of the requested range but ends after the start of the requested range. Sabre has filters for this. If we apply them on all seach objects of a search with a time range, then only the recurring events actually taking place at the time of the requested time range will be returned. Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
1 parent 9cb90b3 commit 2e8cf44

File tree

1 file changed

+28
-1
lines changed

1 file changed

+28
-1
lines changed

apps/dav/lib/CalDAV/CalDavBackend.php

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1915,7 +1915,34 @@ public function search(array $calendarInfo, $pattern, array $searchProperties,
19151915
}
19161916

19171917
$result = $outerQuery->executeQuery();
1918-
$calendarObjects = $result->fetchAll();
1918+
$calendarObjects = array_filter($result->fetchAll(), function (array $row) use ($options) {
1919+
$start = $options['timerange']['start'] ?? null;
1920+
$end = $options['timerange']['end'] ?? null;
1921+
1922+
if ($start === null || !($start instanceof DateTimeInterface) || $end === null || !($end instanceof DateTimeInterface)) {
1923+
// No filter required
1924+
return true;
1925+
}
1926+
1927+
return $this->validateFilterForObject($row, [
1928+
'name' => 'VCALENDAR',
1929+
'comp-filters' => [
1930+
[
1931+
'name' => 'VEVENT',
1932+
'comp-filters' => [],
1933+
'prop-filters' => [],
1934+
'is-not-defined' => false,
1935+
'time-range' => [
1936+
'start' => $start,
1937+
'end' => $end,
1938+
],
1939+
],
1940+
],
1941+
'prop-filters' => [],
1942+
'is-not-defined' => false,
1943+
'time-range' => null,
1944+
]);
1945+
});
19191946
$result->closeCursor();
19201947

19211948
return array_map(function ($o) {

0 commit comments

Comments
 (0)