diff options
author | Faraz Samapoor <f.samapoor@gmail.com> | 2023-11-09 14:33:05 +0330 |
---|---|---|
committer | Faraz Samapoor <f.samapoor@gmail.com> | 2024-01-15 10:36:02 +0330 |
commit | cdf9d94423f7a6ee2f825cec86278e5f977de493 (patch) | |
tree | efe0b2dfb8ab9eb1b6ebef6345b83807c4f9fb4e /lib | |
parent | 28450718541b331f6db6da92cb22dd44879f7727 (diff) | |
download | nextcloud-server-cdf9d94423f7a6ee2f825cec86278e5f977de493.tar.gz nextcloud-server-cdf9d94423f7a6ee2f825cec86278e5f977de493.zip |
Adds new exception to check for the availability of the index.
Signed-off-by: Faraz Samapoor <f.samapoor@gmail.com>
Co-authored-by: Côme Chilliet <91878298+come-nc@users.noreply.github.com>
Diffstat (limited to 'lib')
4 files changed, 45 insertions, 2 deletions
diff --git a/lib/composer/composer/autoload_classmap.php b/lib/composer/composer/autoload_classmap.php index 63ba07e2e4f..e92725d814b 100644 --- a/lib/composer/composer/autoload_classmap.php +++ b/lib/composer/composer/autoload_classmap.php @@ -422,6 +422,7 @@ return array( 'OCP\\Files\\UnseekableException' => $baseDir . '/lib/public/Files/UnseekableException.php', 'OCP\\Files_FullTextSearch\\Model\\AFilesDocument' => $baseDir . '/lib/public/Files_FullTextSearch/Model/AFilesDocument.php', 'OCP\\FullTextSearch\\Exceptions\\FullTextSearchAppNotAvailableException' => $baseDir . '/lib/public/FullTextSearch/Exceptions/FullTextSearchAppNotAvailableException.php', + 'OCP\\FullTextSearch\\Exceptions\\FullTextSearchIndexNotAvailableException' => $baseDir . '/lib/public/FullTextSearch/Exceptions/FullTextSearchIndexNotAvailableException.php', 'OCP\\FullTextSearch\\IFullTextSearchManager' => $baseDir . '/lib/public/FullTextSearch/IFullTextSearchManager.php', 'OCP\\FullTextSearch\\IFullTextSearchPlatform' => $baseDir . '/lib/public/FullTextSearch/IFullTextSearchPlatform.php', 'OCP\\FullTextSearch\\IFullTextSearchProvider' => $baseDir . '/lib/public/FullTextSearch/IFullTextSearchProvider.php', diff --git a/lib/composer/composer/autoload_static.php b/lib/composer/composer/autoload_static.php index bf1a13d49de..0746fa5c9b0 100644 --- a/lib/composer/composer/autoload_static.php +++ b/lib/composer/composer/autoload_static.php @@ -455,6 +455,7 @@ class ComposerStaticInit749170dad3f5e7f9ca158f5a9f04f6a2 'OCP\\Files\\UnseekableException' => __DIR__ . '/../../..' . '/lib/public/Files/UnseekableException.php', 'OCP\\Files_FullTextSearch\\Model\\AFilesDocument' => __DIR__ . '/../../..' . '/lib/public/Files_FullTextSearch/Model/AFilesDocument.php', 'OCP\\FullTextSearch\\Exceptions\\FullTextSearchAppNotAvailableException' => __DIR__ . '/../../..' . '/lib/public/FullTextSearch/Exceptions/FullTextSearchAppNotAvailableException.php', + 'OCP\\FullTextSearch\\Exceptions\\FullTextSearchIndexNotAvailableException' => __DIR__ . '/../../..' . '/lib/public/FullTextSearch/Exceptions/FullTextSearchIndexNotAvailableException.php', 'OCP\\FullTextSearch\\IFullTextSearchManager' => __DIR__ . '/../../..' . '/lib/public/FullTextSearch/IFullTextSearchManager.php', 'OCP\\FullTextSearch\\IFullTextSearchPlatform' => __DIR__ . '/../../..' . '/lib/public/FullTextSearch/IFullTextSearchPlatform.php', 'OCP\\FullTextSearch\\IFullTextSearchProvider' => __DIR__ . '/../../..' . '/lib/public/FullTextSearch/IFullTextSearchProvider.php', diff --git a/lib/private/FullTextSearch/Model/IndexDocument.php b/lib/private/FullTextSearch/Model/IndexDocument.php index 76638e23894..1b2e0eb5896 100644 --- a/lib/private/FullTextSearch/Model/IndexDocument.php +++ b/lib/private/FullTextSearch/Model/IndexDocument.php @@ -26,6 +26,7 @@ declare(strict_types=1); namespace OC\FullTextSearch\Model; use JsonSerializable; +use OCP\FullTextSearch\Exceptions\FullTextSearchIndexNotAvailableException; use OCP\FullTextSearch\Model\IDocumentAccess; use OCP\FullTextSearch\Model\IIndex; use OCP\FullTextSearch\Model\IIndexDocument; @@ -51,7 +52,7 @@ class IndexDocument implements IIndexDocument, JsonSerializable { protected DocumentAccess $access; - protected IIndex $index; + protected ?IIndex $index = null; protected int $modifiedTime = 0; @@ -136,9 +137,14 @@ class IndexDocument implements IIndexDocument, JsonSerializable { /** * Get the Index. * + * @throws FullTextSearchIndexNotAvailableException * @since 15.0.0 */ final public function getIndex(): IIndex { + if ($this->index === null) { + throw new FullTextSearchIndexNotAvailableException('No IIndex generated'); + } + return $this->index; } @@ -148,7 +154,7 @@ class IndexDocument implements IIndexDocument, JsonSerializable { * @since 16.0.0 */ final public function hasIndex(): bool { - return isset($this->index); + return $this->index !== null; } /** diff --git a/lib/public/FullTextSearch/Exceptions/FullTextSearchIndexNotAvailableException.php b/lib/public/FullTextSearch/Exceptions/FullTextSearchIndexNotAvailableException.php new file mode 100644 index 00000000000..cf3c5905135 --- /dev/null +++ b/lib/public/FullTextSearch/Exceptions/FullTextSearchIndexNotAvailableException.php @@ -0,0 +1,35 @@ +<?php + +declare(strict_types=1); + +/** + * @copyright 2023, Faraz Samapoor <f.samapoor@gmail.com> + * + * @author Faraz Samapoor <f.samapoor@gmail.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/>. + * + */ +namespace OCP\FullTextSearch\Exceptions; + +/** + * @since 28.0.0 + * + * Class FullTextSearchIndexNotAvailableException + * + */ +class FullTextSearchIndexNotAvailableException extends \Exception { +} |