Skip to content

Commit

Permalink
Adds new exception to check for the availability of the index.
Browse files Browse the repository at this point in the history
Signed-off-by: Faraz Samapoor <[email protected]>
Co-authored-by: Côme Chilliet <[email protected]>
  • Loading branch information
fsamapoor and come-nc committed Nov 9, 2023
1 parent f088cc2 commit e03294a
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 2 deletions.
10 changes: 8 additions & 2 deletions lib/private/FullTextSearch/Model/IndexDocument.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
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;
Expand All @@ -51,7 +52,7 @@ class IndexDocument implements IIndexDocument, JsonSerializable {

protected DocumentAccess $access;

protected IIndex $index;
protected ?IIndex $index = null;

protected int $modifiedTime = 0;

Expand Down Expand Up @@ -136,9 +137,14 @@ final public function setIndex(IIndex $index): IIndexDocument {
/**
* 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;
}

Expand All @@ -148,7 +154,7 @@ final public function getIndex(): IIndex {
* @since 16.0.0
*/
final public function hasIndex(): bool {
return isset($this->index);
return $this->index !== null;
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

declare(strict_types=1);

/**
* @copyright 2023, Faraz Samapoor <[email protected]>
*
* @author Faraz Samapoor <[email protected]>
*
* @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 {
}

0 comments on commit e03294a

Please sign in to comment.