Skip to content

Commit 82d2ddf

Browse files
fsamapoorcome-nc
andcommitted
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>
1 parent e058b01 commit 82d2ddf

File tree

4 files changed

+45
-2
lines changed

4 files changed

+45
-2
lines changed

lib/composer/composer/autoload_classmap.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -420,6 +420,7 @@
420420
'OCP\\Files\\UnseekableException' => $baseDir . '/lib/public/Files/UnseekableException.php',
421421
'OCP\\Files_FullTextSearch\\Model\\AFilesDocument' => $baseDir . '/lib/public/Files_FullTextSearch/Model/AFilesDocument.php',
422422
'OCP\\FullTextSearch\\Exceptions\\FullTextSearchAppNotAvailableException' => $baseDir . '/lib/public/FullTextSearch/Exceptions/FullTextSearchAppNotAvailableException.php',
423+
'OCP\\FullTextSearch\\Exceptions\\FullTextSearchIndexNotAvailableException' => $baseDir . '/lib/public/FullTextSearch/Exceptions/FullTextSearchIndexNotAvailableException.php',
423424
'OCP\\FullTextSearch\\IFullTextSearchManager' => $baseDir . '/lib/public/FullTextSearch/IFullTextSearchManager.php',
424425
'OCP\\FullTextSearch\\IFullTextSearchPlatform' => $baseDir . '/lib/public/FullTextSearch/IFullTextSearchPlatform.php',
425426
'OCP\\FullTextSearch\\IFullTextSearchProvider' => $baseDir . '/lib/public/FullTextSearch/IFullTextSearchProvider.php',

lib/composer/composer/autoload_static.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -453,6 +453,7 @@ class ComposerStaticInit749170dad3f5e7f9ca158f5a9f04f6a2
453453
'OCP\\Files\\UnseekableException' => __DIR__ . '/../../..' . '/lib/public/Files/UnseekableException.php',
454454
'OCP\\Files_FullTextSearch\\Model\\AFilesDocument' => __DIR__ . '/../../..' . '/lib/public/Files_FullTextSearch/Model/AFilesDocument.php',
455455
'OCP\\FullTextSearch\\Exceptions\\FullTextSearchAppNotAvailableException' => __DIR__ . '/../../..' . '/lib/public/FullTextSearch/Exceptions/FullTextSearchAppNotAvailableException.php',
456+
'OCP\\FullTextSearch\\Exceptions\\FullTextSearchIndexNotAvailableException' => __DIR__ . '/../../..' . '/lib/public/FullTextSearch/Exceptions/FullTextSearchIndexNotAvailableException.php',
456457
'OCP\\FullTextSearch\\IFullTextSearchManager' => __DIR__ . '/../../..' . '/lib/public/FullTextSearch/IFullTextSearchManager.php',
457458
'OCP\\FullTextSearch\\IFullTextSearchPlatform' => __DIR__ . '/../../..' . '/lib/public/FullTextSearch/IFullTextSearchPlatform.php',
458459
'OCP\\FullTextSearch\\IFullTextSearchProvider' => __DIR__ . '/../../..' . '/lib/public/FullTextSearch/IFullTextSearchProvider.php',

lib/private/FullTextSearch/Model/IndexDocument.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
namespace OC\FullTextSearch\Model;
2727

2828
use JsonSerializable;
29+
use OCP\FullTextSearch\Exceptions\FullTextSearchIndexNotAvailableException;
2930
use OCP\FullTextSearch\Model\IDocumentAccess;
3031
use OCP\FullTextSearch\Model\IIndex;
3132
use OCP\FullTextSearch\Model\IIndexDocument;
@@ -51,7 +52,7 @@ class IndexDocument implements IIndexDocument, JsonSerializable {
5152

5253
protected DocumentAccess $access;
5354

54-
protected IIndex $index;
55+
protected ?IIndex $index = null;
5556

5657
protected int $modifiedTime = 0;
5758

@@ -136,9 +137,14 @@ final public function setIndex(IIndex $index): IIndexDocument {
136137
/**
137138
* Get the Index.
138139
*
140+
* @throws FullTextSearchIndexNotAvailableException
139141
* @since 15.0.0
140142
*/
141143
final public function getIndex(): IIndex {
144+
if ($this->index === null) {
145+
throw new FullTextSearchIndexNotAvailableException('No IIndex generated');
146+
}
147+
142148
return $this->index;
143149
}
144150

@@ -148,7 +154,7 @@ final public function getIndex(): IIndex {
148154
* @since 16.0.0
149155
*/
150156
final public function hasIndex(): bool {
151-
return isset($this->index);
157+
return $this->index !== null;
152158
}
153159

154160
/**
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* @copyright 2023, Faraz Samapoor <f.samapoor@gmail.com>
7+
*
8+
* @author Faraz Samapoor <f.samapoor@gmail.com>
9+
*
10+
* @license GNU AGPL version 3 or any later version
11+
*
12+
* This program is free software: you can redistribute it and/or modify
13+
* it under the terms of the GNU Affero General Public License as
14+
* published by the Free Software Foundation, either version 3 of the
15+
* License, or (at your option) any later version.
16+
*
17+
* This program is distributed in the hope that it will be useful,
18+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
19+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20+
* GNU Affero General Public License for more details.
21+
*
22+
* You should have received a copy of the GNU Affero General Public License
23+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
24+
*
25+
*/
26+
namespace OCP\FullTextSearch\Exceptions;
27+
28+
/**
29+
* @since 28.0.0
30+
*
31+
* Class FullTextSearchIndexNotAvailableException
32+
*
33+
*/
34+
class FullTextSearchIndexNotAvailableException extends \Exception {
35+
}

0 commit comments

Comments
 (0)