diff options
Diffstat (limited to 'lib/private/Search')
-rw-r--r-- | lib/private/Search/Filter/BooleanFilter.php | 23 | ||||
-rw-r--r-- | lib/private/Search/Filter/DateTimeFilter.php | 23 | ||||
-rw-r--r-- | lib/private/Search/Filter/FloatFilter.php | 23 | ||||
-rw-r--r-- | lib/private/Search/Filter/GroupFilter.php | 23 | ||||
-rw-r--r-- | lib/private/Search/Filter/IntegerFilter.php | 23 | ||||
-rw-r--r-- | lib/private/Search/Filter/StringFilter.php | 21 | ||||
-rw-r--r-- | lib/private/Search/Filter/StringsFilter.php | 21 | ||||
-rw-r--r-- | lib/private/Search/Filter/UserFilter.php | 23 | ||||
-rw-r--r-- | lib/private/Search/FilterCollection.php | 21 | ||||
-rw-r--r-- | lib/private/Search/FilterFactory.php | 25 | ||||
-rw-r--r-- | lib/private/Search/Provider/File.php | 107 | ||||
-rw-r--r-- | lib/private/Search/Result/Audio.php | 41 | ||||
-rw-r--r-- | lib/private/Search/Result/File.php | 151 | ||||
-rw-r--r-- | lib/private/Search/Result/Folder.php | 37 | ||||
-rw-r--r-- | lib/private/Search/Result/Image.php | 41 | ||||
-rw-r--r-- | lib/private/Search/SearchComposer.php | 68 | ||||
-rw-r--r-- | lib/private/Search/SearchQuery.php | 25 | ||||
-rw-r--r-- | lib/private/Search/UnsupportedFilter.php | 23 |
18 files changed, 74 insertions, 645 deletions
diff --git a/lib/private/Search/Filter/BooleanFilter.php b/lib/private/Search/Filter/BooleanFilter.php index a64bf17f31c..894dc13b657 100644 --- a/lib/private/Search/Filter/BooleanFilter.php +++ b/lib/private/Search/Filter/BooleanFilter.php @@ -3,25 +3,8 @@ declare(strict_types=1); /** - * @copyright 2023 Benjamin Gaussorgues <benjamin.gaussorgues@nextcloud.com> - * - * @author Benjamin Gaussorgues <benjamin.gaussorgues@nextcloud.com> - * - * @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 <http://www.gnu.org/licenses/>. - * + * SPDX-FileCopyrightText: 2023 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later */ namespace OC\Search\Filter; @@ -36,7 +19,7 @@ class BooleanFilter implements IFilter { $this->value = match ($value) { 'true', 'yes', 'y', '1' => true, 'false', 'no', 'n', '0', '' => false, - default => throw new InvalidArgumentException('Invalid boolean value '. $value), + default => throw new InvalidArgumentException('Invalid boolean value ' . $value), }; } diff --git a/lib/private/Search/Filter/DateTimeFilter.php b/lib/private/Search/Filter/DateTimeFilter.php index 79abf9ad542..48c1725a5e1 100644 --- a/lib/private/Search/Filter/DateTimeFilter.php +++ b/lib/private/Search/Filter/DateTimeFilter.php @@ -3,25 +3,8 @@ declare(strict_types=1); /** - * @copyright 2023 Benjamin Gaussorgues <benjamin.gaussorgues@nextcloud.com> - * - * @author Benjamin Gaussorgues <benjamin.gaussorgues@nextcloud.com> - * - * @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 <http://www.gnu.org/licenses/>. - * + * SPDX-FileCopyrightText: 2023 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later */ namespace OC\Search\Filter; @@ -34,7 +17,7 @@ class DateTimeFilter implements IFilter { public function __construct(string $value) { if (filter_var($value, FILTER_VALIDATE_INT)) { - $value = '@'.$value; + $value = '@' . $value; } $this->value = new DateTimeImmutable($value); diff --git a/lib/private/Search/Filter/FloatFilter.php b/lib/private/Search/Filter/FloatFilter.php index 3db19ded59b..f2384552943 100644 --- a/lib/private/Search/Filter/FloatFilter.php +++ b/lib/private/Search/Filter/FloatFilter.php @@ -3,25 +3,8 @@ declare(strict_types=1); /** - * @copyright 2023 Benjamin Gaussorgues <benjamin.gaussorgues@nextcloud.com> - * - * @author Benjamin Gaussorgues <benjamin.gaussorgues@nextcloud.com> - * - * @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 <http://www.gnu.org/licenses/>. - * + * SPDX-FileCopyrightText: 2023 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later */ namespace OC\Search\Filter; @@ -35,7 +18,7 @@ class FloatFilter implements IFilter { public function __construct(string $value) { $this->value = filter_var($value, FILTER_VALIDATE_FLOAT); if ($this->value === false) { - throw new InvalidArgumentException('Invalid float value '. $value); + throw new InvalidArgumentException('Invalid float value ' . $value); } } diff --git a/lib/private/Search/Filter/GroupFilter.php b/lib/private/Search/Filter/GroupFilter.php index f0b34a360ca..fe0b2ce42d8 100644 --- a/lib/private/Search/Filter/GroupFilter.php +++ b/lib/private/Search/Filter/GroupFilter.php @@ -3,25 +3,8 @@ declare(strict_types=1); /** - * @copyright 2023 Benjamin Gaussorgues <benjamin.gaussorgues@nextcloud.com> - * - * @author Benjamin Gaussorgues <benjamin.gaussorgues@nextcloud.com> - * - * @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 <http://www.gnu.org/licenses/>. - * + * SPDX-FileCopyrightText: 2023 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later */ namespace OC\Search\Filter; @@ -40,7 +23,7 @@ class GroupFilter implements IFilter { ) { $group = $groupManager->get($value); if ($group === null) { - throw new InvalidArgumentException('Group '.$value.' not found'); + throw new InvalidArgumentException('Group ' . $value . ' not found'); } $this->group = $group; } diff --git a/lib/private/Search/Filter/IntegerFilter.php b/lib/private/Search/Filter/IntegerFilter.php index b5b907b220e..028b7d0678f 100644 --- a/lib/private/Search/Filter/IntegerFilter.php +++ b/lib/private/Search/Filter/IntegerFilter.php @@ -3,25 +3,8 @@ declare(strict_types=1); /** - * @copyright 2023 Benjamin Gaussorgues <benjamin.gaussorgues@nextcloud.com> - * - * @author Benjamin Gaussorgues <benjamin.gaussorgues@nextcloud.com> - * - * @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 <http://www.gnu.org/licenses/>. - * + * SPDX-FileCopyrightText: 2023 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later */ namespace OC\Search\Filter; @@ -35,7 +18,7 @@ class IntegerFilter implements IFilter { public function __construct(string $value) { $this->value = filter_var($value, FILTER_VALIDATE_INT); if ($this->value === false) { - throw new InvalidArgumentException('Invalid integer value '. $value); + throw new InvalidArgumentException('Invalid integer value ' . $value); } } diff --git a/lib/private/Search/Filter/StringFilter.php b/lib/private/Search/Filter/StringFilter.php index 8f754d12051..6944a7803f3 100644 --- a/lib/private/Search/Filter/StringFilter.php +++ b/lib/private/Search/Filter/StringFilter.php @@ -3,25 +3,8 @@ declare(strict_types=1); /** - * @copyright 2023 Benjamin Gaussorgues <benjamin.gaussorgues@nextcloud.com> - * - * @author Benjamin Gaussorgues <benjamin.gaussorgues@nextcloud.com> - * - * @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 <http://www.gnu.org/licenses/>. - * + * SPDX-FileCopyrightText: 2023 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later */ namespace OC\Search\Filter; diff --git a/lib/private/Search/Filter/StringsFilter.php b/lib/private/Search/Filter/StringsFilter.php index 7a8d88768e8..8b8fabb5347 100644 --- a/lib/private/Search/Filter/StringsFilter.php +++ b/lib/private/Search/Filter/StringsFilter.php @@ -3,25 +3,8 @@ declare(strict_types=1); /** - * @copyright 2023 Benjamin Gaussorgues <benjamin.gaussorgues@nextcloud.com> - * - * @author Benjamin Gaussorgues <benjamin.gaussorgues@nextcloud.com> - * - * @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 <http://www.gnu.org/licenses/>. - * + * SPDX-FileCopyrightText: 2023 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later */ namespace OC\Search\Filter; diff --git a/lib/private/Search/Filter/UserFilter.php b/lib/private/Search/Filter/UserFilter.php index 963d5e123ac..4f2061a4ba6 100644 --- a/lib/private/Search/Filter/UserFilter.php +++ b/lib/private/Search/Filter/UserFilter.php @@ -3,25 +3,8 @@ declare(strict_types=1); /** - * @copyright 2023 Benjamin Gaussorgues <benjamin.gaussorgues@nextcloud.com> - * - * @author Benjamin Gaussorgues <benjamin.gaussorgues@nextcloud.com> - * - * @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 <http://www.gnu.org/licenses/>. - * + * SPDX-FileCopyrightText: 2023 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later */ namespace OC\Search\Filter; @@ -40,7 +23,7 @@ class UserFilter implements IFilter { ) { $user = $userManager->get($value); if ($user === null) { - throw new InvalidArgumentException('User '.$value.' not found'); + throw new InvalidArgumentException('User ' . $value . ' not found'); } $this->user = $user; } diff --git a/lib/private/Search/FilterCollection.php b/lib/private/Search/FilterCollection.php index 15d6695dcac..173c967245a 100644 --- a/lib/private/Search/FilterCollection.php +++ b/lib/private/Search/FilterCollection.php @@ -3,25 +3,8 @@ declare(strict_types=1); /** - * @copyright 2023 Benjamin Gaussorgues <benjamin.gaussorgues@nextcloud.com> - * - * @author Benjamin Gaussorgues <benjamin.gaussorgues@nextcloud.com> - * - * @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 <http://www.gnu.org/licenses/>. - * + * SPDX-FileCopyrightText: 2023 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later */ namespace OC\Search; diff --git a/lib/private/Search/FilterFactory.php b/lib/private/Search/FilterFactory.php index 3f4388f405c..07063c604f4 100644 --- a/lib/private/Search/FilterFactory.php +++ b/lib/private/Search/FilterFactory.php @@ -3,25 +3,8 @@ declare(strict_types=1); /** - * @copyright 2023 Benjamin Gaussorgues <benjamin.gaussorgues@nextcloud.com> - * - * @author Benjamin Gaussorgues <benjamin.gaussorgues@nextcloud.com> - * - * @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 <http://www.gnu.org/licenses/>. - * + * SPDX-FileCopyrightText: 2023 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later */ namespace OC\Search; @@ -44,8 +27,8 @@ final class FilterFactory { FilterDefinition::TYPE_NC_USER => new Filter\UserFilter($filter, \OC::$server->get(IUserManager::class)), FilterDefinition::TYPE_PERSON => self::getPerson($filter), FilterDefinition::TYPE_STRING => new Filter\StringFilter($filter), - FilterDefinition::TYPE_STRINGS => new Filter\StringsFilter(... (array) $filter), - default => throw new RuntimeException('Invalid filter type '. $type), + FilterDefinition::TYPE_STRINGS => new Filter\StringsFilter(... (array)$filter), + default => throw new RuntimeException('Invalid filter type ' . $type), }; } diff --git a/lib/private/Search/Provider/File.php b/lib/private/Search/Provider/File.php deleted file mode 100644 index 6522e9db5a0..00000000000 --- a/lib/private/Search/Provider/File.php +++ /dev/null @@ -1,107 +0,0 @@ -<?php -/** - * @copyright Copyright (c) 2016, ownCloud, Inc. - * - * @author Andrew Brown <andrew@casabrown.com> - * @author Bart Visscher <bartv@thisnet.nl> - * @author Christoph Wurst <christoph@winzerhof-wurst.at> - * @author Jakob Sack <mail@jakobsack.de> - * @author John Molakvoæ <skjnldsv@protonmail.com> - * @author Jörn Friedrich Dreyer <jfd@butonic.de> - * @author Robin Appelman <robin@icewind.nl> - * - * @license AGPL-3.0 - * - * This code is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License, version 3, - * as published by the Free Software Foundation. - * - * 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, version 3, - * along with this program. If not, see <http://www.gnu.org/licenses/> - * - */ -namespace OC\Search\Provider; - -use OC\Files\Search\SearchComparison; -use OC\Files\Search\SearchOrder; -use OC\Files\Search\SearchQuery; -use OCP\Files\FileInfo; -use OCP\Files\IRootFolder; -use OCP\Files\Search\ISearchComparison; -use OCP\Files\Search\ISearchOrder; -use OCP\IUserSession; -use OCP\Search\PagedProvider; - -/** - * Provide search results from the 'files' app - * @deprecated 20.0.0 - */ -class File extends PagedProvider { - /** - * Search for files and folders matching the given query - * - * @param string $query - * @param int|null $limit - * @param int|null $offset - * @return \OCP\Search\Result[] - * @deprecated 20.0.0 - */ - public function search($query, ?int $limit = null, ?int $offset = null) { - /** @var IRootFolder $rootFolder */ - $rootFolder = \OCP\Server::get(IRootFolder::class); - /** @var IUserSession $userSession */ - $userSession = \OCP\Server::get(IUserSession::class); - $user = $userSession->getUser(); - if (!$user) { - return []; - } - $userFolder = $rootFolder->getUserFolder($user->getUID()); - $fileQuery = new SearchQuery( - new SearchComparison(ISearchComparison::COMPARE_LIKE, 'name', '%' . $query . '%'), - (int)$limit, - (int)$offset, - [ - new SearchOrder(ISearchOrder::DIRECTION_DESCENDING, 'mtime'), - ], - $user - ); - $files = $userFolder->search($fileQuery); - $results = []; - // edit results - foreach ($files as $fileData) { - // create audio result - if ($fileData->getMimePart() === 'audio') { - $result = new \OC\Search\Result\Audio($fileData); - } - // create image result - elseif ($fileData->getMimePart() === 'image') { - $result = new \OC\Search\Result\Image($fileData); - } - // create folder result - elseif ($fileData->getMimetype() === FileInfo::MIMETYPE_FOLDER) { - $result = new \OC\Search\Result\Folder($fileData); - } - // or create file result - else { - $result = new \OC\Search\Result\File($fileData); - } - // add to results - $results[] = $result; - } - // return - return $results; - } - - public function searchPaged($query, $page, $size) { - if ($size === 0) { - return $this->search($query); - } else { - return $this->search($query, $size, ($page - 1) * $size); - } - } -} diff --git a/lib/private/Search/Result/Audio.php b/lib/private/Search/Result/Audio.php deleted file mode 100644 index 41afe691e8c..00000000000 --- a/lib/private/Search/Result/Audio.php +++ /dev/null @@ -1,41 +0,0 @@ -<?php -/** - * @copyright Copyright (c) 2016, ownCloud, Inc. - * - * @author Andrew Brown <andrew@casabrown.com> - * @author Christoph Wurst <christoph@winzerhof-wurst.at> - * @author Jörn Friedrich Dreyer <jfd@butonic.de> - * - * @license AGPL-3.0 - * - * This code is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License, version 3, - * as published by the Free Software Foundation. - * - * 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, version 3, - * along with this program. If not, see <http://www.gnu.org/licenses/> - * - */ -namespace OC\Search\Result; - -/** - * A found audio file - * @deprecated 20.0.0 - */ -class Audio extends File { - /** - * Type name; translated in templates - * @var string - * @deprecated 20.0.0 - */ - public $type = 'audio'; - - /** - * @TODO add ID3 information - */ -} diff --git a/lib/private/Search/Result/File.php b/lib/private/Search/Result/File.php deleted file mode 100644 index 59111b0cee2..00000000000 --- a/lib/private/Search/Result/File.php +++ /dev/null @@ -1,151 +0,0 @@ -<?php -/** - * @copyright Copyright (c) 2016, ownCloud, Inc. - * - * @author Andrew Brown <andrew@casabrown.com> - * @author Christoph Wurst <christoph@winzerhof-wurst.at> - * @author John Molakvoæ <skjnldsv@protonmail.com> - * @author Jörn Friedrich Dreyer <jfd@butonic.de> - * @author Lukas Reschke <lukas@statuscode.ch> - * @author Robin Appelman <robin@icewind.nl> - * - * @license AGPL-3.0 - * - * This code is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License, version 3, - * as published by the Free Software Foundation. - * - * 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, version 3, - * along with this program. If not, see <http://www.gnu.org/licenses/> - * - */ -namespace OC\Search\Result; - -use OCP\Files\FileInfo; -use OCP\Files\Folder; -use OCP\IPreview; -use OCP\IUserSession; - -/** - * A found file - * @deprecated 20.0.0 - */ -class File extends \OCP\Search\Result { - /** - * Type name; translated in templates - * @var string - * @deprecated 20.0.0 - */ - public $type = 'file'; - - /** - * Path to file - * @var string - * @deprecated 20.0.0 - */ - public $path; - - /** - * Size, in bytes - * @var int - * @deprecated 20.0.0 - */ - public $size; - - /** - * Date modified, in human readable form - * @var string - * @deprecated 20.0.0 - */ - public $modified; - - /** - * File mime type - * @var string - * @deprecated 20.0.0 - */ - public $mime_type; - - /** - * File permissions: - * - * @var string - * @deprecated 20.0.0 - */ - public $permissions; - - /** - * Has a preview - * - * @var string - * @deprecated 20.0.0 - */ - public $has_preview; - - /** - * Create a new file search result - * @param FileInfo $data file data given by provider - * @deprecated 20.0.0 - */ - public function __construct(FileInfo $data) { - $path = $this->getRelativePath($data->getPath()); - - $this->id = $data->getId(); - $this->name = $data->getName(); - $this->link = \OC::$server->getURLGenerator()->linkToRoute( - 'files.view.index', - [ - 'dir' => dirname($path), - 'scrollto' => $data->getName(), - ] - ); - $this->permissions = $data->getPermissions(); - $this->path = $path; - $this->size = $data->getSize(); - $this->modified = $data->getMtime(); - $this->mime_type = $data->getMimetype(); - $this->has_preview = $this->hasPreview($data); - } - - /** - * @var Folder $userFolderCache - * @deprecated 20.0.0 - */ - protected static $userFolderCache = null; - - /** - * converts a path relative to the users files folder - * eg /user/files/foo.txt -> /foo.txt - * @param string $path - * @return string relative path - * @deprecated 20.0.0 - */ - protected function getRelativePath($path) { - if (!isset(self::$userFolderCache)) { - $userSession = \OC::$server->get(IUserSession::class); - $userID = $userSession->getUser()->getUID(); - self::$userFolderCache = \OC::$server->getUserFolder($userID); - } - $relativePath = self::$userFolderCache->getRelativePath($path); - if ($relativePath === null) { - throw new \Exception("Search result not in user folder"); - } - return $relativePath; - } - - /** - * Is the preview available - * @param FileInfo $data - * @return bool - * @deprecated 20.0.0 - */ - protected function hasPreview($data) { - $previewManager = \OC::$server->get(IPreview::class); - return $previewManager->isAvailable($data); - } -} diff --git a/lib/private/Search/Result/Folder.php b/lib/private/Search/Result/Folder.php deleted file mode 100644 index 36d0e91c042..00000000000 --- a/lib/private/Search/Result/Folder.php +++ /dev/null @@ -1,37 +0,0 @@ -<?php -/** - * @copyright Copyright (c) 2016, ownCloud, Inc. - * - * @author Andrew Brown <andrew@casabrown.com> - * @author Christoph Wurst <christoph@winzerhof-wurst.at> - * @author Jörn Friedrich Dreyer <jfd@butonic.de> - * - * @license AGPL-3.0 - * - * This code is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License, version 3, - * as published by the Free Software Foundation. - * - * 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, version 3, - * along with this program. If not, see <http://www.gnu.org/licenses/> - * - */ -namespace OC\Search\Result; - -/** - * A found folder - * @deprecated 20.0.0 - */ -class Folder extends File { - /** - * Type name; translated in templates - * @var string - * @deprecated 20.0.0 - */ - public $type = 'folder'; -} diff --git a/lib/private/Search/Result/Image.php b/lib/private/Search/Result/Image.php deleted file mode 100644 index 27f5702e39a..00000000000 --- a/lib/private/Search/Result/Image.php +++ /dev/null @@ -1,41 +0,0 @@ -<?php -/** - * @copyright Copyright (c) 2016, ownCloud, Inc. - * - * @author Andrew Brown <andrew@casabrown.com> - * @author Christoph Wurst <christoph@winzerhof-wurst.at> - * @author Jörn Friedrich Dreyer <jfd@butonic.de> - * - * @license AGPL-3.0 - * - * This code is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License, version 3, - * as published by the Free Software Foundation. - * - * 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, version 3, - * along with this program. If not, see <http://www.gnu.org/licenses/> - * - */ -namespace OC\Search\Result; - -/** - * A found image file - * @deprecated 20.0.0 - */ -class Image extends File { - /** - * Type name; translated in templates - * @var string - * @deprecated 20.0.0 - */ - public $type = 'image'; - - /** - * @TODO add EXIF information - */ -} diff --git a/lib/private/Search/SearchComposer.php b/lib/private/Search/SearchComposer.php index 03e84a079fe..be366e8ba6c 100644 --- a/lib/private/Search/SearchComposer.php +++ b/lib/private/Search/SearchComposer.php @@ -3,35 +3,19 @@ declare(strict_types=1); /** - * @copyright 2020 Christoph Wurst <christoph@winzerhof-wurst.at> - * - * @author Christoph Wurst <christoph@winzerhof-wurst.at> - * @author Joas Schilling <coding@schilljs.com> - * @author John Molakvoæ <skjnldsv@protonmail.com> - * - * @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 <http://www.gnu.org/licenses/>. - * + * SPDX-FileCopyrightText: 2020 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later */ namespace OC\Search; use InvalidArgumentException; use OC\AppFramework\Bootstrap\Coordinator; +use OC\Core\ResponseDefinitions; +use OCP\IAppConfig; use OCP\IURLGenerator; use OCP\IUser; use OCP\Search\FilterDefinition; +use OCP\Search\IExternalProvider; use OCP\Search\IFilter; use OCP\Search\IFilteringProvider; use OCP\Search\IInAppSearch; @@ -42,7 +26,10 @@ use Psr\Container\ContainerExceptionInterface; use Psr\Container\ContainerInterface; use Psr\Log\LoggerInterface; use RuntimeException; +use function array_filter; use function array_map; +use function array_values; +use function in_array; /** * Queries individual \OCP\Search\IProvider implementations and composes a @@ -62,6 +49,7 @@ use function array_map; * results are awaited or shown as they come in. * * @see IProvider::search() for the arguments of the individual search requests + * @psalm-import-type CoreUnifiedSearchProvider from ResponseDefinitions */ class SearchComposer { /** @@ -78,7 +66,8 @@ class SearchComposer { private Coordinator $bootstrapCoordinator, private ContainerInterface $container, private IURLGenerator $urlGenerator, - private LoggerInterface $logger + private LoggerInterface $logger, + private IAppConfig $appConfig, ) { $this->commonFilters = [ IFilter::BUILTIN_TERM => new FilterDefinition(IFilter::BUILTIN_TERM, FilterDefinition::TYPE_STRING), @@ -130,6 +119,8 @@ class SearchComposer { } } + $this->filterProviders(); + $this->loadFilters(); } @@ -149,7 +140,7 @@ class SearchComposer { } foreach ($provider->getSupportedFilters() as $filterName) { if ($this->getFilterDefinition($filterName, $providerId) === null) { - throw new InvalidArgumentException('Invalid filter '. $filterName); + throw new InvalidArgumentException('Invalid filter ' . $filterName); } } } @@ -175,7 +166,7 @@ class SearchComposer { * @param string $route the route the user is currently at * @param array $routeParameters the parameters of the route the user is currently at * - * @return array + * @return list<CoreUnifiedSearchProvider> */ public function getProviders(string $route, array $routeParameters): array { $this->loadLazyProviders(); @@ -188,6 +179,7 @@ class SearchComposer { if ($order === null) { return; } + $isExternalProvider = $provider instanceof IExternalProvider ? $provider->isExternalProvider() : false; $triggers = [$provider->getId()]; if ($provider instanceof IFilteringProvider) { $triggers += $provider->getAlternateIds(); @@ -202,7 +194,8 @@ class SearchComposer { 'name' => $provider->getName(), 'icon' => $this->fetchIcon($appId, $provider->getId()), 'order' => $order, - 'triggers' => $triggers, + 'isExternalProvider' => $isExternalProvider, + 'triggers' => array_values($triggers), 'filters' => $this->getFiltersType($filters, $provider->getId()), 'inAppSearch' => $provider instanceof IInAppSearch, ]; @@ -219,12 +212,31 @@ class SearchComposer { return $providers; } + /** + * Filter providers based on 'unified_search.providers_allowed' core app config array + * Will remove providers that are not in the allowed list + */ + private function filterProviders(): void { + $allowedProviders = $this->appConfig->getValueArray('core', 'unified_search.providers_allowed'); + + if (empty($allowedProviders)) { + return; + } + + foreach (array_keys($this->providers) as $providerId) { + if (!in_array($providerId, $allowedProviders, true)) { + unset($this->providers[$providerId]); + unset($this->handlers[$providerId]); + } + } + } + private function fetchIcon(string $appId, string $providerId): string { $icons = [ - [$providerId, $providerId.'.svg'], + [$providerId, $providerId . '.svg'], [$providerId, 'app.svg'], - [$appId, $providerId.'.svg'], - [$appId, $appId.'.svg'], + [$appId, $providerId . '.svg'], + [$appId, $appId . '.svg'], [$appId, 'app.svg'], ['core', 'places/default-app-icon.svg'], ]; diff --git a/lib/private/Search/SearchQuery.php b/lib/private/Search/SearchQuery.php index e4295c4ab76..791edb7a0f7 100644 --- a/lib/private/Search/SearchQuery.php +++ b/lib/private/Search/SearchQuery.php @@ -3,27 +3,8 @@ declare(strict_types=1); /** - * @copyright 2020 Christoph Wurst <christoph@winzerhof-wurst.at> - * - * @author Christoph Wurst <christoph@winzerhof-wurst.at> - * @author Joas Schilling <coding@schilljs.com> - * @author John Molakvoæ <skjnldsv@protonmail.com> - * - * @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 <http://www.gnu.org/licenses/>. - * + * SPDX-FileCopyrightText: 2020 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later */ namespace OC\Search; @@ -44,7 +25,7 @@ class SearchQuery implements ISearchQuery { private int $limit = self::LIMIT_DEFAULT, private int|string|null $cursor = null, private string $route = '', - private array $routeParameters = [], + private array $routeParameters = [], ) { } diff --git a/lib/private/Search/UnsupportedFilter.php b/lib/private/Search/UnsupportedFilter.php index 84b6163d2fa..ea520e6b872 100644 --- a/lib/private/Search/UnsupportedFilter.php +++ b/lib/private/Search/UnsupportedFilter.php @@ -3,25 +3,8 @@ declare(strict_types=1); /** - * @copyright 2023 Benjamin Gaussorgues <benjamin.gaussorgues@nextcloud.com> - * - * @author Benjamin Gaussorgues <benjamin.gaussorgues@nextcloud.com> - * - * @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 <http://www.gnu.org/licenses/>. - * + * SPDX-FileCopyrightText: 2023 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later */ namespace OC\Search; @@ -29,6 +12,6 @@ use Exception; final class UnsupportedFilter extends Exception { public function __construct(string $filerName, $providerId) { - parent::__construct('Provider '.$providerId.' doesn’t support filter '.$filerName.'.'); + parent::__construct('Provider ' . $providerId . ' doesn’t support filter ' . $filerName . '.'); } } |