From 1c25fcab5c000501b4f600c7d767497c2f0868cf Mon Sep 17 00:00:00 2001 From: Maxence Lange Date: Wed, 17 Jul 2019 22:48:38 -0100 Subject: ./occ fulltextsearch:document:index Signed-off-by: Maxence Lange --- appinfo/info.xml | 1 + lib/Command/DocumentIndex.php | 160 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 161 insertions(+) create mode 100644 lib/Command/DocumentIndex.php diff --git a/appinfo/info.xml b/appinfo/info.xml index 5ef655e..e02b188 100644 --- a/appinfo/info.xml +++ b/appinfo/info.xml @@ -34,6 +34,7 @@ Core App of the full-text search framework for your Nextcloud. OCA\FullTextSearch\Command\Check OCA\FullTextSearch\Command\Configure OCA\FullTextSearch\Command\DocumentPlatform + OCA\FullTextSearch\Command\DocumentIndex OCA\FullTextSearch\Command\DocumentProvider OCA\FullTextSearch\Command\Index OCA\FullTextSearch\Command\Live diff --git a/lib/Command/DocumentIndex.php b/lib/Command/DocumentIndex.php new file mode 100644 index 0000000..b2d8e85 --- /dev/null +++ b/lib/Command/DocumentIndex.php @@ -0,0 +1,160 @@ + + * @copyright 2018 + * @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 . + * + */ + +declare(strict_types=1); + + +/** + * FullTextSearch - Full text search framework for Nextcloud + * + * This file is licensed under the Affero General Public License version 3 or + * later. See the COPYING file. + * + * @author Maxence Lange + * @copyright 2018 + * @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 . + * + */ + + +namespace OCA\FullTextSearch\Command; + + +use Exception; +use OC\Core\Command\Base; +use OCA\FullTextSearch\Model\Index; +use OCA\FullTextSearch\Service\MiscService; +use OCA\FullTextSearch\Service\PlatformService; +use OCA\FullTextSearch\Service\ProviderService; +use OCP\FullTextSearch\Model\IIndexDocument; +use Symfony\Component\Console\Input\InputArgument; +use Symfony\Component\Console\Input\InputInterface; +use Symfony\Component\Console\Input\InputOption; +use Symfony\Component\Console\Output\OutputInterface; + + +/** + * Class DocumentProvider + * + * @package OCA\FullTextSearch\Command + */ +class DocumentIndex extends Base { + + + /** @var ProviderService */ + private $providerService; + + /** @var PlatformService */ + private $platformService; + + /** @var MiscService */ + private $miscService; + + + /** + * Index constructor. + * + * @param ProviderService $providerService + * @param PlatformService $platformService + * @param MiscService $miscService + */ + public function __construct( + ProviderService $providerService, PlatformService $platformService, MiscService $miscService + ) { + parent::__construct(); + + $this->providerService = $providerService; + $this->platformService = $platformService; + $this->miscService = $miscService; + } + + + /** + * + */ + protected function configure() { + parent::configure(); + $this->setName('fulltextsearch:document:index') + ->setDescription('index one specific document') + ->addArgument('userId', InputArgument::REQUIRED, 'userId') + ->addArgument('providerId', InputArgument::REQUIRED, 'providerId') + ->addArgument('documentId', InputArgument::REQUIRED, 'documentId'); + } + + + /** + * @param InputInterface $input + * @param OutputInterface $output + * + * @throws Exception + */ + protected function execute(InputInterface $input, OutputInterface $output) { + $providerId = $input->getArgument('providerId'); + $documentId = $input->getArgument('documentId'); + $userId = $input->getArgument('userId'); + + $providerWrapper = $this->providerService->getProvider($providerId); + $provider = $providerWrapper->getProvider(); + + $index = new Index($providerId, $documentId); + $index->setOwnerId($userId); + $index->setStatus(Index::INDEX_FULL); + $indexDocument = $provider->updateDocument($index); + if (!$indexDocument->hasIndex()) { + $indexDocument->setIndex($index); + } + + if ($indexDocument->getIndex() + ->isStatus(Index::INDEX_REMOVE)) { + throw new Exception('Unknown document'); + } + + $platformWrapper = $this->platformService->getPlatform(); + $platform = $platformWrapper->getPlatform(); + + $indexDocument->getIndex() + ->setStatus(Index::INDEX_FULL); + $platform->indexDocument($indexDocument); + } + + +} + + + -- cgit v1.2.3