aboutsummaryrefslogtreecommitdiffstats
path: root/lib/private/SystemTag
diff options
context:
space:
mode:
authorArthur Schiwon <blizzz@arthur-schiwon.de>2023-05-05 21:28:09 +0200
committerArthur Schiwon <blizzz@arthur-schiwon.de>2023-05-16 12:59:04 +0200
commit1e5de8aff49363410851ecd5fd389464e531d621 (patch)
tree716ff28502218b4c0ea207cd2de3d8a70cab85ee /lib/private/SystemTag
parentf42cae2bdb55c18686c4fc58ff13db89845508f0 (diff)
downloadnextcloud-server-1e5de8aff49363410851ecd5fd389464e531d621.tar.gz
nextcloud-server-1e5de8aff49363410851ecd5fd389464e531d621.zip
refactor: remove SystemTag logic from Folder into QuerySearchHelper
- adds OC\SystemTag\SystemTagsInFilesDetector where the search logic is moved to Signed-off-by: Arthur Schiwon <blizzz@arthur-schiwon.de>
Diffstat (limited to 'lib/private/SystemTag')
-rw-r--r--lib/private/SystemTag/SystemTagsInFilesDetector.php68
1 files changed, 68 insertions, 0 deletions
diff --git a/lib/private/SystemTag/SystemTagsInFilesDetector.php b/lib/private/SystemTag/SystemTagsInFilesDetector.php
new file mode 100644
index 00000000000..0fcd7e051f6
--- /dev/null
+++ b/lib/private/SystemTag/SystemTagsInFilesDetector.php
@@ -0,0 +1,68 @@
+<?php
+
+declare(strict_types=1);
+
+/**
+ * @copyright Copyright (c) 2023 Arthur Schiwon <blizzz@arthur-schiwon.de>
+ *
+ * @author Arthur Schiwon <blizzz@arthur-schiwon.de>
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ *
+ */
+
+namespace OC\SystemTag;
+
+use OC\Files\Cache\QuerySearchHelper;
+use OC\Files\Node\Root;
+use OC\Files\Search\SearchComparison;
+use OC\Files\Search\SearchQuery;
+use OCP\Files\Folder;
+use OCP\Files\Search\ISearchComparison;
+
+class SystemTagsInFilesDetector {
+ public function __construct(protected QuerySearchHelper $searchHelper) {
+ }
+
+ public function detectAssignedSystemTagsIn(
+ Folder $folder,
+ string $filteredMediaType = '',
+ int $limit = 0,
+ int $offset = 0
+ ): array {
+ // Currently query has to have exactly one search condition. If no media type is provided,
+ // we fall back to the presence of a system tag.
+ if (empty($filteredMediaType)) {
+ $query = new SearchQuery(new SearchComparison(ISearchComparison::COMPARE_LIKE, 'systemtag', '%'), $limit, $offset, []);
+ } else {
+ $query = new SearchQuery(new SearchComparison(ISearchComparison::COMPARE_LIKE, 'mimetype', $filteredMediaType . '/%'), $limit, $offset, []);
+ }
+ [$caches, ] = $this->searchHelper->getCachesAndMountPointsForSearch(
+ $this->getRootFolder($folder),
+ $folder->getPath(),
+ );
+ return $this->searchHelper->findUsedTagsInCaches($query, $caches);
+ }
+
+ protected function getRootFolder(?Folder $folder): Root {
+ if ($folder instanceof Root) {
+ return $folder;
+ } elseif ($folder === null) {
+ throw new \LogicException('Could not climb up to root folder');
+ }
+ return $this->getRootFolder($folder->getParent());
+ }
+}