From bcc48d08c84ece30270d00bac708f22e5d8eb967 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julius=20H=C3=A4rtl?= Date: Wed, 10 Apr 2019 11:30:58 +0200 Subject: [PATCH 1/3] Add check if fts is enabled MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Julius Härtl --- lib/AppInfo/Application.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/AppInfo/Application.php b/lib/AppInfo/Application.php index d1accdb86..1a7faf6d6 100644 --- a/lib/AppInfo/Application.php +++ b/lib/AppInfo/Application.php @@ -191,7 +191,7 @@ protected function registerCollaborationResources() { } public function registerFullTextSearch() { - if (Util::getVersion()[0] < 16) { + if (Util::getVersion()[0] < 16 || !\OC::$server->getAppManager()->isEnabledForUser('fulltextsearch')) { return; } From 6af28f1b796e45369c2ef5595cdd060a9822328a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julius=20H=C3=A4rtl?= Date: Wed, 10 Apr 2019 11:31:20 +0200 Subject: [PATCH 2/3] Cast ids to integer for fulltextsearch MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Julius Härtl --- lib/Service/FullTextSearchService.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/Service/FullTextSearchService.php b/lib/Service/FullTextSearchService.php index f8e8b0ad8..203c975fc 100644 --- a/lib/Service/FullTextSearchService.php +++ b/lib/Service/FullTextSearchService.php @@ -92,7 +92,7 @@ public function __construct( * @param GenericEvent $e */ public function onCardCreated(GenericEvent $e) { - $cardId = $e->getArgument('id'); + $cardId = (int)$e->getArgument('id'); $userId = $e->getArgument('userId'); $this->fullTextSearchManager->createIndex( @@ -105,7 +105,7 @@ public function onCardCreated(GenericEvent $e) { * @param GenericEvent $e */ public function onCardUpdated(GenericEvent $e) { - $cardId = $e->getArgument('id'); + $cardId = (int)$e->getArgument('id'); $this->fullTextSearchManager->updateIndexStatus( DeckProvider::DECK_PROVIDER_ID, (string)$cardId, IIndex::INDEX_CONTENT @@ -117,7 +117,7 @@ public function onCardUpdated(GenericEvent $e) { * @param GenericEvent $e */ public function onCardDeleted(GenericEvent $e) { - $cardId = $e->getArgument('id'); + $cardId = (int)$e->getArgument('id'); $this->fullTextSearchManager->updateIndexStatus( DeckProvider::DECK_PROVIDER_ID, (string)$cardId, IIndex::INDEX_REMOVE @@ -129,7 +129,7 @@ public function onCardDeleted(GenericEvent $e) { * @param GenericEvent $e */ public function onBoardShares(GenericEvent $e) { - $boardId = $e->getArgument('boardId'); + $boardId = (int)$e->getArgument('boardId'); $cards = array_map( function(Card $item) { From 0258b74b42de834a5a316339ffe107bea8fbfb8f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julius=20H=C3=A4rtl?= Date: Wed, 10 Apr 2019 15:41:32 +0200 Subject: [PATCH 3/3] Catch exceptions and only cast when necessary MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Julius Härtl --- lib/Service/FullTextSearchService.php | 45 +++++++++++++++++---------- 1 file changed, 28 insertions(+), 17 deletions(-) diff --git a/lib/Service/FullTextSearchService.php b/lib/Service/FullTextSearchService.php index 203c975fc..4d8e0e150 100644 --- a/lib/Service/FullTextSearchService.php +++ b/lib/Service/FullTextSearchService.php @@ -40,6 +40,7 @@ use OCA\Deck\Provider\DeckProvider; use OCP\AppFramework\Db\DoesNotExistException; use OCP\AppFramework\Db\MultipleObjectsReturnedException; +use OCP\FullTextSearch\Exceptions\FullTextSearchAppNotAvailableException; use OCP\FullTextSearch\IFullTextSearchManager; use OCP\FullTextSearch\Model\IDocumentAccess; use OCP\FullTextSearch\Model\IIndex; @@ -92,12 +93,15 @@ public function __construct( * @param GenericEvent $e */ public function onCardCreated(GenericEvent $e) { - $cardId = (int)$e->getArgument('id'); + $cardId = $e->getArgument('id'); $userId = $e->getArgument('userId'); - $this->fullTextSearchManager->createIndex( - DeckProvider::DECK_PROVIDER_ID, (string)$cardId, $userId, IIndex::INDEX_FULL - ); + try { + $this->fullTextSearchManager->createIndex( + DeckProvider::DECK_PROVIDER_ID, (string)$cardId, $userId, IIndex::INDEX_FULL + ); + } catch (FullTextSearchAppNotAvailableException $e) { + } } @@ -105,11 +109,14 @@ public function onCardCreated(GenericEvent $e) { * @param GenericEvent $e */ public function onCardUpdated(GenericEvent $e) { - $cardId = (int)$e->getArgument('id'); + $cardId = $e->getArgument('id'); - $this->fullTextSearchManager->updateIndexStatus( + try { + $this->fullTextSearchManager->updateIndexStatus( DeckProvider::DECK_PROVIDER_ID, (string)$cardId, IIndex::INDEX_CONTENT ); + } catch (FullTextSearchAppNotAvailableException $e) { + } } @@ -117,11 +124,14 @@ public function onCardUpdated(GenericEvent $e) { * @param GenericEvent $e */ public function onCardDeleted(GenericEvent $e) { - $cardId = (int)$e->getArgument('id'); + $cardId = $e->getArgument('id'); - $this->fullTextSearchManager->updateIndexStatus( - DeckProvider::DECK_PROVIDER_ID, (string)$cardId, IIndex::INDEX_REMOVE - ); + try { + $this->fullTextSearchManager->updateIndexStatus( + DeckProvider::DECK_PROVIDER_ID, (string)$cardId, IIndex::INDEX_REMOVE + ); + } catch (FullTextSearchAppNotAvailableException $e) { + } } @@ -137,9 +147,12 @@ function(Card $item) { }, $this->getCardsFromBoard($boardId) ); - $this->fullTextSearchManager->updateIndexesStatus( - DeckProvider::DECK_PROVIDER_ID, $cards, IIndex::INDEX_META - ); + try { + $this->fullTextSearchManager->updateIndexesStatus( + DeckProvider::DECK_PROVIDER_ID, $cards, IIndex::INDEX_META + ); + } catch (FullTextSearchAppNotAvailableException $e) { + } } @@ -167,7 +180,7 @@ public function fillIndexDocument(IIndexDocument $document) { $document->setTitle($card->getTitle()); $document->setContent($card->getDescription()); - $document->setAccess($this->generateDocumentAccessFromCardId($card->getId())); + $document->setAccess($this->generateDocumentAccessFromCardId((int)$card->getId())); } @@ -181,9 +194,7 @@ public function fillIndexDocument(IIndexDocument $document) { public function generateDocumentAccessFromCardId(int $cardId): IDocumentAccess { $board = $this->getBoardFromCardId($cardId); - $access = new DocumentAccess($board->getOwner()); - - return $access; + return new DocumentAccess($board->getOwner()); }