Skip to content

Commit

Permalink
feat(caldav): Allow advanced search for events/tasks
Browse files Browse the repository at this point in the history
Signed-off-by: Benjamin Gaussorgues <benjamin.gaussorgues@nextcloud.com>
  • Loading branch information
Altahrim committed Sep 28, 2023
1 parent d1447ef commit 01ff73f
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
8 changes: 7 additions & 1 deletion apps/dav/lib/CalDAV/CalDavBackend.php
Original file line number Diff line number Diff line change
Expand Up @@ -2155,6 +2155,12 @@ public function searchPrincipalUri(string $principalUri,
if (isset($options['offset'])) {
$calendarObjectIdQuery->setFirstResult($options['offset']);
}
if (isset($options['t_since'])) {
$calendarObjectIdQuery->andWhere($calendarObjectIdQuery->expr()->lte('co.lastoccurence', $calendarObjectIdQuery->createNamedParameter($options['t_start']->value->getTimestamp())));
}
if (isset($options['t_until'])) {
$calendarObjectIdQuery->andWhere($calendarObjectIdQuery->expr()->gte('co.firstoccurence', $calendarObjectIdQuery->createNamedParameter($options['t_end']->value->getTimestamp())));
}

$result = $calendarObjectIdQuery->executeQuery();
$matches = $result->fetchAll();
Expand Down Expand Up @@ -3183,7 +3189,7 @@ public function pruneOutdatedSyncTokens(int $keep = 10_000): int {
$maxId = (int) $result->fetchOne();
$result->closeCursor();
if (!$maxId || $maxId < $keep) {
return 0;
return 0;
}

$query = $this->db->getQueryBuilder();
Expand Down
5 changes: 3 additions & 2 deletions apps/dav/lib/Search/EventsSearchProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
* @package OCA\DAV\Search
*/
class EventsSearchProvider extends ACalendarSearchProvider {

/**
* @var string[]
*/
Expand Down Expand Up @@ -107,13 +106,15 @@ public function search(IUser $user,

$searchResults = $this->backend->searchPrincipalUri(
$principalUri,
$query->getTerm(),
$query->getFilter('term', ''),

Check failure on line 109 in apps/dav/lib/Search/EventsSearchProvider.php

View workflow job for this annotation

GitHub Actions / static-code-analysis

InvalidArgument

apps/dav/lib/Search/EventsSearchProvider.php:109:4: InvalidArgument: Argument 2 of OCA\DAV\CalDAV\CalDavBackend::searchPrincipalUri expects string, but OC\Search\Filter|null provided (see https://psalm.dev/004)

Check failure on line 109 in apps/dav/lib/Search/EventsSearchProvider.php

View workflow job for this annotation

GitHub Actions / static-code-analysis

TooManyArguments

apps/dav/lib/Search/EventsSearchProvider.php:109:12: TooManyArguments: Too many arguments for method OCP\Search\ISearchQuery::getfilter - saw 2 (see https://psalm.dev/026)

Check failure

Code scanning / Psalm

InvalidArgument Error

Argument 2 of OCA\DAV\CalDAV\CalDavBackend::searchPrincipalUri expects string, but OC\Search\Filter|null provided

Check failure

Code scanning / Psalm

TooManyArguments Error

Too many arguments for method OCP\Search\ISearchQuery::getfilter - saw 2
[self::$componentType],
self::$searchProperties,
self::$searchParameters,
[
'limit' => $query->getLimit(),
'offset' => $query->getCursor(),
'start' => $query->getFilter('start', null),

Check failure on line 116 in apps/dav/lib/Search/EventsSearchProvider.php

View workflow job for this annotation

GitHub Actions / static-code-analysis

TooManyArguments

apps/dav/lib/Search/EventsSearchProvider.php:116:24: TooManyArguments: Too many arguments for method OCP\Search\ISearchQuery::getfilter - saw 2 (see https://psalm.dev/026)

Check failure

Code scanning / Psalm

TooManyArguments Error

Too many arguments for method OCP\Search\ISearchQuery::getfilter - saw 2
'end' => $query->getFilter('end', null),

Check failure on line 117 in apps/dav/lib/Search/EventsSearchProvider.php

View workflow job for this annotation

GitHub Actions / static-code-analysis

TooManyArguments

apps/dav/lib/Search/EventsSearchProvider.php:117:22: TooManyArguments: Too many arguments for method OCP\Search\ISearchQuery::getfilter - saw 2 (see https://psalm.dev/026)

Check failure

Code scanning / Psalm

TooManyArguments Error

Too many arguments for method OCP\Search\ISearchQuery::getfilter - saw 2
]
);
$formattedResults = \array_map(function (array $eventRow) use ($calendarsById, $subscriptionsById):SearchResultEntry {
Expand Down
5 changes: 3 additions & 2 deletions apps/dav/lib/Search/TasksSearchProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
* @package OCA\DAV\Search
*/
class TasksSearchProvider extends ACalendarSearchProvider {

/**
* @var string[]
*/
Expand Down Expand Up @@ -100,13 +99,15 @@ public function search(IUser $user,

$searchResults = $this->backend->searchPrincipalUri(
$principalUri,
$query->getTerm(),
$query->getFilter('term', ''),

Check failure on line 102 in apps/dav/lib/Search/TasksSearchProvider.php

View workflow job for this annotation

GitHub Actions / static-code-analysis

InvalidArgument

apps/dav/lib/Search/TasksSearchProvider.php:102:4: InvalidArgument: Argument 2 of OCA\DAV\CalDAV\CalDavBackend::searchPrincipalUri expects string, but OC\Search\Filter|null provided (see https://psalm.dev/004)

Check failure on line 102 in apps/dav/lib/Search/TasksSearchProvider.php

View workflow job for this annotation

GitHub Actions / static-code-analysis

TooManyArguments

apps/dav/lib/Search/TasksSearchProvider.php:102:12: TooManyArguments: Too many arguments for method OCP\Search\ISearchQuery::getfilter - saw 2 (see https://psalm.dev/026)

Check failure

Code scanning / Psalm

InvalidArgument Error

Argument 2 of OCA\DAV\CalDAV\CalDavBackend::searchPrincipalUri expects string, but OC\Search\Filter|null provided

Check failure

Code scanning / Psalm

TooManyArguments Error

Too many arguments for method OCP\Search\ISearchQuery::getfilter - saw 2
[self::$componentType],
self::$searchProperties,
self::$searchParameters,
[
'limit' => $query->getLimit(),
'offset' => $query->getCursor(),
'start' => $query->getFilter('start'),
'end' => $query->getFilter('end'),
]
);
$formattedResults = \array_map(function (array $taskRow) use ($calendarsById, $subscriptionsById):SearchResultEntry {
Expand Down

0 comments on commit 01ff73f

Please sign in to comment.