diff options
author | Maxence Lange <maxence@artificial-owl.com> | 2018-07-27 13:06:15 +0300 |
---|---|---|
committer | Maxence Lange <maxence@artificial-owl.com> | 2018-07-27 13:06:15 +0300 |
commit | be05d95051135ab86860047bfe9c750b2216a902 (patch) | |
tree | 5b2fc684780943c9e041324f380998afbd2fe434 /lib | |
parent | 38c032cc41853715ec533f94dd4d164922070700 (diff) |
new commands
Signed-off-by: Maxence Lange <maxence@artificial-owl.com>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Command/DocumentPlatform.php | 104 | ||||
-rw-r--r-- | lib/Command/DocumentProvider.php | 116 |
2 files changed, 220 insertions, 0 deletions
diff --git a/lib/Command/DocumentPlatform.php b/lib/Command/DocumentPlatform.php new file mode 100644 index 0000000..b64d4e8 --- /dev/null +++ b/lib/Command/DocumentPlatform.php @@ -0,0 +1,104 @@ +<?php +/** + * 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 OCA\FullTextSearch\Model\ExtendedBase; +use OCA\FullTextSearch\Service\MiscService; +use OCA\FullTextSearch\Service\PlatformService; +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 DocumentPlatform extends ExtendedBase { + + + /** @var PlatformService */ + private $platformService; + + /** @var MiscService */ + private $miscService; + + + /** + * Index constructor. + * + * @param PlatformService $providerService + * @param MiscService $miscService + */ + public function __construct(PlatformService $providerService, MiscService $miscService) { + parent::__construct(); + + $this->platformService = $providerService; + $this->miscService = $miscService; + } + + + /** + * + */ + protected function configure() { + parent::configure(); + $this->setName('fulltextsearch:document:platform') + ->setDescription('Get document from index') + ->addArgument('providerId', InputArgument::REQUIRED, 'providerId') + ->addArgument('documentId', InputArgument::REQUIRED, 'documentId') + ->addOption('content', 'c', InputOption::VALUE_NONE, 'return some content'); + } + + + /** + * @param InputInterface $input + * @param OutputInterface $output + * + * @return int|null|void + * @throws Exception + */ + protected function execute(InputInterface $input, OutputInterface $output) { + $providerId = $input->getArgument('providerId'); + $documentId = $input->getArgument('documentId'); + + $platform = $this->platformService->getPlatform(); + + $indexDocument = $platform->getDocument($providerId, $documentId); + $result = [ + 'document' => $indexDocument + ]; + if ($input->getOption('content') === true) { + $result['content'] = substr($indexDocument->getContent(), 0, 200); + } + + $output->writeln(json_encode($result, JSON_PRETTY_PRINT)); + } + + +} + + + diff --git a/lib/Command/DocumentProvider.php b/lib/Command/DocumentProvider.php new file mode 100644 index 0000000..db3999a --- /dev/null +++ b/lib/Command/DocumentProvider.php @@ -0,0 +1,116 @@ +<?php +/** + * 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 OCA\FullTextSearch\Model\ExtendedBase; +use OCA\FullTextSearch\Model\Index; +use OCA\FullTextSearch\Model\IndexDocument; +use OCA\FullTextSearch\Service\MiscService; +use OCA\FullTextSearch\Service\ProviderService; +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 extends ExtendedBase { + + + /** @var ProviderService */ + private $providerService; + + /** @var MiscService */ + private $miscService; + + + /** + * Index constructor. + * + * @param ProviderService $providerService + * @param MiscService $miscService + */ + public function __construct(ProviderService $providerService, MiscService $miscService + ) { + parent::__construct(); + + $this->providerService = $providerService; + $this->miscService = $miscService; + } + + + /** + * + */ + protected function configure() { + parent::configure(); + $this->setName('fulltextsearch:document:provider') + ->setDescription('Get document from index') + ->addArgument('userId', InputArgument::REQUIRED, 'userId') + ->addArgument('providerId', InputArgument::REQUIRED, 'providerId') + ->addArgument('documentId', InputArgument::REQUIRED, 'documentId') + ->addOption('content', 'c', InputOption::VALUE_NONE, 'return some content'); + } + + + /** + * @param InputInterface $input + * @param OutputInterface $output + * + * @return int|null|void + * @throws Exception + */ + protected function execute(InputInterface $input, OutputInterface $output) { + $providerId = $input->getArgument('providerId'); + $documentId = $input->getArgument('documentId'); + $userId = $input->getArgument('userId'); + + $provider = $this->providerService->getProvider($providerId); + + $index = new Index($providerId, $documentId); + $index->setOwnerId($userId); + $index->setStatus(Index::INDEX_FULL); + $indexDocument = $provider->updateDocument($index); + $result = [ + 'document' => $indexDocument + ]; + if ($input->getOption('content') === true) { + $content = $indexDocument->getContent(); + if ($indexDocument->isContentEncoded() === IndexDocument::ENCODED_BASE64) { + $content = base64_decode($content); + } + $result['content'] = substr($content, 0, 200); + } + + $output->writeln(json_encode($result, JSON_PRETTY_PRINT)); + } + + +} + + + |