From 6ce61594d6be1ba80c7f61e09c88fcfa509cbcaf Mon Sep 17 00:00:00 2001 From: dartcafe Date: Sun, 5 Jan 2020 20:50:22 +0100 Subject: [PATCH 1/4] fix OCA\DAV\CalDAV\CalDavBackend search $options Signed-off-by: dartcafe --- apps/dav/lib/CalDAV/CalDavBackend.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/dav/lib/CalDAV/CalDavBackend.php b/apps/dav/lib/CalDAV/CalDavBackend.php index bb2a38fe232fe..2d27629c4f436 100644 --- a/apps/dav/lib/CalDAV/CalDavBackend.php +++ b/apps/dav/lib/CalDAV/CalDavBackend.php @@ -1551,12 +1551,12 @@ public function search(array $calendarInfo, $pattern, array $searchProperties, if (isset($options['timerange'])) { if (isset($options['timerange']['start'])) { $outerQuery->andWhere($outerQuery->expr()->gt('lastoccurence', - $outerQuery->createNamedParameter($options['timerange']['start']->getTimeStamp))); + $outerQuery->createNamedParameter($options['timerange']['start']->getTimeStamp()))); } if (isset($options['timerange']['end'])) { $outerQuery->andWhere($outerQuery->expr()->lt('firstoccurence', - $outerQuery->createNamedParameter($options['timerange']['end']->getTimeStamp))); + $outerQuery->createNamedParameter($options['timerange']['end']->getTimeStamp()))); } } From 3478ab86e49db8931acd00993e00b87a313b66f5 Mon Sep 17 00:00:00 2001 From: dartcafe Date: Sun, 5 Jan 2020 21:07:36 +0100 Subject: [PATCH 2/4] Added test testSearch Signed-off-by: dartcafe --- apps/dav/tests/unit/CalDAV/CalDavBackendTest.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/apps/dav/tests/unit/CalDAV/CalDavBackendTest.php b/apps/dav/tests/unit/CalDAV/CalDavBackendTest.php index 1b2169b6675b3..31c51521885be 100644 --- a/apps/dav/tests/unit/CalDAV/CalDavBackendTest.php +++ b/apps/dav/tests/unit/CalDAV/CalDavBackendTest.php @@ -899,8 +899,10 @@ public function testSearch($isShared, $count) { '{http://owncloud.org/ns}owner-principal' => $isShared ? 'user2' : 'user1', ]; + $searchOptions = ['timerange' => ['start' => new DateTime('2013-09-12 13:00:00'), 'end' => new DateTime('2013-09-12 14:00:00')]]; + $result = $this->backend->search($calendarInfo, 'Test', - ['SUMMARY', 'LOCATION', 'ATTENDEE'], [], null, null); + ['SUMMARY', 'LOCATION', 'ATTENDEE'], $searchOptions, null, null); $this->assertCount($count, $result); } From 95761684f6807f1483c34675bac1346dc5e7380f Mon Sep 17 00:00:00 2001 From: Thomas Citharel Date: Sun, 5 Jan 2020 21:27:41 +0100 Subject: [PATCH 3/4] Add extra test case to exclude by timerange Signed-off-by: Thomas Citharel --- apps/dav/tests/unit/CalDAV/CalDavBackendTest.php | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/apps/dav/tests/unit/CalDAV/CalDavBackendTest.php b/apps/dav/tests/unit/CalDAV/CalDavBackendTest.php index 31c51521885be..212b09f31fb49 100644 --- a/apps/dav/tests/unit/CalDAV/CalDavBackendTest.php +++ b/apps/dav/tests/unit/CalDAV/CalDavBackendTest.php @@ -806,7 +806,7 @@ public function testCalendarSearch() { /** * @dataProvider searchDataProvider */ - public function testSearch($isShared, $count) { + public function testSearch(bool $isShared, array $searchOptions, int $count) { $calendarId = $this->createTestCalendar(); $uris = []; @@ -899,8 +899,6 @@ public function testSearch($isShared, $count) { '{http://owncloud.org/ns}owner-principal' => $isShared ? 'user2' : 'user1', ]; - $searchOptions = ['timerange' => ['start' => new DateTime('2013-09-12 13:00:00'), 'end' => new DateTime('2013-09-12 14:00:00')]]; - $result = $this->backend->search($calendarInfo, 'Test', ['SUMMARY', 'LOCATION', 'ATTENDEE'], $searchOptions, null, null); @@ -909,8 +907,9 @@ public function testSearch($isShared, $count) { 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], ]; } From 9a0cf46ad0e6a42c2f2a441429f46c2a24e988cf Mon Sep 17 00:00:00 2001 From: Thomas Citharel Date: Sun, 5 Jan 2020 21:32:33 +0100 Subject: [PATCH 4/4] Add check that DateTime parameters are of correct type Signed-off-by: Thomas Citharel --- apps/dav/lib/CalDAV/CalDavBackend.php | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/apps/dav/lib/CalDAV/CalDavBackend.php b/apps/dav/lib/CalDAV/CalDavBackend.php index 2d27629c4f436..73d7fc1c79a7a 100644 --- a/apps/dav/lib/CalDAV/CalDavBackend.php +++ b/apps/dav/lib/CalDAV/CalDavBackend.php @@ -33,6 +33,7 @@ namespace OCA\DAV\CalDAV; +use DateTime; use OCA\DAV\DAV\Sharing\IShareable; use OCP\DB\QueryBuilder\IQueryBuilder; use OCA\DAV\Connector\Sabre\Principal; @@ -445,7 +446,7 @@ private function getUserDisplayName($uid) { return $this->userDisplayNames[$uid]; } - + /** * @return array */ @@ -1549,12 +1550,12 @@ 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()))); } - 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()))); } @@ -2256,7 +2257,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 {