mirror of
https://github.com/nextcloud/server.git
synced 2026-05-28 04:32:30 -04:00
fix(dav): expand recurrences when searching
Signed-off-by: Richard Steinmetz <richard@steinmetz.cloud>
This commit is contained in:
parent
89b9d49498
commit
a4a0a1fa2e
2 changed files with 81 additions and 1 deletions
|
|
@ -20,6 +20,7 @@
|
|||
* @author Thomas Citharel <nextcloud@tcit.fr>
|
||||
* @author Thomas Müller <thomas.mueller@tmit.eu>
|
||||
* @author Vinicius Cubas Brand <vinicius@eita.org.br>
|
||||
* @author Richard Steinmetz <richard@steinmetz.cloud>
|
||||
*
|
||||
* @license AGPL-3.0
|
||||
*
|
||||
|
|
@ -1951,8 +1952,18 @@ class CalDavBackend extends AbstractBackend implements SyncSupport, Subscription
|
|||
});
|
||||
$result->closeCursor();
|
||||
|
||||
return array_map(function ($o) {
|
||||
return array_map(function ($o) use ($options) {
|
||||
$calendarData = Reader::read($o['calendardata']);
|
||||
|
||||
// Expand recurrences if an explicit time range is requested
|
||||
if ($calendarData instanceof VCalendar
|
||||
&& isset($options['timerange']['start'], $options['timerange']['end'])) {
|
||||
$calendarData = $calendarData->expand(
|
||||
$options['timerange']['start'],
|
||||
$options['timerange']['end'],
|
||||
);
|
||||
}
|
||||
|
||||
$comps = $calendarData->getComponents();
|
||||
$objects = [];
|
||||
$timezones = [];
|
||||
|
|
|
|||
|
|
@ -32,7 +32,9 @@
|
|||
|
||||
namespace OCA\DAV\Tests\unit\CalDAV;
|
||||
|
||||
use DateInterval;
|
||||
use DateTime;
|
||||
use DateTimeImmutable;
|
||||
use DateTimeZone;
|
||||
use OCA\DAV\CalDAV\CalDavBackend;
|
||||
use OCA\DAV\CalDAV\Calendar;
|
||||
|
|
@ -1283,4 +1285,71 @@ EOD;
|
|||
$this->assertEquals($sharerPrivate, $sharerSearchResults[1]['calendardata']);
|
||||
$this->assertEquals($sharerConfidential, $sharerSearchResults[2]['calendardata']);
|
||||
}
|
||||
|
||||
public function testSearchAndExpandRecurrences() {
|
||||
$calendarId = $this->createTestCalendar();
|
||||
$calendarInfo = [
|
||||
'id' => $calendarId,
|
||||
'principaluri' => 'user1',
|
||||
'{http://owncloud.org/ns}owner-principal' => 'user1',
|
||||
];
|
||||
|
||||
$calData = <<<'EOD'
|
||||
BEGIN:VCALENDAR
|
||||
PRODID:-//IDN nextcloud.com//Calendar app 4.5.0-alpha.2//EN
|
||||
CALSCALE:GREGORIAN
|
||||
VERSION:2.0
|
||||
BEGIN:VEVENT
|
||||
CREATED:20230921T133401Z
|
||||
DTSTAMP:20230921T133448Z
|
||||
LAST-MODIFIED:20230921T133448Z
|
||||
SEQUENCE:2
|
||||
UID:7b7d5d12-683c-48ce-973a-b3e1cb0bae2a
|
||||
DTSTART;VALUE=DATE:20230912
|
||||
DTEND;VALUE=DATE:20230913
|
||||
STATUS:CONFIRMED
|
||||
SUMMARY:Daily Event
|
||||
RRULE:FREQ=DAILY
|
||||
END:VEVENT
|
||||
END:VCALENDAR
|
||||
EOD;
|
||||
$uri = static::getUniqueID('calobj');
|
||||
$this->backend->createCalendarObject($calendarId, $uri, $calData);
|
||||
|
||||
$start = new DateTimeImmutable('2023-09-20T00:00:00Z');
|
||||
$end = $start->add(new DateInterval('P14D'));
|
||||
|
||||
$results = $this->backend->search(
|
||||
$calendarInfo,
|
||||
'',
|
||||
[],
|
||||
[
|
||||
'timerange' => [
|
||||
'start' => $start,
|
||||
'end' => $end,
|
||||
]
|
||||
],
|
||||
null,
|
||||
null,
|
||||
);
|
||||
|
||||
$this->assertCount(1, $results);
|
||||
$this->assertCount(14, $results[0]['objects']);
|
||||
foreach ($results as $result) {
|
||||
foreach ($result['objects'] as $object) {
|
||||
$this->assertEquals($object['UID'][0], '7b7d5d12-683c-48ce-973a-b3e1cb0bae2a');
|
||||
$this->assertEquals($object['SUMMARY'][0], 'Daily Event');
|
||||
$this->assertGreaterThanOrEqual(
|
||||
$start->getTimestamp(),
|
||||
$object['DTSTART'][0]->getTimestamp(),
|
||||
'Recurrence starting before requested start',
|
||||
);
|
||||
$this->assertLessThanOrEqual(
|
||||
$end->getTimestamp(),
|
||||
$object['DTSTART'][0]->getTimestamp(),
|
||||
'Recurrence starting after requested end',
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue