Skip to content

Commit e03294a

Browse files
fsamapoorcome-nc
andcommitted
Adds new exception to check for the availability of the index.
Signed-off-by: Faraz Samapoor <[email protected]> Co-authored-by: Côme Chilliet <[email protected]>
1 parent f088cc2 commit e03294a

File tree

2 files changed

+43
-2
lines changed

2 files changed

+43
-2
lines changed

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 <[email protected]>
7+
*
8+
* @author Faraz Samapoor <[email protected]>
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)