diff --git a/apps/dav/lib/SystemTag/SystemTagsInUseCollection.php b/apps/dav/lib/SystemTag/SystemTagsInUseCollection.php index 938b14e1f651e..94a86352a9612 100644 --- a/apps/dav/lib/SystemTag/SystemTagsInUseCollection.php +++ b/apps/dav/lib/SystemTag/SystemTagsInUseCollection.php @@ -31,21 +31,34 @@ use OCP\IUserSession; use OCP\SystemTag\ISystemTagManager; use Sabre\DAV\Exception\Forbidden; +use Sabre\DAV\Exception\NotFound; class SystemTagsInUseCollection extends \Sabre\DAV\SimpleCollection { protected IUserSession $userSession; protected IRootFolder $rootFolder; + protected string $mediaType; - public function __construct(IUserSession $userSession, IRootFolder $rootFolder) { + public function __construct(IUserSession $userSession, IRootFolder $rootFolder, string $mediaType = '') { $this->userSession = $userSession; $this->rootFolder = $rootFolder; + $this->mediaType = $mediaType; $this->name = 'systemtags-current'; + if ($this->mediaType != '') { + $this->name .= '/' . $this->mediaType; + } } public function setName($name): void { throw new Forbidden('Permission denied to rename this collection'); } + public function getChild($name) { + if ($this->mediaType !== '') { + throw new NotFound('Invalid media type'); + } + return new self($this->userSession, $this->rootFolder, $name); + } + public function getChildren() { $user = $this->userSession->getUser(); if ($user === null) { @@ -53,7 +66,7 @@ public function getChildren() { } $userFolder = $this->rootFolder->getUserFolder($user->getUID()); - $result = $userFolder->getSystemTags('image'); + $result = $userFolder->getSystemTags($this->mediaType); $children = []; foreach ($result as $tagData) { $tag = new SystemTag((string)$tagData['id'], $tagData['name'], (bool)$tagData['visibility'], (bool)$tagData['editable']); diff --git a/lib/private/Files/Cache/QuerySearchHelper.php b/lib/private/Files/Cache/QuerySearchHelper.php index 679e937bbdec4..4e115fb64c944 100644 --- a/lib/private/Files/Cache/QuerySearchHelper.php +++ b/lib/private/Files/Cache/QuerySearchHelper.php @@ -98,6 +98,10 @@ protected function applySearchConstraints(CacheQueryBuilder $query, ISearchQuery } } + + /** + * @return array + */ public function findUsedTagsInCaches(ISearchQuery $searchQuery, array $caches): array { $query = $this->getQueryBuilder(); $query->selectTagUsage(); diff --git a/lib/private/Files/Node/Folder.php b/lib/private/Files/Node/Folder.php index bb4b254ceacbb..0d0c1964d6d04 100644 --- a/lib/private/Files/Node/Folder.php +++ b/lib/private/Files/Node/Folder.php @@ -343,10 +343,17 @@ public function searchBySystemTag(string $tag, string $userId, int $limit = 0, i } /** - * @return Node[] + * + * @return array */ public function getSystemTags(string $mediaType, int $limit = 0, int $offset = 0): array { - $query = $this->queryFromOperator(new SearchComparison(ISearchComparison::COMPARE_LIKE, 'mimetype', $mediaType . '/%'), null, $limit, $offset); + // Currently query has to have exactly one search condition. If no media type is provided, + // we fall back to the presence of a systemtag. + if (empty($mediaType)) { + $query = $this->queryFromOperator(new SearchComparison(ISearchComparison::COMPARE_LIKE, 'systemtag', '%'), null, $limit, $offset); + } else { + $query = $this->queryFromOperator(new SearchComparison(ISearchComparison::COMPARE_LIKE, 'mimetype', $mediaType . '/%'), null, $limit, $offset); + } [$caches, ] = $this->getCachesAndMountpointsForSearch(); /** @var QuerySearchHelper $searchHelper */ $searchHelper = \OCP\Server::get(QuerySearchHelper::class);