Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/fulltextsearch.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMaxence Lange <maxence@artificial-owl.com>2020-01-30 14:10:52 +0300
committerMaxence Lange <maxence@artificial-owl.com>2020-01-30 14:10:52 +0300
commit279ace7aafd8920c84c908b6bb21680b26f55ab8 (patch)
tree4a10262623d7f4737bd4b9706b796903c739f239
parentf8299a897d103bbc5a12e307942633c9a72f5db1 (diff)
set index status from cli
Signed-off-by: Maxence Lange <maxence@artificial-owl.com>
-rw-r--r--appinfo/info.xml3
-rw-r--r--lib/Command/DocumentStatus.php201
-rw-r--r--lib/Command/Live.php2
-rw-r--r--lib/Service/IndexService.php6
4 files changed, 209 insertions, 3 deletions
diff --git a/appinfo/info.xml b/appinfo/info.xml
index 981b2fb..355e565 100644
--- a/appinfo/info.xml
+++ b/appinfo/info.xml
@@ -33,9 +33,10 @@ Core App of the full-text search framework for your Nextcloud.
<commands>
<command>OCA\FullTextSearch\Command\Check</command>
<command>OCA\FullTextSearch\Command\Configure</command>
- <command>OCA\FullTextSearch\Command\DocumentPlatform</command>
<command>OCA\FullTextSearch\Command\DocumentIndex</command>
+ <command>OCA\FullTextSearch\Command\DocumentPlatform</command>
<command>OCA\FullTextSearch\Command\DocumentProvider</command>
+ <command>OCA\FullTextSearch\Command\DocumentStatus</command>
<command>OCA\FullTextSearch\Command\Index</command>
<command>OCA\FullTextSearch\Command\Live</command>
<command>OCA\FullTextSearch\Command\Reset</command>
diff --git a/lib/Command/DocumentStatus.php b/lib/Command/DocumentStatus.php
new file mode 100644
index 0000000..d19915c
--- /dev/null
+++ b/lib/Command/DocumentStatus.php
@@ -0,0 +1,201 @@
+<?php 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 <maxence@artificial-owl.com>
+ * @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 <http://www.gnu.org/licenses/>.
+ *
+ */
+
+
+namespace OCA\FullTextSearch\Command;
+
+
+use Exception;
+use OC\Core\Command\Base;
+use OCA\FullTextSearch\Exceptions\IndexDoesNotExistException;
+use OCA\FullTextSearch\Service\IndexService;
+use OCA\FullTextSearch\Service\MiscService;
+use OCP\FullTextSearch\Model\IIndex;
+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 DocumentStatus
+ *
+ * @package OCA\FullTextSearch\Command
+ */
+class DocumentStatus extends Base {
+
+
+ /** @var IndexService */
+ private $indexService;
+
+ /** @var MiscService */
+ private $miscService;
+
+ /** @var array */
+ private $statusAvailable = [
+ 'IGNORE' => 'document will never be indexed',
+ 'INDEX' => 'document will be indexed',
+ 'DONE' => 'document is well indexed',
+ 'REMOVE' => 'document will be removed',
+ 'FAILED' => 'index had fail'
+ ];
+
+
+ /**
+ * DocumentStatus constructor.
+ *
+ * @param IndexService $indexService
+ * @param MiscService $miscService
+ */
+ public function __construct(IndexService $indexService, MiscService $miscService) {
+ parent::__construct();
+
+ $this->indexService = $indexService;
+ $this->miscService = $miscService;
+ }
+
+
+ /**
+ *
+ */
+ protected function configure() {
+ parent::configure();
+ $this->setName('fulltextsearch:document:status')
+ ->setDescription('change the status on one specific document')
+ ->addArgument('provider', InputArgument::REQUIRED, 'Id of the provider')
+ ->addArgument('document', InputArgument::REQUIRED, 'If of the document')
+ ->addOption('value', '', InputOption::VALUE_REQUIRED, 'new status', '')
+ ->addOption('user', 'u', InputOption::VALUE_REQUIRED, 'specify the owner of the document', '')
+ ->addOption('json', 'j', InputOption::VALUE_NONE, 'return status in JSON');
+ }
+
+
+ /**
+ * @param InputInterface $input
+ * @param OutputInterface $output
+ *
+ * @throws Exception
+ */
+ protected function execute(InputInterface $input, OutputInterface $output) {
+ $providerId = $input->getArgument('provider');
+ $documentId = $input->getArgument('document');
+ $value = $input->getOption('value');
+ $userId = $input->getOption('user');
+ $json = $input->getOption('json');
+
+ try {
+ $index = $this->indexService->getIndex($providerId, $documentId);
+ if ($value !== '') {
+ $status = $this->statusConvertFromString($value);
+ $index->setStatus($status, true);
+ $this->indexService->updateIndex($index);
+ }
+ } catch (IndexDoesNotExistException $e) {
+ if ($userId === '') {
+ throw new Exception(
+ "Index is not known.\nIf you want to generate the entry, please specify the owner of the document using --user <userId>"
+ );
+ }
+
+ $status = $this->statusConvertFromString($value);
+ $index = $this->indexService->createIndex($providerId, $documentId, $userId, $status);
+ }
+
+
+ if ($json) {
+ echo json_encode($index, JSON_PRETTY_PRINT) . "\n";
+
+ return;
+ }
+
+ $status = $this->statusConvertToString($index->getStatus());
+ $desc = $this->statusAvailable[$status];
+ $output->writeln('current status: <info>' . $status . '</info> (' . $desc . ')');
+ }
+
+
+ /**
+ * @param int $status
+ *
+ * @return string
+ */
+ private function statusConvertToString(int $status): string {
+ switch ($status) {
+ case IIndex::INDEX_OK:
+ case IIndex::INDEX_DONE:
+ return 'DONE';
+
+ case IIndex::INDEX_IGNORE:
+ return 'IGNORE';
+
+ case IIndex::INDEX_META:
+ case IIndex::INDEX_CONTENT:
+ case IIndex:: INDEX_PARTS:
+ case IIndex:: INDEX_FULL:
+ return 'INDEX';
+
+ case IIndex:: INDEX_REMOVE:
+ return 'REMOVE';
+
+ case IIndex::INDEX_FAILED:
+ return 'FAILED';
+ }
+
+ return 'unknown';
+ }
+
+
+ /**
+ * @param string $status
+ *
+ * @return int
+ * @throws Exception
+ */
+ private function statusConvertFromString(string $status): int {
+ switch ($status) {
+ case 'DONE':
+ return IIndex::INDEX_OK;
+
+ case 'IGNORE':
+ return IIndex::INDEX_IGNORE;
+
+ case 'INDEX':
+ return IIndex:: INDEX_FULL;
+
+ case 'REMOVE':
+ return IIndex:: INDEX_REMOVE;
+
+ case 'FAILED':
+ return IIndex::INDEX_FAILED;
+ }
+
+ throw new Exception("Specify a valid status: " . implode(', ', array_keys($this->statusAvailable)));
+ }
+
+}
+
diff --git a/lib/Command/Live.php b/lib/Command/Live.php
index 3d54d12..229c320 100644
--- a/lib/Command/Live.php
+++ b/lib/Command/Live.php
@@ -68,7 +68,7 @@ class Live extends ACommandBase {
const INDEX_OPTION_NO_READLINE = '_no-readline';
- const CYCLE_DELAY = 300000;
+ const CYCLE_DELAY = 3000000;
const PANEL_RUN = 'run';
const PANEL_RUN_LINE_MEMORY = 'Memory: %_memory%';
diff --git a/lib/Service/IndexService.php b/lib/Service/IndexService.php
index 3dc29ea..112d15f 100644
--- a/lib/Service/IndexService.php
+++ b/lib/Service/IndexService.php
@@ -395,6 +395,10 @@ class IndexService implements IIndexService {
]
);
+ if ($index->isStatus(IIndex::INDEX_IGNORE)) {
+ return;
+ }
+
if (!$index->isStatus(Index::INDEX_REMOVE)) {
try {
$document = $provider->updateDocument($index);
@@ -451,7 +455,7 @@ class IndexService implements IIndexService {
*
* @throws Exception
*/
- private function updateIndex(IIndex $index) {
+ public function updateIndex(IIndex $index) {
/** @var Index $index */
$this->updateIndexError($index);