Skip to content

Commit 69960c8

Browse files
authored
Merge pull request #20102 from nextcloud/backport/18679/stable18
[stable18] fix OCA\DAV\CalDAV\CalDavBackend search $options
2 parents 34fc462 + 8d7411d commit 69960c8

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
lines changed

apps/dav/lib/CalDAV/CalDavBackend.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333

3434
namespace OCA\DAV\CalDAV;
3535

36+
use DateTime;
3637
use OCA\DAV\Connector\Sabre\Principal;
3738
use OCA\DAV\DAV\Sharing\Backend;
3839
use OCA\DAV\DAV\Sharing\IShareable;
@@ -1551,14 +1552,14 @@ public function search(array $calendarInfo, $pattern, array $searchProperties,
15511552
->from('calendarobjects', 'c');
15521553

15531554
if (isset($options['timerange'])) {
1554-
if (isset($options['timerange']['start'])) {
1555+
if (isset($options['timerange']['start']) && $options['timerange']['start'] instanceof DateTime) {
15551556
$outerQuery->andWhere($outerQuery->expr()->gt('lastoccurence',
1556-
$outerQuery->createNamedParameter($options['timerange']['start']->getTimeStamp)));
1557+
$outerQuery->createNamedParameter($options['timerange']['start']->getTimeStamp())));
15571558

15581559
}
1559-
if (isset($options['timerange']['end'])) {
1560+
if (isset($options['timerange']['end']) && $options['timerange']['end'] instanceof DateTime) {
15601561
$outerQuery->andWhere($outerQuery->expr()->lt('firstoccurence',
1561-
$outerQuery->createNamedParameter($options['timerange']['end']->getTimeStamp)));
1562+
$outerQuery->createNamedParameter($options['timerange']['end']->getTimeStamp())));
15621563
}
15631564
}
15641565

@@ -2258,7 +2259,7 @@ public function getDenormalizedData($calendarData) {
22582259
}
22592260
} else {
22602261
$it = new EventIterator($vObject, (string)$component->UID);
2261-
$maxDate = new \DateTime(self::MAX_DATE);
2262+
$maxDate = new DateTime(self::MAX_DATE);
22622263
if ($it->isInfinite()) {
22632264
$lastOccurrence = $maxDate->getTimestamp();
22642265
} else {

apps/dav/tests/unit/CalDAV/CalDavBackendTest.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -807,7 +807,7 @@ public function testCalendarSearch() {
807807
/**
808808
* @dataProvider searchDataProvider
809809
*/
810-
public function testSearch($isShared, $count) {
810+
public function testSearch(bool $isShared, array $searchOptions, int $count) {
811811
$calendarId = $this->createTestCalendar();
812812

813813
$uris = [];
@@ -901,15 +901,16 @@ public function testSearch($isShared, $count) {
901901
];
902902

903903
$result = $this->backend->search($calendarInfo, 'Test',
904-
['SUMMARY', 'LOCATION', 'ATTENDEE'], [], null, null);
904+
['SUMMARY', 'LOCATION', 'ATTENDEE'], $searchOptions, null, null);
905905

906906
$this->assertCount($count, $result);
907907
}
908908

909909
public function searchDataProvider() {
910910
return [
911-
[false, 4],
912-
[true, 2],
911+
[false, [], 4],
912+
[true, ['timerange' => ['start' => new DateTime('2013-09-12 13:00:00'), 'end' => new DateTime('2013-09-12 14:00:00')]], 2],
913+
[true, ['timerange' => ['start' => new DateTime('2013-09-12 15:00:00'), 'end' => new DateTime('2013-09-12 16:00:00')]], 0],
913914
];
914915
}
915916

0 commit comments

Comments
 (0)