Skip to content

Commit

Permalink
Merge pull request #18679 from nextcloud/calDavSearch
Browse files Browse the repository at this point in the history
fix OCA\DAV\CalDAV\CalDavBackend search $options
  • Loading branch information
rullzer authored Mar 22, 2020
2 parents 6675f9b + 42dde6d commit 9956922
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
11 changes: 6 additions & 5 deletions apps/dav/lib/CalDAV/CalDavBackend.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@

namespace OCA\DAV\CalDAV;

use DateTime;
use OCA\DAV\Connector\Sabre\Principal;
use OCA\DAV\DAV\Sharing\Backend;
use OCA\DAV\DAV\Sharing\IShareable;
Expand Down Expand Up @@ -1551,14 +1552,14 @@ public function search(array $calendarInfo, $pattern, array $searchProperties,
->from('calendarobjects', 'c');

if (isset($options['timerange'])) {
if (isset($options['timerange']['start'])) {
if (isset($options['timerange']['start']) && $options['timerange']['start'] instanceof DateTime) {
$outerQuery->andWhere($outerQuery->expr()->gt('lastoccurence',
$outerQuery->createNamedParameter($options['timerange']['start']->getTimeStamp)));
$outerQuery->createNamedParameter($options['timerange']['start']->getTimeStamp())));

}
if (isset($options['timerange']['end'])) {
if (isset($options['timerange']['end']) && $options['timerange']['end'] instanceof DateTime) {
$outerQuery->andWhere($outerQuery->expr()->lt('firstoccurence',
$outerQuery->createNamedParameter($options['timerange']['end']->getTimeStamp)));
$outerQuery->createNamedParameter($options['timerange']['end']->getTimeStamp())));
}
}

Expand Down Expand Up @@ -2258,7 +2259,7 @@ public function getDenormalizedData($calendarData) {
}
} else {
$it = new EventIterator($vObject, (string)$component->UID);
$maxDate = new \DateTime(self::MAX_DATE);
$maxDate = new DateTime(self::MAX_DATE);
if ($it->isInfinite()) {
$lastOccurrence = $maxDate->getTimestamp();
} else {
Expand Down
9 changes: 5 additions & 4 deletions apps/dav/tests/unit/CalDAV/CalDavBackendTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -807,7 +807,7 @@ public function testCalendarSearch() {
/**
* @dataProvider searchDataProvider
*/
public function testSearch($isShared, $count) {
public function testSearch(bool $isShared, array $searchOptions, int $count) {
$calendarId = $this->createTestCalendar();

$uris = [];
Expand Down Expand Up @@ -901,15 +901,16 @@ public function testSearch($isShared, $count) {
];

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

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

public function searchDataProvider() {
return [
[false, 4],
[true, 2],
[false, [], 4],
[true, ['timerange' => ['start' => new DateTime('2013-09-12 13:00:00'), 'end' => new DateTime('2013-09-12 14:00:00')]], 2],
[true, ['timerange' => ['start' => new DateTime('2013-09-12 15:00:00'), 'end' => new DateTime('2013-09-12 16:00:00')]], 0],
];
}

Expand Down

0 comments on commit 9956922

Please sign in to comment.