From 339153942c2b56afef03726caf1d3531bb33bcf4 Mon Sep 17 00:00:00 2001 From: Maxence Lange Date: Fri, 26 Oct 2018 10:10:16 +0200 Subject: compat-nc15 Signed-off-by: Maxence Lange --- lib/Api/v1/FullTextSearch.php | 5 +- lib/AppInfo/Application.php | 23 ++ lib/Command/Check.php | 4 +- lib/Command/Configure.php | 4 +- lib/Command/DocumentPlatform.php | 4 +- lib/Command/DocumentProvider.php | 6 +- lib/Command/Index.php | 27 +- lib/Command/Live.php | 10 +- lib/Command/Reset.php | 6 +- lib/Command/Search.php | 10 +- lib/Command/Stop.php | 4 +- lib/Command/Test.php | 21 +- lib/Controller/ApiController.php | 4 +- lib/Controller/TemplatesController.php | 38 +- lib/Cron/Index.php | 2 - lib/Db/IndexesRequest.php | 18 +- lib/Db/IndexesRequestBuilder.php | 14 +- lib/Db/TickRequest.php | 10 +- lib/Db/TickRequestBuilder.php | 8 +- lib/IFullTextSearchPlatform.php | 151 -------- lib/IFullTextSearchProvider.php | 169 --------- lib/Model/DocumentAccess.php | 192 ---------- lib/Model/ExtendedBase.php | 72 ---- lib/Model/ExtendedIndex.php | 35 -- lib/Model/ExtendedTick.php | 64 ---- lib/Model/Index.php | 122 ++++--- lib/Model/IndexDocument.php | 633 --------------------------------- lib/Model/IndexOptions.php | 70 ++-- lib/Model/PlatformWrapper.php | 10 +- lib/Model/ProviderIndexes.php | 18 +- lib/Model/ProviderWrapper.php | 2 +- lib/Model/Runner.php | 55 +-- lib/Model/SearchRequest.php | 226 +++++++----- lib/Model/SearchResult.php | 131 +++++-- lib/Model/Tick.php | 33 +- lib/Provider/TestProvider.php | 68 ++-- lib/Service/CliService.php | 3 +- lib/Service/ConfigService.php | 4 +- lib/Service/IndexService.php | 115 +++--- lib/Service/PlatformService.php | 6 +- lib/Service/ProviderService.php | 25 +- lib/Service/RunningService.php | 14 +- lib/Service/SearchService.php | 35 +- lib/Service/TestService.php | 14 +- 44 files changed, 687 insertions(+), 1798 deletions(-) delete mode 100644 lib/IFullTextSearchPlatform.php delete mode 100644 lib/IFullTextSearchProvider.php delete mode 100644 lib/Model/DocumentAccess.php delete mode 100644 lib/Model/ExtendedBase.php delete mode 100644 lib/Model/ExtendedIndex.php delete mode 100644 lib/Model/ExtendedTick.php delete mode 100644 lib/Model/IndexDocument.php (limited to 'lib') diff --git a/lib/Api/v1/FullTextSearch.php b/lib/Api/v1/FullTextSearch.php index 6ae451b..5d25f1d 100644 --- a/lib/Api/v1/FullTextSearch.php +++ b/lib/Api/v1/FullTextSearch.php @@ -29,7 +29,6 @@ namespace OCA\FullTextSearch\Api\v1; use OCA\FullTextSearch\Service\ConfigService; use OCA\FullTextSearch\AppInfo\Application; -use OCA\FullTextSearch\Model\ExtendedIndex; use OCA\FullTextSearch\Model\Index; use OCA\FullTextSearch\Service\IndexService; use OCA\FullTextSearch\Service\ProviderService; @@ -97,7 +96,7 @@ class FullTextSearch { * @param string $providerId * @param string|int $documentId * - * @return ExtendedIndex + * @return Index * @throws QueryException */ public static function getIndex($providerId, $documentId) { @@ -189,4 +188,4 @@ class FullTextSearch { ->isProviderIndexed($providerId); } -} \ No newline at end of file +} diff --git a/lib/AppInfo/Application.php b/lib/AppInfo/Application.php index 1b81eec..61122c6 100644 --- a/lib/AppInfo/Application.php +++ b/lib/AppInfo/Application.php @@ -28,9 +28,13 @@ namespace OCA\FullTextSearch\AppInfo; use OCA\FullTextSearch\Capabilities; use OCA\FullTextSearch\Service\ConfigService; +use OCA\FullTextSearch\Service\IndexService; +use OCA\FullTextSearch\Service\ProviderService; +use OCA\FullTextSearch\Service\SearchService; use OCP\AppFramework\App; use OCP\AppFramework\IAppContainer; use OCP\AppFramework\QueryException; +use OCP\FullTextSearch\IFullTextSearchManager; class Application extends App { @@ -59,6 +63,25 @@ class Application extends App { } + /** + * Register Navigation Tab + * + * @throws QueryException + */ + public function registerServices() { + /** @var IFullTextSearchManager $fullTextSearchManager */ + $fullTextSearchManager = $this->container->query(IFullTextSearchManager::class); + + $providerService = $this->container->query(ProviderService::class); + $indexService = $this->container->query(IndexService::class); + $searchService = $this->container->query(SearchService::class); + + $fullTextSearchManager->registerProviderService($providerService); + $fullTextSearchManager->registerIndexService($indexService); + $fullTextSearchManager->registerSearchService($searchService); + } + + /** * Register Navigation Tab * diff --git a/lib/Command/Check.php b/lib/Command/Check.php index 8b3aca1..81ee47f 100644 --- a/lib/Command/Check.php +++ b/lib/Command/Check.php @@ -27,7 +27,7 @@ namespace OCA\FullTextSearch\Command; use Exception; -use OCA\FullTextSearch\Model\ExtendedBase; +use OC\Core\Command\Base; use OCA\FullTextSearch\Service\ConfigService; use OCA\FullTextSearch\Service\MiscService; use OCA\FullTextSearch\Service\PlatformService; @@ -37,7 +37,7 @@ use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; -class Check extends ExtendedBase { +class Check extends Base { /** @var ConfigService */ private $configService; diff --git a/lib/Command/Configure.php b/lib/Command/Configure.php index 7bc71b7..787e8cd 100644 --- a/lib/Command/Configure.php +++ b/lib/Command/Configure.php @@ -27,7 +27,7 @@ namespace OCA\FullTextSearch\Command; use Exception; -use OCA\FullTextSearch\Model\ExtendedBase; +use OC\Core\Command\Base; use OCA\FullTextSearch\Service\ConfigService; use OCA\FullTextSearch\Service\MiscService; use Symfony\Component\Console\Input\InputArgument; @@ -35,7 +35,7 @@ use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; -class Configure extends ExtendedBase { +class Configure extends Base { /** @var ConfigService */ private $configService; diff --git a/lib/Command/DocumentPlatform.php b/lib/Command/DocumentPlatform.php index 72315e0..74ff352 100644 --- a/lib/Command/DocumentPlatform.php +++ b/lib/Command/DocumentPlatform.php @@ -27,7 +27,7 @@ namespace OCA\FullTextSearch\Command; use Exception; -use OCA\FullTextSearch\Model\ExtendedBase; +use OC\Core\Command\Base; use OCA\FullTextSearch\Service\MiscService; use OCA\FullTextSearch\Service\PlatformService; use Symfony\Component\Console\Input\InputArgument; @@ -36,7 +36,7 @@ use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; -class DocumentPlatform extends ExtendedBase { +class DocumentPlatform extends Base { /** @var PlatformService */ diff --git a/lib/Command/DocumentProvider.php b/lib/Command/DocumentProvider.php index 583efc1..93fb3cb 100644 --- a/lib/Command/DocumentProvider.php +++ b/lib/Command/DocumentProvider.php @@ -27,9 +27,9 @@ namespace OCA\FullTextSearch\Command; use Exception; -use OCA\FullTextSearch\Model\ExtendedBase; +use OC\Core\Command\Base; use OCA\FullTextSearch\Model\Index; -use OCA\FullTextSearch\Model\IndexDocument; +use OCP\FullTextSearch\Model\IndexDocument; use OCA\FullTextSearch\Service\MiscService; use OCA\FullTextSearch\Service\ProviderService; use Symfony\Component\Console\Input\InputArgument; @@ -38,7 +38,7 @@ use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; -class DocumentProvider extends ExtendedBase { +class DocumentProvider extends Base { /** @var ProviderService */ diff --git a/lib/Command/Index.php b/lib/Command/Index.php index 2697a81..f6c5105 100644 --- a/lib/Command/Index.php +++ b/lib/Command/Index.php @@ -28,8 +28,7 @@ namespace OCA\FullTextSearch\Command; use Exception; use OCA\FullTextSearch\Exceptions\TickDoesNotExistException; -use OCA\FullTextSearch\IFullTextSearchProvider; -use OCA\FullTextSearch\Model\ExtendedBase; +use OC\Core\Command\Base; use OCA\FullTextSearch\Model\Index as ModelIndex; use OCA\FullTextSearch\Model\IndexOptions; use OCA\FullTextSearch\Model\Runner; @@ -39,6 +38,7 @@ use OCA\FullTextSearch\Service\MiscService; use OCA\FullTextSearch\Service\PlatformService; use OCA\FullTextSearch\Service\ProviderService; use OCA\FullTextSearch\Service\RunningService; +use OCP\FullTextSearch\IFullTextSearchProvider; use OCP\IUserManager; use Symfony\Component\Console\Formatter\OutputFormatterStyle; use Symfony\Component\Console\Input\InputArgument; @@ -47,7 +47,7 @@ use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Terminal; -class Index extends ExtendedBase { +class Index extends Base { // '%job:1s%%message:-40s%%current:6s%/%max:6s% [%bar%] %percent:3s%% \n %duration% %infos:-12s% %jvm:-30s% ' const PANEL_RUN = 'run'; @@ -176,14 +176,6 @@ class Index extends ExtendedBase { } - /** - * @throws Exception - */ - public function interrupted() { - if ($this->hasBeenInterrupted()) { - throw new \Exception('ctrl-c'); - } - } /** @@ -223,7 +215,7 @@ class Index extends ExtendedBase { $this->runner->setInfo('options', json_encode($options)); try { - $this->runner->sourceIsCommandLine($this, $output); + $this->runner->sourceIsCommandLine($output); $this->runner->start(); if ($options->getOption('errors') === 'reset') { @@ -423,9 +415,8 @@ class Index extends ExtendedBase { return false; } - if ($options->getOption('providers', null) !== null - && is_array($options->getOption('providers'))) { - return (in_array($providerId, $options->getOption('providers'))); + if ($options->getOptionArray('providers', []) !== []) { + return (in_array($providerId, $options->getOptionArray('providers'))); } return true; @@ -442,9 +433,8 @@ class Index extends ExtendedBase { return [$this->userManager->get($options->getOption('user'))]; } - if ($options->getOption('users', null) !== null - && is_array($options->getOption('users'))) { - return array_map([$this->userManager, 'get'], $options->getOption('users')); + if ($options->getOptionArray('users', []) !== []) { + return array_map([$this->userManager, 'get'], $options->getOptionArray('users')); } return $this->userManager->search(''); @@ -536,6 +526,7 @@ class Index extends ExtendedBase { $this->cliService->displayPanel('commands', self::PANEL_COMMANDS_ROOT); } + // full list of info that can be edited $this->runner->setInfoArray( [ 'userId' => '', diff --git a/lib/Command/Live.php b/lib/Command/Live.php index f750e18..dc1a187 100644 --- a/lib/Command/Live.php +++ b/lib/Command/Live.php @@ -27,11 +27,10 @@ namespace OCA\FullTextSearch\Command; use Exception; -use OCA\FullTextSearch\Exceptions\InterruptException; +use OC\Core\Command\Base; use OCA\FullTextSearch\Exceptions\TickDoesNotExistException; -use OCA\FullTextSearch\Model\ExtendedBase; -use OCA\FullTextSearch\Model\Runner; use OCA\FullTextSearch\Model\Index as ModelIndex; +use OCA\FullTextSearch\Model\Runner; use OCA\FullTextSearch\Service\CliService; use OCA\FullTextSearch\Service\ConfigService; use OCA\FullTextSearch\Service\IndexService; @@ -46,7 +45,7 @@ use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Terminal; -class Live extends ExtendedBase { +class Live extends Base { const CYCLE_DELAY = 300000; @@ -217,7 +216,7 @@ class Live extends ExtendedBase { try { - $this->runner->sourceIsCommandLine($this, $output); + $this->runner->sourceIsCommandLine($output); $this->runner->start(); $this->cliService->runDisplay($output); @@ -238,7 +237,6 @@ class Live extends ExtendedBase { /** * @throws Exception - * @throws InterruptException * @throws TickDoesNotExistException */ private function liveCycle() { diff --git a/lib/Command/Reset.php b/lib/Command/Reset.php index 2a7cee1..42349e1 100644 --- a/lib/Command/Reset.php +++ b/lib/Command/Reset.php @@ -27,7 +27,7 @@ namespace OCA\FullTextSearch\Command; use Exception; -use OCA\FullTextSearch\Model\ExtendedBase; +use OC\Core\Command\Base; use OCA\FullTextSearch\Model\Runner; use OCA\FullTextSearch\Service\IndexService; use OCA\FullTextSearch\Service\MiscService; @@ -37,7 +37,7 @@ use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; -class Reset extends ExtendedBase { +class Reset extends Base { /** @var IndexService */ private $indexService; @@ -85,7 +85,7 @@ class Reset extends ExtendedBase { protected function execute(InputInterface $input, OutputInterface $output) { try { - $this->runner->sourceIsCommandLine($this, $output); + $this->runner->sourceIsCommandLine($output); $this->runner->start(); $this->runner->output('reset.'); diff --git a/lib/Command/Search.php b/lib/Command/Search.php index b3eab78..bd0ff28 100644 --- a/lib/Command/Search.php +++ b/lib/Command/Search.php @@ -28,11 +28,12 @@ namespace OCA\FullTextSearch\Command; use Exception; use OC\Core\Command\Base; -use OCA\FullTextSearch\Model\IndexDocument; use OCA\FullTextSearch\Model\SearchRequest; use OCA\FullTextSearch\Model\SearchResult; use OCA\FullTextSearch\Service\MiscService; use OCA\FullTextSearch\Service\SearchService; +use OCP\FullTextSearch\Model\IndexDocument; +use OCP\FullTextSearch\Model\ISearchResult; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; @@ -103,8 +104,11 @@ class Search extends Base { } - private function displaySearchResult(SearchResult $searchResult) { - + /** + * @param ISearchResult $searchResult + */ + private function displaySearchResult(ISearchResult $searchResult) { + /** @var SearchResult $searchResult */ echo '> ' . $searchResult->getProvider() ->getName() . "\n"; diff --git a/lib/Command/Stop.php b/lib/Command/Stop.php index 63b039b..a25a568 100644 --- a/lib/Command/Stop.php +++ b/lib/Command/Stop.php @@ -26,14 +26,14 @@ namespace OCA\FullTextSearch\Command; -use OCA\FullTextSearch\Model\ExtendedBase; +use OC\Core\Command\Base; use OCA\FullTextSearch\Service\MiscService; use OCA\FullTextSearch\Service\RunningService; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; -class Stop extends ExtendedBase { +class Stop extends Base { /** @var RunningService */ private $runningService; diff --git a/lib/Command/Test.php b/lib/Command/Test.php index f560b25..c49055c 100644 --- a/lib/Command/Test.php +++ b/lib/Command/Test.php @@ -27,16 +27,13 @@ namespace OCA\FullTextSearch\Command; use Exception; +use OC\Core\Command\Base; use OCA\FullTextSearch\Exceptions\InterruptException; use OCA\FullTextSearch\Exceptions\ProviderDoesNotExistException; use OCA\FullTextSearch\Exceptions\ProviderIsNotCompatibleException; use OCA\FullTextSearch\Exceptions\ProviderIsNotUniqueException; use OCA\FullTextSearch\Exceptions\RunnerAlreadyUpException; use OCA\FullTextSearch\Exceptions\TickDoesNotExistException; -use OCA\FullTextSearch\IFullTextSearchPlatform; -use OCA\FullTextSearch\IFullTextSearchProvider; -use OCA\FullTextSearch\Model\DocumentAccess; -use OCA\FullTextSearch\Model\ExtendedBase; use OCA\FullTextSearch\Model\IndexOptions; use OCA\FullTextSearch\Model\Runner; use OCA\FullTextSearch\Model\SearchRequest; @@ -49,12 +46,15 @@ use OCA\FullTextSearch\Service\ProviderService; use OCA\FullTextSearch\Service\RunningService; use OCA\FullTextSearch\Service\TestService; use OCP\AppFramework\QueryException; +use OCP\FullTextSearch\IFullTextSearchPlatform; +use OCP\FullTextSearch\IFullTextSearchProvider; +use OCP\FullTextSearch\Model\DocumentAccess; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; -class Test extends ExtendedBase { +class Test extends Base { const DELAY_STABILIZE_PLATFORM = 3; @@ -158,7 +158,6 @@ class Test extends ExtendedBase { $this->pause($output, $platformDelay); $this->testContentLicense($output, $testPlatform); $this->testSearchSimple($output, $testPlatform, $testProvider); - $this->testUpdatingDocumentsAccess($output, $testPlatform, $testProvider); $this->pause($output, $platformDelay); $this->testSearchAccess($output, $testPlatform, $testProvider); @@ -255,6 +254,7 @@ class Test extends ExtendedBase { */ private function testMockedProvider($output, IFullTextSearchProvider $testProvider) { $this->output($output, 'Testing mocked provider: get indexable documents.'); + $testProvider->setIndexOptions(new IndexOptions()); $indexableDocuments = $testProvider->generateIndexableDocuments(TestService::DOCUMENT_USER1); $this->output($output, '(' . sizeof($indexableDocuments) . ' items)', false); @@ -337,8 +337,7 @@ class Test extends ExtendedBase { * @param IFullTextSearchPlatform $testPlatform * @param IFullTextSearchProvider $testProvider * - * @throws InterruptException - * @throws TickDoesNotExistException + * @throws Exception */ private function testIndexingDocuments( OutputInterface $output, IFullTextSearchPlatform $testPlatform, @@ -386,7 +385,8 @@ class Test extends ExtendedBase { $this->output($output, 'Comparing document with source.'); $this->testService->compareIndexDocument( - $this->testService->generateIndexDocumentContentLicense(), $indexDocument + $this->testService->generateIndexDocumentContentLicense(new IndexOptions()), + $indexDocument ); $this->output($output, true); } @@ -447,8 +447,7 @@ class Test extends ExtendedBase { * @param IFullTextSearchPlatform $testPlatform * @param IFullTextSearchProvider $testProvider * - * @throws InterruptException - * @throws TickDoesNotExistException + * @throws Exception */ private function testUpdatingDocumentsAccess( OutputInterface $output, IFullTextSearchPlatform $testPlatform, diff --git a/lib/Controller/ApiController.php b/lib/Controller/ApiController.php index e5a2ca5..1c3b0e4 100644 --- a/lib/Controller/ApiController.php +++ b/lib/Controller/ApiController.php @@ -102,7 +102,7 @@ class ApiController extends Controller { */ private function searchDocuments(SearchRequest $request) { try { - $result = $this->searchService->search(null, $request); + $result = $this->searchService->search('', $request); return $this->success( [ @@ -150,4 +150,4 @@ class ApiController extends Controller { ); } -} \ No newline at end of file +} diff --git a/lib/Controller/TemplatesController.php b/lib/Controller/TemplatesController.php index 9aea5c7..5364e20 100644 --- a/lib/Controller/TemplatesController.php +++ b/lib/Controller/TemplatesController.php @@ -30,7 +30,6 @@ use Exception; use OC\AppFramework\Http; use OCA\FullTextSearch\AppInfo\Application; use OCA\FullTextSearch\Exceptions\ProviderDoesNotExistException; -use OCA\FullTextSearch\IFullTextSearchProvider; use OCA\FullTextSearch\Service\ConfigService; use OCA\FullTextSearch\Service\MiscService; use OCA\FullTextSearch\Service\ProviderService; @@ -42,6 +41,7 @@ use OCP\IRequest; class TemplatesController extends Controller { + /** @var IConfig */ private $config; @@ -90,19 +90,22 @@ class TemplatesController extends Controller { $providerWrapper = $this->providerService->getProvider($providerId); $provider = $providerWrapper->getProvider(); - $panel = []; - $options = $provider->getOptionsTemplate(); - if (is_array($options) && array_key_exists('panel', $options)) { - $panel = $options['panel']; - } + $searchTemplate = $provider->getSearchTemplate(); - if (array_key_exists('template', $panel)) { + $template = ''; + if ($searchTemplate->getTemplate() !== '') { $tmpl = - new TemplateResponse($providerWrapper->getAppId(), $panel['template'], [], 'blank'); - $panel['template'] = $tmpl->render(); + new TemplateResponse( + $providerWrapper->getAppId(), $searchTemplate->getTemplate(), [], 'blank' + ); + $template = $tmpl->render(); } - $ret[$providerId] = $panel; + $ret[$providerId] = + [ + 'options' => $searchTemplate->getPanelOptions(), + 'template' => $template + ]; return new DataResponse($ret, Http::STATUS_OK); } @@ -123,17 +126,14 @@ class TemplatesController extends Controller { $provider = $providerWrapper->getProvider(); $providerAppId = $providerWrapper->getAppId(); - $options = $provider->getOptionsTemplate(); - $nav = []; - if (is_array($options) && array_key_exists('navigation', $options)) { - $nav = $options['navigation']; - } - + $searchTemplate = $provider->getSearchTemplate(); $ret[$providerAppId] = [ - 'provider' => $provider->getId(), - 'title' => $provider->getName(), - 'navigation' => $nav + 'provider' => $provider->getId(), + 'title' => $provider->getName(), + 'options' => $searchTemplate->getNavigationOptions(), + 'css' => $searchTemplate->getCss(), + 'icon' => $searchTemplate->getIcon() ]; } diff --git a/lib/Cron/Index.php b/lib/Cron/Index.php index 729d54e..4cf8497 100644 --- a/lib/Cron/Index.php +++ b/lib/Cron/Index.php @@ -30,7 +30,6 @@ namespace OCA\FullTextSearch\Cron; use Exception; use OC\BackgroundJob\TimedJob; use OCA\FullTextSearch\AppInfo\Application; -use OCA\FullTextSearch\Exceptions\InterruptException; use OCA\FullTextSearch\Model\Runner; use OCA\FullTextSearch\Service\ConfigService; use OCA\FullTextSearch\Service\IndexService; @@ -105,7 +104,6 @@ class Index extends TimedJob { /** * @throws Exception - * @throws InterruptException */ private function liveCycle() { diff --git a/lib/Db/IndexesRequest.php b/lib/Db/IndexesRequest.php index edb7eac..2eb225c 100644 --- a/lib/Db/IndexesRequest.php +++ b/lib/Db/IndexesRequest.php @@ -28,9 +28,9 @@ namespace OCA\FullTextSearch\Db; use OCA\FullTextSearch\Exceptions\IndexDoesNotExistException; -use OCA\FullTextSearch\IFullTextSearchProvider; -use OCA\FullTextSearch\Model\ExtendedIndex; use OCA\FullTextSearch\Model\Index; +use OCP\FullTextSearch\IFullTextSearchProvider; +use OCP\FullTextSearch\Model\IIndex; class IndexesRequest extends IndexesRequestBuilder { @@ -103,7 +103,7 @@ class IndexesRequest extends IndexesRequestBuilder { /** - * @return ExtendedIndex[] + * @return Index[] */ public function getErrorIndexes() { @@ -171,9 +171,9 @@ class IndexesRequest extends IndexesRequestBuilder { /** - * @param Index $index + * @param IIndex $index */ - public function deleteIndex(Index $index) { + public function deleteIndex(IIndex $index) { $qb = $this->getIndexesDeleteSql(); $this->limitToProviderId($qb, $index->getProviderId()); $this->limitToDocumentId($qb, $index->getDocumentId()); @@ -209,10 +209,10 @@ class IndexesRequest extends IndexesRequestBuilder { * @param string $providerId * @param string|int $documentId * - * @return ExtendedIndex + * @return Index * @throws IndexDoesNotExistException */ - public function getIndex($providerId, $documentId) { + public function getIndex($providerId, $documentId): Index { $qb = $this->getIndexesSelectSql(); $this->limitToProviderId($qb, $providerId); $this->limitToDocumentId($qb, $documentId); @@ -235,7 +235,7 @@ class IndexesRequest extends IndexesRequestBuilder { * @param string $providerId * @param array $documentIds * - * @return ExtendedIndex[] + * @return Index[] * @throws IndexDoesNotExistException */ public function getIndexes($providerId, $documentIds) { @@ -303,4 +303,4 @@ class IndexesRequest extends IndexesRequestBuilder { } -} \ No newline at end of file +} diff --git a/lib/Db/IndexesRequestBuilder.php b/lib/Db/IndexesRequestBuilder.php index 3f68e16..0eb47c2 100644 --- a/lib/Db/IndexesRequestBuilder.php +++ b/lib/Db/IndexesRequestBuilder.php @@ -27,7 +27,7 @@ namespace OCA\FullTextSearch\Db; -use OCA\FullTextSearch\Model\ExtendedIndex; +use OCA\FullTextSearch\Model\Index; use OCA\FullTextSearch\Service\ConfigService; use OCA\FullTextSearch\Service\MiscService; use OCP\DB\QueryBuilder\IQueryBuilder; @@ -113,19 +113,19 @@ class IndexesRequestBuilder extends CoreRequestBuilder { /** * @param array $data * - * @return ExtendedIndex + * @return Index */ protected function parseIndexesSelectSql($data) { - $index = new ExtendedIndex($data['provider_id'], $data['document_id']); + $index = new Index($data['provider_id'], $data['document_id']); $index->setStatus($data['status']) ->setSource($data['source']) - ->setOptions(json_decode($data['options'], true)) - ->setErrorCount($data['err']) - ->setErrors(json_decode($data['message'], true)) ->setOwnerId($data['owner_id']) ->setLastIndex($data['indexed']); + $index->setOptions(json_decode($data['options'], true)); + $index->setErrorCount($data['err']); + $index->setErrors(json_decode($data['message'], true)); return $index; } -} \ No newline at end of file +} diff --git a/lib/Db/TickRequest.php b/lib/Db/TickRequest.php index ba6dfe5..4338450 100644 --- a/lib/Db/TickRequest.php +++ b/lib/Db/TickRequest.php @@ -28,9 +28,9 @@ namespace OCA\FullTextSearch\Db; use OCA\FullTextSearch\Exceptions\TickDoesNotExistException; -use OCA\FullTextSearch\Model\ExtendedTick; use OCA\FullTextSearch\Model\Tick; + class TickRequest extends TickRequestBuilder { @@ -114,7 +114,7 @@ class TickRequest extends TickRequestBuilder { * * @param int $id * - * @return ExtendedTick + * @return Tick * @throws TickDoesNotExistException */ public function getTickById($id) { @@ -138,7 +138,7 @@ class TickRequest extends TickRequestBuilder { * * @param string $status * - * @return ExtendedTick[] + * @return Tick[] */ public function getTickByStatus($status) { @@ -160,7 +160,7 @@ class TickRequest extends TickRequestBuilder { /** * @param string $source * - * @return ExtendedTick[] + * @return Tick[] */ public function getTickBySource($source) { $qb = $this->getTickSelectSql(); @@ -177,4 +177,4 @@ class TickRequest extends TickRequestBuilder { } -} \ No newline at end of file +} diff --git a/lib/Db/TickRequestBuilder.php b/lib/Db/TickRequestBuilder.php index bbce090..cd3cf09 100644 --- a/lib/Db/TickRequestBuilder.php +++ b/lib/Db/TickRequestBuilder.php @@ -27,7 +27,7 @@ namespace OCA\FullTextSearch\Db; -use OCA\FullTextSearch\Model\ExtendedTick; +use OCA\FullTextSearch\Model\Tick; use OCA\FullTextSearch\Service\ConfigService; use OCA\FullTextSearch\Service\MiscService; use OCP\DB\QueryBuilder\IQueryBuilder; @@ -111,10 +111,10 @@ class TickRequestBuilder extends CoreRequestBuilder { /** * @param array $data * - * @return ExtendedTick + * @return Tick */ protected function parseTickSelectSql($data) { - $tick = new ExtendedTick($data['source'], $data['id']); + $tick = new Tick($data['source'], $data['id']); $tick->setData(json_decode($data['data'], true)) ->setTick($data['tick']) ->setFirstTick($data['first_tick']) @@ -124,4 +124,4 @@ class TickRequestBuilder extends CoreRequestBuilder { return $tick; } -} \ No newline at end of file +} diff --git a/lib/IFullTextSearchPlatform.php b/lib/IFullTextSearchPlatform.php deleted file mode 100644 index 947394f..0000000 --- a/lib/IFullTextSearchPlatform.php +++ /dev/null @@ -1,151 +0,0 @@ - - * @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; - - -use OCA\FullTextSearch\Model\DocumentAccess; -use OCA\FullTextSearch\Model\Index; -use OCA\FullTextSearch\Model\IndexDocument; -use OCA\FullTextSearch\Model\Runner; -use OCA\FullTextSearch\Model\SearchRequest; -use OCA\FullTextSearch\Model\SearchResult; - -interface IFullTextSearchPlatform { - - /** - * must returns a unique Id - * - * @return string - */ - public function getId(); - - - /** - * @return string - */ - public function getName(); - - - /** - * @return array - */ - public function getConfiguration(); - - - /** - * @param Runner $runner - */ - public function setRunner(Runner $runner); - - - /** - * Load the search platform - */ - public function loadPlatform(); - - - /** - * test the search platform - */ - public function testPlatform(); - - - /** - * Init an index regarding a provider - */ - public function initializeIndex(); - - - /** - * Reset the indexes - * - * @param string $providerId - */ - public function resetIndex($providerId); - - - /** - * Reset indexes - * - * @param Index[] $indexes - */ - public function deleteIndexes($indexes); - - - // DEPRECATED ! -// /** -// * $command can be null. instanceof ExtendedBase if the method is called from CLI. -// * Use it to echo whatever and intercept ^C -// * -// * @deprecated -// * @param IFullTextSearchProvider $provider -// * @param IndexDocument[] $documents -// * -// * @return Index[] -// */ -// public function indexDocuments(IFullTextSearchProvider $provider, $documents); - - - /** - * @param IFullTextSearchProvider $provider - * @param IndexDocument $document - * - * @return Index - */ - public function indexDocument(IFullTextSearchProvider $provider, IndexDocument $document); - - - /** - * @param IFullTextSearchProvider $provider - * @param DocumentAccess $access - * @param SearchRequest $request - * - * @return SearchResult - */ - public function searchDocuments( - IFullTextSearchProvider $provider, DocumentAccess $access, SearchRequest $request - ); - - -// /** -// * @param SearchRequest $request -// * @param DocumentAccess $access -// * @param SearchResult $result -// * -// * @return SearchResult -// */ -// public function searchRequest(SearchResult $result, DocumentAccess $access); - - -// /** -// * @param string $providerId -// * @param string $documentId -// * -// * @return IndexDocument -// */ -// public function getDocument($providerId, $documentId); -} diff --git a/lib/IFullTextSearchProvider.php b/lib/IFullTextSearchProvider.php deleted file mode 100644 index 57089ba..0000000 --- a/lib/IFullTextSearchProvider.php +++ /dev/null @@ -1,169 +0,0 @@ - - * @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; - -use OC\User\NoUserException; -use OCA\FullTextSearch\Model\Index; -use OCA\FullTextSearch\Model\IndexDocument; -use OCA\FullTextSearch\Model\IndexOptions; -use OCA\FullTextSearch\Model\Runner; -use OCA\FullTextSearch\Model\SearchRequest; -use OCA\FullTextSearch\Model\SearchResult; - -interface IFullTextSearchProvider { - - - /** - * return a unique Id of the Provider - * - * @return string - */ - public function getId(); - - - /** - * return a display name of the Provider - * - * @return string - */ - public function getName(); - - - /** - * @return array - */ - public function getConfiguration(); - - - /** - * @return array|string - */ - public function getOptionsTemplate(); - - - /** - * Called when loading the provider - */ - public function loadProvider(); - - - /** - * @param Runner $runner - */ - public function setRunner(Runner $runner); - - -// /** -// * @param IndexOptions $options -// */ -// public function setIndexOptions($options); - - - /** - * returns all indexable document for a user. - * There is no need to fill the document with content at this point. - * - * @param string $userId - * - * @return IndexDocument[] - */ - public function generateIndexableDocuments($userId); - - - /** - * fill a chunk of documents with more content, prior to index. - * - * @deprecated - * - * @param IndexDocument[] $chunk - * - * @return IndexDocument[] - */ - public function fillIndexDocuments($chunk); - - - /** - * fill document with more content, prior to index. - * - * @param IndexDocument $document - */ -// public function fillIndexDocument($document); - - - /** - * @param IndexDocument $document - * - * @return bool - */ - public function isDocumentUpToDate($document); - - - /** - * update a document regarding the current Index' status - * - * @param Index $index - * - * @return IndexDocument - * @throws NoUserException - */ - public function updateDocument(Index $index); - - - /** - * @param IFullTextSearchPlatform $platform - */ - public function onInitializingIndex(IFullTextSearchPlatform $platform); - - - /** - * @param IFullTextSearchPlatform $platform - */ - public function onResettingIndex(IFullTextSearchPlatform $platform); - - - /** - * before a search, improve the request - * - * @param SearchRequest $searchRequest - */ - public function improveSearchRequest(SearchRequest $searchRequest); - - - /** - * after a search, improve the result - * - * @param SearchResult $searchResult - */ - public function improveSearchResult(SearchResult $searchResult); - - - /** - * not used yet. - */ - public function unloadProvider(); - -} diff --git a/lib/Model/DocumentAccess.php b/lib/Model/DocumentAccess.php deleted file mode 100644 index 7c61b53..0000000 --- a/lib/Model/DocumentAccess.php +++ /dev/null @@ -1,192 +0,0 @@ - - * @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\Model; - - -class DocumentAccess implements \JsonSerializable { - - /** @var string */ - private $ownerId; - - /** @var string */ - private $viewerId; - - /** @var array */ - private $users = []; - - /** @var array */ - private $groups = []; - - /** @var array */ - private $circles = []; - - /** @var array */ - private $links = []; - - /** - * DocumentAccess constructor. - * - * @param string $ownerId - */ - public function __construct($ownerId = '') { - $this->setOwnerId($ownerId); - } - - - /** - * @param $ownerId - * - * @return $this - */ - public function setOwnerId($ownerId) { - if ($ownerId === false) { - $ownerId = ''; - } - $this->ownerId = $ownerId; - - return $this; - } - - - /** - * @return string - */ - public function getOwnerId() { - return $this->ownerId; - } - - - /** - * @param string $viewerId - */ - public function setViewerId($viewerId) { - $this->viewerId = $viewerId; - } - - /** - * @return string - */ - public function getViewerId() { - return $this->viewerId; - } - - - /** - * @param array $users - */ - public function setUsers($users) { - $this->users = $users; - } - - /** - * @return array - */ - public function getUsers() { - return $this->users; - } - - /** - * @param array $users - */ - public function addUsers($users) { - $this->users = array_merge($this->users, $users); - } - - - /** - * @param array $groups - */ - public function setGroups($groups) { - $this->groups = $groups; - } - - /** - * @return array - */ - public function getGroups() { - return $this->groups; - } - - - /** - * @param array $groups - */ - public function addGroups($groups) { - $this->groups = array_merge($this->groups, $groups); - } - - - /** - * @param array $circles - */ - public function setCircles($circles) { - $this->circles = $circles; - } - - /** - * @return array - */ - public function getCircles() { - return $this->circles; - } - - /** - * @param array $circles - */ - public function addCircles($circles) { - $this->circles = array_merge($this->circles, $circles); - } - - /** - * @param array $links - */ - public function setLinks($links) { - $this->links = $links; - } - - /** - * @return array - */ - public function getLinks() { - return $this->links; - } - - - /** - * - */ - public function jsonSerialize() { - return [ - 'ownerId' => $this->getOwnerId(), - 'viewerId' => $this->getViewerId(), - 'users' => $this->getUsers(), - 'groups' => $this->getGroups(), - 'circles' => $this->getCircles(), - 'links' => $this->getLinks() - ]; - } -} \ No newline at end of file diff --git a/lib/Model/ExtendedBase.php b/lib/Model/ExtendedBase.php deleted file mode 100644 index b808f4f..0000000 --- a/lib/Model/ExtendedBase.php +++ /dev/null @@ -1,72 +0,0 @@ - - * @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\Model; - -use OC\Core\Command\Base; -use OCA\FullTextSearch\Exceptions\InterruptException; -use Symfony\Component\Console\Output\OutputInterface; - - -class ExtendedBase extends Base { - - /** @var OutputInterface */ - private $output; - - public function __construct() { - parent::__construct(); - } - - - /** - * @return bool|void - * @throws InterruptException - */ - public function hasBeenInterrupted() { - if (parent::hasBeenInterrupted()) { - throw new InterruptException('Interrupted by user.'); - } - } -// -// -// /** -// * @param OutputInterface $output -// * -// * @deprecated -// */ -// public function setOutput(OutputInterface $output) { -// $this->output = $output; -// } -// -// /** -// * @return OutputInterface -// * @deprecated -// */ -// public function getOutput() { -// return $this->output; -// } -} \ No newline at end of file diff --git a/lib/Model/ExtendedIndex.php b/lib/Model/ExtendedIndex.php deleted file mode 100644 index a26377e..0000000 --- a/lib/Model/ExtendedIndex.php +++ /dev/null @@ -1,35 +0,0 @@ - - * @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\Model; - - -class ExtendedIndex extends Index { - - - -} \ No newline at end of file diff --git a/lib/Model/ExtendedTick.php b/lib/Model/ExtendedTick.php deleted file mode 100644 index 8c70c6c..0000000 --- a/lib/Model/ExtendedTick.php +++ /dev/null @@ -1,64 +0,0 @@ - - * @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\Model; - - -class ExtendedTick extends Tick { - - /** - * @param string $key - * @param string|int $value - * - * @return $this - */ - public function setInfo($key, $value) { - $this->data[$key] = $value; - - return $this; - } - - public function unsetInfo($key) { - unset($this->data[$key]); - } - - /** - * @param $key - * @param int|string $default - * - * @return int|string - */ - public function getInfo($key, $default = '') { - if (!array_key_exists($key, $this->data)) { - return $default; - } - - return $this->data[$key]; - - } - -} \ No newline at end of file diff --git a/lib/Model/Index.php b/lib/Model/Index.php index ebb69da..34ba9dc 100644 --- a/lib/Model/Index.php +++ b/lib/Model/Index.php @@ -1,6 +1,9 @@ providerId = $providerId; $this->documentId = $documentId; } @@ -92,14 +80,14 @@ class Index implements \JsonSerializable { /** * @return string */ - public function getProviderId() { + public function getProviderId(): string { return $this->providerId; } /** * @return string */ - public function getDocumentId() { + public function getDocumentId(): string { return $this->documentId; } @@ -107,9 +95,9 @@ class Index implements \JsonSerializable { /** * @param string $source * - * @return $this + * @return IIndex */ - public function setSource($source) { + public function setSource(string $source): IIndex { $this->source = $source; return $this; @@ -118,7 +106,7 @@ class Index implements \JsonSerializable { /** * @return string */ - public function getSource() { + public function getSource(): string { return $this->source; } @@ -126,9 +114,9 @@ class Index implements \JsonSerializable { /** * @param string $ownerId * - * @return $this + * @return IIndex */ - public function setOwnerId($ownerId) { + public function setOwnerId(string $ownerId): IIndex { $this->ownerId = $ownerId; return $this; @@ -137,7 +125,7 @@ class Index implements \JsonSerializable { /** * @return string */ - public function getOwnerId() { + public function getOwnerId(): string { return $this->ownerId; } @@ -146,9 +134,9 @@ class Index implements \JsonSerializable { * @param int $status * @param bool $reset * - * @return $this + * @return IIndex */ - public function setStatus($status, $reset = false) { + public function setStatus(int $status, bool $reset = false): IIndex { if ($reset === true) { $this->status = $status; } else if (!$this->isStatus($status)) { @@ -161,7 +149,7 @@ class Index implements \JsonSerializable { /** * @return int */ - public function getStatus() { + public function getStatus(): int { return $this->status; } @@ -170,29 +158,33 @@ class Index implements \JsonSerializable { * * @return bool */ - public function isStatus($status) { - return ((int)$status & $this->getStatus()); + public function isStatus(int $status): bool { + return (bool)((int)$status & $this->getStatus()); } /** * @param int $status + * + * @return IIndex */ - public function unsetStatus($status) { + public function unsetStatus(int $status): IIndex { if (!$this->isStatus($status)) { - return; + return $this; } $this->status -= $status; + + return $this; } /** * @param string $option - * @param string|int $value + * @param string $value * - * @return $this + * @return IIndex */ - public function addOption($option, $value) { + public function addOption(string $option, string $value): IIndex { $this->options[$option] = $value; return $this; @@ -202,9 +194,9 @@ class Index implements \JsonSerializable { * @param string $option * @param int $value * - * @return $this + * @return IIndex */ - public function addOptionInt($option, $value) { + public function addOptionInt(string $option, int $value): IIndex { $this->options[$option] = $value; return $this; @@ -214,9 +206,9 @@ class Index implements \JsonSerializable { /** * @param array $options * - * @return $this + * @return IIndex */ - public function setOptions($options) { + public function setOptions(array $options): IIndex { $this->options = $options; return $this; @@ -225,7 +217,7 @@ class Index implements \JsonSerializable { /** * @return array */ - public function getOptions() { + public function getOptions(): array { return $this->options; } @@ -236,7 +228,7 @@ class Index implements \JsonSerializable { * * @return string */ - public function getOption($option, $default = '') { + public function getOption(string $option, string $default = ''): string { if (!array_key_exists($option, $this->options)) { return $default; } @@ -245,14 +237,13 @@ class Index implements \JsonSerializable { } - /** * @param string $option * @param int $default * * @return int */ - public function getOptionInt($option, $default = 0) { + public function getOptionInt(string $option, int $default = 0): int { if (!array_key_exists($option, $this->options)) { return $default; } @@ -263,9 +254,9 @@ class Index implements \JsonSerializable { /** * @param int $err * - * @return $this + * @return IIndex */ - public function setErrorCount($err) { + public function setErrorCount(int $err): IIndex { $this->err = $err; return $this; @@ -274,14 +265,14 @@ class Index implements \JsonSerializable { /** * @return int */ - public function getErrorCount() { + public function getErrorCount(): int { return $this->err; } /** * @return array */ - public function getLastError() { + public function getLastError(): array { return array_values(array_slice($this->errors, -1))[0]; } @@ -289,24 +280,26 @@ class Index implements \JsonSerializable { /** * */ - public function resetErrors() { + public function resetErrors(): IIndex { $this->setErrors([]); $this->setErrorCount(0); + + return $this; } /** * @return array */ - public function getErrors() { + public function getErrors(): array { return $this->errors; } /** * @param array $messages * - * @return Index + * @return IIndex */ - public function setErrors($messages) { + public function setErrors(array $messages): IIndex { $this->errors = $messages; return $this; @@ -317,24 +310,29 @@ class Index implements \JsonSerializable { * @param string $message * @param string $exception * @param int $sev + * + * @return IIndex */ - public function addError($message, $exception = '', $sev = self::ERROR_SEV_3) { + public function addError(string $message, string $exception = '', int $sev = IIndex::ERROR_SEV_3 + ): IIndex { $this->errors[] = [ - 'message' => substr($message, 0, 1800), + 'message' => substr($message, 0, 1800), 'exception' => $exception, - 'severity' => $sev + 'severity' => $sev ]; $this->err++; + + return $this; } /** * @param int $lastIndex * - * @return $this + * @return IIndex */ - public function setLastIndex($lastIndex = -1) { + public function setLastIndex(int $lastIndex = -1): IIndex { if ($lastIndex === -1) { $lastIndex = time(); } @@ -347,7 +345,7 @@ class Index implements \JsonSerializable { /** * @return int */ - public function getLastIndex() { + public function getLastIndex(): int { return $this->lastIndex; } @@ -381,4 +379,4 @@ class Index implements \JsonSerializable { unset($this->lastIndex); } -} \ No newline at end of file +} diff --git a/lib/Model/IndexDocument.php b/lib/Model/IndexDocument.php deleted file mode 100644 index 12a011c..0000000 --- a/lib/Model/IndexDocument.php +++ /dev/null @@ -1,633 +0,0 @@ - - * @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\Model; - -class IndexDocument implements \JsonSerializable { - - const NOT_ENCODED = 0; - const ENCODED_BASE64 = 1; - - /** @var string|int */ - protected $id; - - /** @var string */ - protected $providerId; - - /** @var DocumentAccess */ - protected $access; - - /** @var Index */ - protected $index; - - /** @var int */ - protected $modifiedTime = 0; - - /** @var string */ - protected $source = ''; - - /** @var array */ - protected $tags = []; - - /** @var array */ - protected $metaTags = []; - - /** @var array */ - protected $subTags = []; - - /** @var string */ - protected $title = ''; - - /** @var string */ - protected $content = null; - - /** @var string */ - protected $hash = ''; - - /** @var array */ - protected $parts = []; - - /** @var string */ - protected $link = ''; - - /** @var array */ - protected $more = []; - - /** @var array */ - protected $excerpts = []; - - /** @var string */ - protected $score; - - /** @var array */ - protected $info = []; - - /** @var int */ - protected $contentEncoded; - - - public function __construct($providerId, $id) { - $this->providerId = $providerId; - $this->id = $id; - } - - -// /** -// * @param string|integer $id -// * -// * @return $this -// */ -// public function setId($id) { -// $this->id = $id; -// -// return $this; -// } - - /** - * @return string|integer - */ - public function getId() { - return $this->id; - } - - -// /** -// * @param string $providerId -// * -// * @return $this -// */ -// public function setProviderId($providerId) { -// $this->providerId = $providerId; -// -// return $this; -// } - - /** - * @return string - */ - public function getProviderId() { - return $this->providerId; - } - - - /** - * @param Index $index - */ - public function setIndex(Index $index) { - $this->index = $index; - } - - /** - * @return Index - */ - public function getIndex() { - return $this->index; - } - - - /** - * @param int $modifiedTime - * - * @return $this - */ - public function setModifiedTime($modifiedTime) { - $this->modifiedTime = $modifiedTime; - - return $this; - } - - /** - * @return int - */ - public function getModifiedTime() { - return $this->modifiedTime; - } - - /** - * @param int $time - * - * @return bool - */ - public function isOlderThan($time) { - return ($this->modifiedTime < $time); - } - - - /** - * @param DocumentAccess $access - * - * @return $this - */ - public function setAccess(DocumentAccess $access) { - $this->access = $access; - - return $this; - } - - /** - * @return DocumentAccess - */ - public function getAccess() { - return $this->access; - } - - - /** - * @param array $tags - * - * @return $this - */ - public function setTags($tags) { - $this->tags = $tags; - - return $this; - } - - /** - * @return array - */ - public function getTags() { - return $this->tags; - } - - /** - * @param $tag - * - * @return $this - */ - public function addTag($tag) { - $this->tags[] = $tag; - - return $this; - } - - - /** - * @param array $tags - * - * @return $this - */ - public function setMetaTags($tags) { - $this->metaTags = $tags; - - return $this; - } - - /** - * @return array - */ - public function getMetaTags() { - return $this->metaTags; - } - - /** - * @param $tags - * - * @return $this - */ - public function addMetaTag($tags) { - $this->metaTags[] = $tags; - - return $this; - } - - - /** - * @param array $tags - * - * @return $this - */ - public function setSubTags($tags) { - $this->subTags = $tags; - - return $this; - } - - /** - * @param bool $formatted - * - * @return array - */ - public function getSubTags($formatted = false) { - if ($formatted === false) { - return $this->subTags; - } - - $subTags = []; - $ak = array_keys($this->subTags); - foreach ($ak as $source) { - $tags = $this->subTags[$source]; - foreach ($tags as $tag) { - $subTags[] = $source . '_' . $tag; - } - } - - return $subTags; - } - - /** - * @param string $k - * @param string $tag - * - * @return $this - */ - public function addSubTag($k, $tag) { - $this->subTags[$k] = $tag; - - return $this; - } - - - /** - * @return string - */ - public function getSource() { - return $this->source; - } - - /** - * @param string $source - * - * @return $this - */ - public function setSource($source) { - $this->source = $source; - - return $this; - } - - - /** - * @param string $title - * - * @return $this - */ - public function setTitle($title) { - $this->title = $title; - - return $this; - } - - /** - * @return string - */ - public function getTitle() { - return $this->title; - } - - - /** - * @param string $content - * @param int $encoded - * - * @return $this - */ - public function setContent($content, $encoded = 0) { - $this->content = $content; - $this->contentEncoded = $encoded; - - return $this; - } - - /** - * @return string - */ - public function getContent() { - return $this->content; - } - - /** - * @return int - */ - public function getContentSize() { - return strlen($this->getContent()); - } - - - /** - * @return $this - */ - public function initHash() { - if ($this->getContent() === '' || is_null($this->getContent())) { - return $this; - } - - $this->hash = hash("md5", $this->getContent()); - - return $this; - } - - /** - * @param $hash - * - * @return $this - */ - public function setHash($hash) { - $this->hash = $hash; - - return $this; - } - - /** - * @return string - */ - public function getHash() { - return $this->hash; - } - - - /** - * @param string $part - * @param string $content - * - * @return $this - */ - public function addPart($part, $content) { - $this->parts[$part] = $content; - - return $this; - } - - /** - * @param array $parts - * - * @return $this - */ - public function setParts($parts) { - $this->parts = $parts; - - return $this; - } - - /** - * @return array - */ - public function getParts() { - return $this->parts; - } - - - /** - * @return int - */ - public function isContentEncoded() { - return $this->contentEncoded; - } - - - /** - * @param string $link - * - * @return $this - */ - public function setLink($link) { - $this->link = $link; - - return $this; - } - - /** - * @return string - */ - public function getLink() { - return $this->link; - } - - - /** - * @param array $more - * - * @return $this - */ - public function setMore($more) { - $this->more = $more; - - return $this; - } - - /** - * @return array - */ - public function getMore() { - return $this->more; - } - - - /** - * @param array $excerpts - * - * @return $this - */ - public function setExcerpts($excerpts) { - $excerpts = array_map([$this, 'cleanExcerpt'], $excerpts); - - $this->excerpts = $excerpts; - - return $this; - } - - /** - * @return array - */ - public function getExcerpts() { - return $this->excerpts; - } - - /** - * @param string $excerpt - */ - public function addExcerpt($excerpt) { - $excerpt = $this->cleanExcerpt($excerpt); - - $this->excerpts[] = $excerpt; - } - - /** - * @param $excerpt - * - * @return mixed - */ - public function cleanExcerpt($excerpt) { - $excerpt = str_replace("\\n", ' ', $excerpt); - $excerpt = str_replace("\\r", ' ', $excerpt); - $excerpt = str_replace("\\t", ' ', $excerpt); - $excerpt = str_replace("\n", ' ', $excerpt); - $excerpt = str_replace("\r", ' ', $excerpt); - $excerpt = str_replace("\t", ' ', $excerpt); - - return $excerpt; - } - - /** - * @param string $score - * - * @return $this - */ - public function setScore($score) { - $this->score = $score; - - return $this; - } - - /** - * @return string - */ - public function getScore() { - return $this->score; - } - - - /** - * @param string $info - * @param mixed $value - * - * @return $this - */ - public function setInfo($info, $value) { - $this->info[$info] = $value; - - return $this; - } - - /** - * @param string $info - * @param mixed $default - * - * @return mixed - */ - public function getInfo($info, $default = '') { - if (!key_exists($info, $this->info)) { - return $default; - } - - return $this->info[$info]; - } - - - /** - * @return array - */ - public function getInfoAll() { - - $info = []; - foreach ($this->info as $k => $v) { - if (substr($k, 0, 1) === '_') { - continue; - } - - $info[$k] = $v; - } - - return $info; - } - - - public function __destruct() { - unset($this->id); - unset($this->providerId); - unset($this->access); - unset($this->modifiedTime); - unset($this->title); - unset($this->content); - unset($this->hash); - unset($this->link); - unset($this->source); - unset($this->tags); - unset($this->metaTags); - unset($this->subTags); - unset($this->more); - unset($this->excerpts); - unset($this->score); - unset($this->info); - unset($this->contentEncoded); - } - - /** - * @return array - */ - public function jsonSerialize() { - return [ - 'id' => $this->getId(), - 'providerId' => $this->getProviderId(), - 'access' => $this->getAccess(), - 'modifiedTime' => $this->getModifiedTime(), - 'title' => $this->getTitle(), - 'link' => $this->getLink(), - 'index' => $this->getIndex(), - 'source' => $this->getSource(), - 'info' => $this->getInfoAll(), - 'hash' => $this->getHash(), - 'contentSize' => $this->getContentSize(), - 'tags' => $this->getTags(), - 'metatags' => $this->getMetaTags(), - 'subtags' => $this->getSubTags(), - 'more' => $this->getMore(), - 'excerpts' => $this->getExcerpts(), - 'score' => $this->getScore() - ]; - } - -} \ No newline at end of file diff --git a/lib/Model/IndexOptions.php b/lib/Model/IndexOptions.php index 2c5456e..1261bab 100644 --- a/lib/Model/IndexOptions.php +++ b/lib/Model/IndexOptions.php @@ -27,7 +27,10 @@ namespace OCA\FullTextSearch\Model; -class IndexOptions implements \JsonSerializable { +use JsonSerializable; +use OCP\FullTextSearch\Model\IIndexOptions; + +class IndexOptions implements IIndexOptions, JsonSerializable { /** * @var array @@ -42,51 +45,67 @@ class IndexOptions implements \JsonSerializable { /** * @return array */ - public function getOptions() { + public function getOptions(): array { return $this->options; } /** * @param array $options + * + * @return IIndexOptions */ - public function setOptions($options) { + public function setOptions(array $options): IIndexOptions { $this->options = $options; + + return $this; } /** - * @param string $k - * @param string $v + * @param string $option + * @param string $value + * + * @return IIndexOptions */ - public function addOption($k, $v) { - $this->options[$k] = $v; + public function addOption(string $option, string $value): IIndexOptions { + $this->options[$option] = $value; + + return $this; } /** - * @param string $k - * @param array $array + * @param string $option + * @param array $value + * + * @return IIndexOptions */ - public function addOptionArray($k, $array) { - $this->options[$k] = $array; + public function addOptionArray(string $option, array $value): IIndexOptions { + $this->options[$option] = $value; + + return $this; } /** - * @param string $k - * @param bool $bool + * @param string $option + * @param bool $value + * + * @return IIndexOptions */ - public function addOptionBool($k, $bool) { - $this->options[$k] = $bool; + public function addOptionBool(string $option, bool $value): IIndexOptions { + $this->options[$option] = $value; + + return $this; } /** - * @param string $k + * @param string $option * @param string $default * * @return string */ - public function getOption($k, $default = '') { - if (array_key_exists($k, $this->options)) { - return $this->options[$k]; + public function getOption(string $option, string $default = ''): string { + if (array_key_exists($option, $this->options)) { + return $this->options[$option]; } return $default; @@ -99,7 +118,7 @@ class IndexOptions implements \JsonSerializable { * * @return array */ - public function getOptionArray($option, $default = []) { + public function getOptionArray(string $option, array $default = []): array { if (array_key_exists($option, $this->options)) { $options = $this->options[$option]; if (is_array($options)) { @@ -117,7 +136,7 @@ class IndexOptions implements \JsonSerializable { * * @return bool */ - public function getOptionBool($option, $default) { + public function getOptionBool(string $option, bool $default): bool { if (array_key_exists($option, $this->options)) { $options = $this->options[$option]; if (is_bool($options)) { @@ -130,14 +149,9 @@ class IndexOptions implements \JsonSerializable { /** - * Specify data which should be serialized to JSON - * - * @link http://php.net/manual/en/jsonserializable.jsonserialize.php - * @return mixed data which can be serialized by json_encode, - * which is a value of any type other than a resource. - * @since 5.4.0 + * @return array */ public function jsonSerialize() { return $this->options; } -} \ No newline at end of file +} diff --git a/lib/Model/PlatformWrapper.php b/lib/Model/PlatformWrapper.php index 2bcccbb..6a9673a 100644 --- a/lib/Model/PlatformWrapper.php +++ b/lib/Model/PlatformWrapper.php @@ -28,7 +28,7 @@ namespace OCA\FullTextSearch\Model; -use OCA\FullTextSearch\IFullTextSearchPlatform; +use OCP\FullTextSearch\IFullTextSearchPlatform; /** @@ -56,9 +56,9 @@ class PlatformWrapper { * Provider constructor. * * @param string $appId - * @param IFullTextSearchPlatform $platform + * @param string $class */ - public function __construct($appId, $class) { + public function __construct(string $appId, string $class) { $this->appId = $appId; $this->class = $class; } @@ -66,7 +66,7 @@ class PlatformWrapper { /** * @return string */ - public function getAppId() { + public function getAppId(): string { return $this->appId; } @@ -75,7 +75,7 @@ class PlatformWrapper { * * @return PlatformWrapper */ - public function setAppId($appId) { + public function setAppId(string $appId): PlatformWrapper { $this->appId = $appId; return $this; diff --git a/lib/Model/ProviderIndexes.php b/lib/Model/ProviderIndexes.php index 2915181..3177066 100644 --- a/lib/Model/ProviderIndexes.php +++ b/lib/Model/ProviderIndexes.php @@ -27,9 +27,12 @@ namespace OCA\FullTextSearch\Model; +use OCA\FullTextSearch\Exceptions\IndexDoesNotExistException; +use OCP\FullTextSearch\Model\IIndex; + class ProviderIndexes { - /** @var Index[] */ + /** @var IIndex[] */ private $indexes; @@ -39,9 +42,9 @@ class ProviderIndexes { /** - * @return Index[] + * @return IIndex[] */ - public function getIndexes() { + public function getIndexes():array { return $this->indexes; } @@ -49,17 +52,18 @@ class ProviderIndexes { /** * @param string $documentId * - * @return null|Index + * @return IIndex + * @throws IndexDoesNotExistException */ - public function getIndex($documentId) { + public function getIndex(string $documentId): IIndex { foreach ($this->indexes as $index) { if ($index->getDocumentId() === (string)$documentId) { return $index; } } - return null; + throw new IndexDoesNotExistException(); } -} \ No newline at end of file +} diff --git a/lib/Model/ProviderWrapper.php b/lib/Model/ProviderWrapper.php index 866c58c..d1de140 100644 --- a/lib/Model/ProviderWrapper.php +++ b/lib/Model/ProviderWrapper.php @@ -28,7 +28,7 @@ namespace OCA\FullTextSearch\Model; -use OCA\FullTextSearch\IFullTextSearchProvider; +use OCP\FullTextSearch\IFullTextSearchProvider; /** diff --git a/lib/Model/Runner.php b/lib/Model/Runner.php index a2187aa..04f1d4e 100644 --- a/lib/Model/Runner.php +++ b/lib/Model/Runner.php @@ -32,10 +32,12 @@ use OCA\FullTextSearch\Exceptions\TickDoesNotExistException; use OCA\FullTextSearch\Exceptions\TickIsNotAliveException; use OCA\FullTextSearch\Service\MiscService; use OCA\FullTextSearch\Service\RunningService; +use OCP\FullTextSearch\Model\IIndex; +use OCP\FullTextSearch\Model\IRunner; use Symfony\Component\Console\Output\OutputInterface; -class Runner { +class Runner implements IRunner { const TICK_TTL = 1800; @@ -43,10 +45,6 @@ class Runner { const TICK_UPDATE = 10; const MEMORY_UPDATE = 5; - const RESULT_TYPE_SUCCESS = 1; - const RESULT_TYPE_WARNING = 4; - const RESULT_TYPE_FAIL = 9; - /** @var RunningService */ private $runningService; @@ -59,9 +57,6 @@ class Runner { /** @var int */ private $tickId; - /** @var ExtendedBase */ - private $commandBase = null; - /** @var OutputInterface */ private $outputInterface = null; @@ -135,7 +130,7 @@ class Runner { * @return string * @throws \Exception */ - public function updateAction($action = '', $force = false) { + public function updateAction(string $action = '', bool $force = false): string { $n = ''; if (sizeof($this->methodOnKeyPress) > 0) { $n = fread(STDIN, 9999); @@ -195,7 +190,7 @@ class Runner { * @param string $value * @param int $type */ - public function setInfo($info, $value, $type = 0) { + public function setInfo(string $info, string $value, int $type = 0) { $this->info[$info] = $value; $this->setInfoColored($info, $type); $this->infoUpdated(); @@ -204,7 +199,7 @@ class Runner { /** * @param array $data */ - public function setInfoArray($data) { + public function setInfoArray(array $data) { $keys = array_keys($data); //$this->info['info'] = ''; foreach ($keys as $k) { @@ -219,7 +214,7 @@ class Runner { * @param string $info * @param int $level */ - public function setInfoColored($info, $level) { + public function setInfoColored(string $info, int $level) { $value = $this->getInfo($info); if ($value === '') { @@ -228,15 +223,15 @@ class Runner { $color = ''; switch ($level) { - case self::RESULT_TYPE_SUCCESS: + case IRunner::RESULT_TYPE_SUCCESS: $color = 'info'; break; - case self::RESULT_TYPE_WARNING: + case IRunner::RESULT_TYPE_WARNING: $color = 'comment'; break; - case self::RESULT_TYPE_FAIL: + case IRunner::RESULT_TYPE_FAIL: $color = 'error'; break; } @@ -306,12 +301,13 @@ class Runner { } /** - * @param Index $index + * @param IIndex $index * @param string $message * @param string $class * @param int $sev */ - public function newIndexError($index, $message, $class = '', $sev = 3) { + public function newIndexError(IIndex $index, string $message, string $class = '', int $sev = 3 + ) { $error = [ 'index' => $index, 'message' => $message, @@ -334,12 +330,12 @@ class Runner { /** - * @param Index $index + * @param IIndex $index * @param string $message * @param string $status * @param int $type */ - public function newIndexResult($index, $message, $status, $type) { + public function newIndexResult(IIndex $index, string $message, string $status, int $type) { $result = [ 'index' => $index, 'message' => $message, @@ -353,17 +349,6 @@ class Runner { } -// /** -// * @throws InterruptException -// */ -// private function hasBeenInterrupted() { -// if ($this->commandBase === null) { -// return; -// } -// $this->commandBase->hasBeenInterrupted(); -// } - - /** * @param int $tick * @param string $action @@ -402,10 +387,10 @@ class Runner { /** * @deprecated - verifier l'interet !? * - * @param $reason - * @param $stop + * @param string $reason + * @param bool $stop */ - public function exception($reason, $stop) { + public function exception(string $reason, bool $stop) { if (!$stop) { $this->output('Exception: ' . $reason); // TODO: feed an array of exceptions for log; @@ -423,12 +408,10 @@ class Runner { /** - * @param ExtendedBase $base * @param OutputInterface $output */ - public function sourceIsCommandLine(ExtendedBase $base, OutputInterface $output) { + public function sourceIsCommandLine(OutputInterface $output) { $this->outputInterface = $output; - $this->commandBase = $base; } diff --git a/lib/Model/SearchRequest.php b/lib/Model/SearchRequest.php index 0fce57a..1d21169 100644 --- a/lib/Model/SearchRequest.php +++ b/lib/Model/SearchRequest.php @@ -26,9 +26,11 @@ namespace OCA\FullTextSearch\Model; +use JsonSerializable; use OCA\FullTextSearch\Service\MiscService; +use OCP\FullTextSearch\Model\ISearchRequest; -class SearchRequest implements \JsonSerializable { +class SearchRequest implements ISearchRequest, JsonSerializable { /** @var array */ private $providers; @@ -89,52 +91,64 @@ class SearchRequest implements \JsonSerializable { /** * @return array */ - public function getProviders() { + public function getProviders(): array { return $this->providers; } /** * @param array $providers + * + * @return ISearchRequest */ - public function setProviders($providers) { + public function setProviders(array $providers): ISearchRequest { $this->providers = $providers; + + return $this; } /** * @return string */ - public function getAuthor() { + public function getAuthor(): string { return $this->author; } /** * @param string $author + * + * @return ISearchRequest */ - public function setAuthor($author) { + public function setAuthor(string $author): ISearchRequest { $this->author = $author; + + return $this; } /** * @return string */ - public function getSearch() { + public function getSearch(): string { return $this->search; } /** * @param string $search + * + * @return ISearchRequest */ - public function setSearch($search) { + public function setSearch(string $search): ISearchRequest { $this->search = $search; + + return $this; } /** * */ - public function cleanSearch() { + public function cleanSearch(): ISearchRequest { $search = trim(str_replace(' ', ' ', $this->getSearch())); preg_match_all('/[^?]"(?:\\\\.|[^\\\\"])*"|\S+/', " $search ", $words); @@ -148,15 +162,17 @@ class SearchRequest implements \JsonSerializable { } $this->setSearch(implode(" ", $searchItems)); + + return $this; } /** - * @param $word + * @param string $word * * @return bool */ - private function searchQueryOptions($word) { + private function searchQueryOptions(string $word): bool { if (($pos = strpos($word, ':')) === false) { return false; } @@ -184,99 +200,111 @@ class SearchRequest implements \JsonSerializable { /** * @return int */ - public function getPage() { + public function getPage(): int { return $this->page; } /** * @param int $page + * + * @return ISearchRequest */ - public function setPage($page) { + public function setPage(int $page): ISearchRequest { if ($page < 1) { $page = 1; } $this->page = $page; + + return $this; } /** * @return int */ - public function getSize() { + public function getSize(): int { return $this->size; } /** * @param int $size + * + * @return ISearchRequest */ - public function setSize($size) { + public function setSize(int $size): ISearchRequest { $this->size = $size; + + return $this; } /** * @return array */ - public function getOptions() { + public function getOptions(): array { return $this->options; } /** * @param array $options + * + * @return ISearchRequest */ - public function setOptions($options) { + public function setOptions(array $options): ISearchRequest { $this->options = $options; + + return $this; } /** - * @param $key + * @param $option * @param $value * - * @return $this + * @return ISearchRequest */ - public function addOption($key, $value) { - $this->options[$key] = $value; + public function addOption(string $option, string $value): ISearchRequest { + $this->options[$option] = $value; return $this; } /** - * @param string $k - * @param array $array + * @param string $option + * @param array $value * - * @return SearchRequest + * @return ISearchRequest */ - public function addOptionArray($k, $array) { - $this->options[$k] = $array; + public function addOptionArray(string $option, array $value): ISearchRequest { + $this->options[$option] = $value; return $this; } /** - * @param string $k - * @param bool $bool + * @param string $option + * @param bool $value * - * @return SearchRequest + * @return ISearchRequest */ - public function addOptionBool($k, $bool) { - $this->options[$k] = $bool; + public function addOptionBool(string $option, bool $value): ISearchRequest { + $this->options[$option] = $value; return $this; } /** - * @param $key - * @param $value + * @param string $option + * @param string $value * - * @return $this + * @return ISearchRequest */ - public function addMultipleOption($key, $value) { - if (!array_key_exists($key, $this->options)) { - $this->options[$key] = []; + public function addMultipleOption(string $option, string $value): ISearchRequest { + if (!array_key_exists($option, $this->options)) { + $this->options[$option] = []; } - $this->options[$key][] = $value; + $this->options[$option][] = $value; return $this; } @@ -287,7 +315,7 @@ class SearchRequest implements \JsonSerializable { * * @return string */ - public function getOption($option, $default = '') { + public function getOption(string $option, string $default = ''): string { if (array_key_exists($option, $this->options)) { return $this->options[$option]; } @@ -302,7 +330,7 @@ class SearchRequest implements \JsonSerializable { * * @return array */ - public function getOptionArray($option, $default = []) { + public function getOptionArray(string $option, array $default = []): array { if (array_key_exists($option, $this->options)) { $options = $this->options[$option]; if (is_array($options)) { @@ -315,12 +343,12 @@ class SearchRequest implements \JsonSerializable { /** - * @param array $parts + * @param string $part * - * @return $this + * @return ISearchRequest */ - public function setParts($parts) { - $this->parts = $parts; + public function addPart(string $part): ISearchRequest { + $this->parts[] = $part; return $this; } @@ -328,24 +356,38 @@ class SearchRequest implements \JsonSerializable { /** * @return array */ - public function getParts() { + public function getParts(): array { return $this->parts; } + /** + * @since 15.0.0 + * + * @param array $parts + * + * @return ISearchRequest + */ + public function setParts(array $parts): ISearchRequest { + $this->parts = $parts; + + return $this; + } + + /** * @return array */ - public function getFields() { + public function getFields(): array { return $this->fields; } /** * @param array $fields * - * @return $this + * @return ISearchRequest */ - public function setFields($fields) { + public function setFields(array $fields): ISearchRequest { $this->fields = $fields; return $this; @@ -353,11 +395,11 @@ class SearchRequest implements \JsonSerializable { /** - * @param $field + * @param string $field * - * @return $this + * @return ISearchRequest */ - public function limitToField($field) { + public function addLimitField(string $field): ISearchRequest { array_push($this->limitFields, $field); return $this; @@ -366,17 +408,17 @@ class SearchRequest implements \JsonSerializable { /** * @return array */ - public function getLimitFields() { + public function getLimitFields(): array { return $this->limitFields; } /** - * @param $field + * @param string $field * - * @return $this + * @return ISearchRequest */ - public function addField($field) { + public function addField(string $field): ISearchRequest { $this->fields[] = $field; return $this; @@ -385,32 +427,40 @@ class SearchRequest implements \JsonSerializable { /** * @param string $tag + * + * @return ISearchRequest */ - public function addTag($tag) { + public function addTag(string $tag): ISearchRequest { $this->tags[] = $tag; + + return $this; } /** * @return array */ - public function getTags() { + public function getTags(): array { return $this->tags; } /** * @param array $tags + * + * @return ISearchRequest */ - public function setTags($tags) { + public function setTags(array $tags): ISearchRequest { $this->tags = $tags; + + return $this; } /** * @param array $tags * - * @return $this + * @return ISearchRequest */ - public function setMetaTags($tags) { + public function setMetaTags(array $tags): ISearchRequest { $this->metaTags = $tags; return $this; @@ -419,17 +469,17 @@ class SearchRequest implements \JsonSerializable { /** * @return array */ - public function getMetaTags() { + public function getMetaTags(): array { return $this->metaTags; } /** - * @param string $tags + * @param string $tag * - * @return $this + * @return ISearchRequest */ - public function addMetaTag($tags) { - $this->metaTags[] = $tags; + public function addMetaTag(string $tag): ISearchRequest { + $this->metaTags[] = $tag; return $this; } @@ -438,9 +488,9 @@ class SearchRequest implements \JsonSerializable { /** * @param array $tags * - * @return $this + * @return ISearchRequest */ - public function setSubTags($tags) { + public function setSubTags(array $tags): ISearchRequest { $this->subTags = $tags; return $this; @@ -451,7 +501,7 @@ class SearchRequest implements \JsonSerializable { * * @return array */ - public function getSubTags($formatted = false) { + public function getSubTags(bool $formatted = false): array { if ($formatted === false) { return $this->subTags; } @@ -472,9 +522,9 @@ class SearchRequest implements \JsonSerializable { * @param string $source * @param string $tag * - * @return $this + * @return ISearchRequest */ - public function addSubTag($source, $tag) { + public function addSubTag(string $source, string $tag): ISearchRequest { if (!array_key_exists($source, $this->subTags)) { $this->subTags[$source] = []; } @@ -488,9 +538,9 @@ class SearchRequest implements \JsonSerializable { /** * @param string $field * - * @return $this + * @return ISearchRequest */ - public function addWildcardField($field) { + public function addWildcardField(string $field): ISearchRequest { $this->wildcardFields[] = $field; return $this; @@ -500,7 +550,7 @@ class SearchRequest implements \JsonSerializable { /** * @return array */ - public function getWildcardFields() { + public function getWildcardFields(): array { return $this->wildcardFields; } @@ -508,7 +558,7 @@ class SearchRequest implements \JsonSerializable { // /** // * @param array $query // * -// * @return $this +// * @return ISearchRequest // */ // public function addWildcardQuery($query) { // $this->addWildcardQueries([$query]); @@ -519,7 +569,7 @@ class SearchRequest implements \JsonSerializable { // /** // * @param array $query // * -// * @return $this +// * @return ISearchRequest // */ // public function addWildcardQueries($query) { // array_push($this->wildcardQueries, $query); @@ -538,9 +588,9 @@ class SearchRequest implements \JsonSerializable { /** * @param array $filter * - * @return $this + * @return ISearchRequest */ - public function addWildcardFilter($filter) { + public function addWildcardFilter(array $filter): ISearchRequest { $this->addWildcardFilters([$filter]); return $this; @@ -549,9 +599,9 @@ class SearchRequest implements \JsonSerializable { /** * @param array $filters * - * @return $this + * @return ISearchRequest */ - public function addWildcardFilters($filters) { + public function addWildcardFilters(array $filters): ISearchRequest { array_push($this->wildcardFilters, $filters); return $this; @@ -560,17 +610,17 @@ class SearchRequest implements \JsonSerializable { /** * @return array */ - public function getWildcardFilters() { + public function getWildcardFilters(): array { return $this->wildcardFilters; } /** - * @param array $filter + * @param string $filter * - * @return $this + * @return ISearchRequest */ - public function addRegexFilter($filter) { + public function addRegexFilter(string $filter): ISearchRequest { $this->addRegexFilters([$filter]); return $this; @@ -579,9 +629,9 @@ class SearchRequest implements \JsonSerializable { /** * @param array $filters * - * @return $this + * @return ISearchRequest */ - public function addRegexFilters($filters) { + public function addRegexFilters(array $filters): ISearchRequest { array_push($this->regexFilters, $filters); return $this; @@ -590,7 +640,7 @@ class SearchRequest implements \JsonSerializable { /** * @return array */ - public function getRegexFilters() { + public function getRegexFilters(): array { return $this->regexFilters; } @@ -619,7 +669,7 @@ class SearchRequest implements \JsonSerializable { * * @return SearchRequest */ - public static function fromJSON($json) { + public static function fromJSON($json): SearchRequest { return self::fromArray(json_decode($json, true)); } @@ -628,7 +678,7 @@ class SearchRequest implements \JsonSerializable { * * @return SearchRequest */ - public static function fromArray($arr) { + public static function fromArray($arr): SearchRequest { $providers = $arr['providers']; if (!is_array($providers)) { $providers = [$providers]; @@ -650,4 +700,4 @@ class SearchRequest implements \JsonSerializable { } -} \ No newline at end of file +} diff --git a/lib/Model/SearchResult.php b/lib/Model/SearchResult.php index e985fc3..f51a7f0 100644 --- a/lib/Model/SearchResult.php +++ b/lib/Model/SearchResult.php @@ -1,4 +1,7 @@ documents = $documents; return $this; @@ -78,16 +87,16 @@ class SearchResult implements \JsonSerializable { /** * @return IndexDocument[] */ - public function getDocuments() { + public function getDocuments(): array { return $this->documents; } /** * @param IndexDocument $document * - * @return $this + * @return ISearchResult */ - public function addDocument(IndexDocument $document) { + public function addDocument(IndexDocument $document): ISearchResult { $this->documents[] = $document; return $this; @@ -96,37 +105,45 @@ class SearchResult implements \JsonSerializable { /** * @return int */ - public function getCount() { + public function getCount(): int { return count($this->documents); } /** * @param string $result + * + * @return ISearchResult */ - public function setRawResult($result) { + public function setRawResult(string $result): ISearchResult { $this->rawResult = $result; + + return $this; } /** * @return string */ - public function getRawResult() { + public function getRawResult(): string { return $this->rawResult; } /** * @param IFullTextSearchProvider $provider + * + * @return ISearchResult */ - public function setProvider(IFullTextSearchProvider $provider) { + public function setProvider(IFullTextSearchProvider $provider): ISearchResult { $this->provider = $provider; + + return $this; } /** * @return IFullTextSearchProvider */ - public function getProvider() { + public function getProvider(): IFullTextSearchProvider { return $this->provider; } @@ -134,30 +151,38 @@ class SearchResult implements \JsonSerializable { /** * @return IFullTextSearchPlatform */ - public function getPlatform() { + public function getPlatform(): IFullTextSearchPlatform { return $this->platform; } /** * @param IFullTextSearchPlatform $platform + * + * @return ISearchResult */ - public function setPlatform($platform) { + public function setPlatform($platform): ISearchResult { $this->platform = $platform; + + return $this; } /** * @return int */ - public function getTotal() { + public function getTotal(): int { return $this->total; } /** * @param int $total + * + * @return ISearchResult */ - public function setTotal($total) { + public function setTotal(int $total): ISearchResult { $this->total = $total; + + return $this; } @@ -170,54 +195,70 @@ class SearchResult implements \JsonSerializable { /** * @param int $maxScore + * + * @return ISearchResult */ - public function setMaxScore($maxScore) { + public function setMaxScore(int $maxScore): ISearchResult { $this->maxScore = $maxScore; + + return $this; } /** * @return int */ - public function getTime() { + public function getTime(): int { return $this->time; } /** * @param int $time + * + * @return ISearchResult */ - public function setTime($time) { + public function setTime(int $time): ISearchResult { $this->time = $time; + + return $this; } /** * @return bool */ - public function isTimedOut() { + public function isTimedOut(): bool { return $this->timedOut; } /** * @param bool $timedOut + * + * @return ISearchResult */ - public function setTimedOut($timedOut) { + public function setTimedOut(bool $timedOut): ISearchResult { $this->timedOut = $timedOut; + + return $this; } /** - * @return SearchRequest + * @return ISearchRequest */ - public function getRequest() { + public function getRequest(): ISearchRequest { return $this->request; } /** - * @param SearchRequest $request + * @param ISearchRequest $request + * + * @return ISearchResult */ - public function setRequest($request) { + public function setRequest(ISearchRequest $request): ISearchResult { $this->request = $request; + + return $this; } @@ -230,8 +271,8 @@ class SearchResult implements \JsonSerializable { $provider = []; if ($providerObj !== null) { $provider = [ - 'id' => $providerObj->getId(), - 'name' => $providerObj->getName() + 'id' => $providerObj->getId(), + 'name' => $providerObj->getName() ]; } @@ -239,8 +280,8 @@ class SearchResult implements \JsonSerializable { $platform = []; if ($platformObj !== null) { $platform = [ - 'id' => $platformObj->getId(), - 'name' => $platformObj->getName() + 'id' => $platformObj->getId(), + 'name' => $platformObj->getName() ]; } @@ -258,4 +299,32 @@ class SearchResult implements \JsonSerializable { ] ]; } + + /** + * @since 15.0.0 + * + * @param string $category + * @param string $value + * @param int $count + * + * @return ISearchResult + */ + public function addAggregation(string $category, string $value, int $count): ISearchResult { + // TODO: Implement addAggregation() method. + + return $this; + } + + /** + * @since 15.0.0 + * + * @param string $category + * + * @return array + */ + public function getAggregations(string $category): array { + // TODO: Implement getAggregations() method. + + return []; + } } diff --git a/lib/Model/Tick.php b/lib/Model/Tick.php index 865bb86..bd7649d 100644 --- a/lib/Model/Tick.php +++ b/lib/Model/Tick.php @@ -187,4 +187,35 @@ class Tick { return $this; } -} \ No newline at end of file + + /** + * @param string $key + * @param string|int $value + * + * @return $this + */ + public function setInfo($key, $value) { + $this->data[$key] = $value; + + return $this; + } + + public function unsetInfo($key) { + unset($this->data[$key]); + } + + /** + * @param $key + * @param int|string $default + * + * @return int|string + */ + public function getInfo($key, $default = '') { + if (!array_key_exists($key, $this->data)) { + return $default; + } + + return $this->data[$key]; + + } +} diff --git a/lib/Provider/TestProvider.php b/lib/Provider/TestProvider.php index 1deeb11..1247faf 100644 --- a/lib/Provider/TestProvider.php +++ b/lib/Provider/TestProvider.php @@ -27,18 +27,20 @@ namespace OCA\FullTextSearch\Provider; -use OCA\FullTextSearch\AppInfo\Application; -use OCA\FullTextSearch\IFullTextSearchPlatform; -use OCA\FullTextSearch\IFullTextSearchProvider; -use OCA\FullTextSearch\Model\Index; -use OCA\FullTextSearch\Model\IndexDocument; use OCA\FullTextSearch\Model\IndexOptions; use OCA\FullTextSearch\Model\Runner; -use OCA\FullTextSearch\Model\SearchRequest; -use OCA\FullTextSearch\Model\SearchResult; use OCA\FullTextSearch\Service\ConfigService; use OCA\FullTextSearch\Service\MiscService; use OCA\FullTextSearch\Service\TestService; +use OCP\FullTextSearch\IFullTextSearchPlatform; +use OCP\FullTextSearch\IFullTextSearchProvider; +use OCP\FullTextSearch\Model\IIndex; +use OCP\FullTextSearch\Model\IIndexOptions; +use OCP\FullTextSearch\Model\IndexDocument; +use OCP\FullTextSearch\Model\IRunner; +use OCP\FullTextSearch\Model\ISearchRequest; +use OCP\FullTextSearch\Model\ISearchResult; +use OCP\FullTextSearch\Model\SearchTemplate; class TestProvider implements IFullTextSearchProvider { @@ -74,15 +76,13 @@ class TestProvider implements IFullTextSearchProvider { $this->configService = $configService; $this->testService = $testService; $this->miscService = $miscService; - - $this->indexOptions = new IndexOptions(); } /** * return unique id of the provider */ - public function getId() { + public function getId(): string { return self::TEST_PROVIDER_ID; } @@ -90,7 +90,7 @@ class TestProvider implements IFullTextSearchProvider { /** * return name of the provider */ - public function getName() { + public function getName(): string { return 'Test Provider'; } @@ -98,29 +98,29 @@ class TestProvider implements IFullTextSearchProvider { /** * @return array */ - public function getConfiguration() { + public function getConfiguration(): array { return $this->configService->getConfig(); } - public function setRunner(Runner $runner) { + public function setRunner(IRunner $runner) { $this->runner = $runner; } /** - * @param IndexOptions $options + * @param IIndexOptions $options */ - public function setIndexOptions($options) { + public function setIndexOptions(IIndexOptions $options) { $this->indexOptions = $options; } /** - * @return array + * @return SearchTemplate */ - public function getOptionsTemplate() { - return []; + public function getSearchTemplate(): SearchTemplate { + return new SearchTemplate(); } @@ -143,7 +143,7 @@ class TestProvider implements IFullTextSearchProvider { * * @return IndexDocument[] */ - public function generateIndexableDocuments($userId) { + public function generateIndexableDocuments(string $userId): array { $result = []; $result[] = $this->testService->generateIndexDocumentContentLicense($this->indexOptions); @@ -155,20 +155,6 @@ class TestProvider implements IFullTextSearchProvider { } - /** - * generate documents prior to the indexing. - * throw NoResultException if no more result - * - * @param IndexDocument[] $chunk - * - * @deprecated - * @return IndexDocument[] - */ - public function fillIndexDocuments($chunk) { - return $chunk; - } - - /** * generate documents prior to the indexing. * @@ -183,17 +169,17 @@ class TestProvider implements IFullTextSearchProvider { * * @return bool */ - public function isDocumentUpToDate($document) { + public function isDocumentUpToDate(IndexDocument $document): bool { return false; } /** - * @param Index $index + * @param IIndex $index * - * @return IndexDocument|null + * @return IndexDocument */ - public function updateDocument(Index $index) { + public function updateDocument(IIndex $index): IndexDocument { return null; } @@ -222,18 +208,18 @@ class TestProvider implements IFullTextSearchProvider { /** * before a search, improve the request * - * @param SearchRequest $request + * @param ISearchRequest $request */ - public function improveSearchRequest(SearchRequest $request) { + public function improveSearchRequest(ISearchRequest $request) { } /** * after a search, improve results * - * @param SearchResult $searchResult + * @param ISearchResult $searchResult */ - public function improveSearchResult(SearchResult $searchResult) { + public function improveSearchResult(ISearchResult $searchResult) { } diff --git a/lib/Service/CliService.php b/lib/Service/CliService.php index 0448555..4ae6bde 100644 --- a/lib/Service/CliService.php +++ b/lib/Service/CliService.php @@ -140,9 +140,8 @@ class CliService { /** * @param OutputInterface $output - * @param array $initVar */ - public function runDisplay(OutputInterface $output, $initVar = []) { + public function runDisplay(OutputInterface $output) { $this->output = $output; $output->writeLn(''); diff --git a/lib/Service/ConfigService.php b/lib/Service/ConfigService.php index 8462831..2d5f119 100644 --- a/lib/Service/ConfigService.php +++ b/lib/Service/ConfigService.php @@ -105,11 +105,11 @@ class ConfigService { /** * Get a version of an app * - * @param string $key + * @param string $appId * * @return string */ - public function getAppVersion($appId) { + public function getAppVersion(string $appId): string { return $this->config->getAppValue($appId, 'installed_version', ''); } diff --git a/lib/Service/IndexService.php b/lib/Service/IndexService.php index 85564cb..42d6d44 100644 --- a/lib/Service/IndexService.php +++ b/lib/Service/IndexService.php @@ -30,19 +30,20 @@ use Exception; use OCA\FullTextSearch\Db\IndexesRequest; use OCA\FullTextSearch\Exceptions\DatabaseException; use OCA\FullTextSearch\Exceptions\IndexDoesNotExistException; -use OCA\FullTextSearch\Exceptions\InterruptException; use OCA\FullTextSearch\Exceptions\NotIndexableDocumentException; -use OCA\FullTextSearch\Exceptions\TickDoesNotExistException; -use OCA\FullTextSearch\IFullTextSearchPlatform; -use OCA\FullTextSearch\IFullTextSearchProvider; -use OCA\FullTextSearch\Model\ExtendedIndex; use OCA\FullTextSearch\Model\Index; -use OCA\FullTextSearch\Model\IndexDocument; use OCA\FullTextSearch\Model\IndexOptions; use OCA\FullTextSearch\Model\ProviderIndexes; use OCA\FullTextSearch\Model\Runner; +use OCP\FullTextSearch\IFullTextSearchPlatform; +use OCP\FullTextSearch\IFullTextSearchProvider; +use OCP\FullTextSearch\Model\IIndex; +use OCP\FullTextSearch\Model\IIndexOptions; +use OCP\FullTextSearch\Model\IndexDocument; +use OCP\FullTextSearch\Model\IRunner; +use OCP\FullTextSearch\Service\IIndexService; -class IndexService { +class IndexService implements IIndexService { /** @var IndexesRequest */ private $indexesRequest; @@ -105,7 +106,7 @@ class IndexService { * * @throws Exception */ - private function updateRunnerAction($action, $force = false) { + private function updateRunnerAction(string $action, bool $force = false) { if ($this->runner === null) { return; } @@ -116,9 +117,11 @@ class IndexService { /** * @param string $info * @param string $value - * @param string $color + * @param int $color */ - private function updateRunnerInfo($info, $value, $color = '') { + private function updateRunnerInfo( + string $info, string $value, int $color = IRunner::RESULT_TYPE_SUCCESS + ) { if ($this->runner === null) { return; } @@ -129,7 +132,7 @@ class IndexService { /** * @param array $data */ - private function updateRunnerInfoArray($data) { + private function updateRunnerInfoArray(array $data) { if ($this->runner === null) { return; } @@ -144,8 +147,6 @@ class IndexService { * @param string $userId * @param IndexOptions $options * - * @throws InterruptException - * @throws TickDoesNotExistException * @throws Exception */ public function indexProviderContentFromUser( @@ -154,9 +155,11 @@ class IndexService { $this->updateRunnerAction('generateIndex' . $provider->getName()); $this->updateRunnerInfoArray( [ - 'userId' => $userId, - 'providerId' => $provider->getId(), - 'providerName' => $provider->getName() + 'userId' => $userId, + 'providerId' => $provider->getId(), + 'providerName' => $provider->getName(), + 'documentCurrent' => 0, + 'documentTotal' => 0 ] ); @@ -180,13 +183,13 @@ class IndexService { /** * @param IFullTextSearchProvider $provider * @param IndexDocument[] $documents - * @param IndexOptions $options + * @param IIndexOptions $options * * @return IndexDocument[] * @throws Exception */ private function updateDocumentsWithCurrIndex( - IFullTextSearchProvider $provider, array $documents, IndexOptions $options + IFullTextSearchProvider $provider, array $documents, IIndexOptions $options ) { $currIndex = $this->getProviderIndexFromProvider($provider); @@ -200,8 +203,9 @@ class IndexService { } $count++; - $index = $currIndex->getIndex($document->getId()); - if ($index === null) { + try { + $index = $currIndex->getIndex($document->getId()); + } catch (IndexDoesNotExistException $e) { $index = new Index($document->getProviderId(), $document->getId()); $index->setStatus(Index::INDEX_FULL); $index->setLastIndex(); @@ -302,15 +306,12 @@ class IndexService { ); $this->filterDocumentBeforeIndex($document); + $index = $this->indexDocument($platform, $document); + $this->updateIndex($index); + } catch (Exception $e) { - $document->__destruct(); - continue; } - $index = $this->indexDocument($platform, $provider, $document); - - $this->updateIndex($index); - $document->__destruct(); unset($document); } @@ -338,15 +339,12 @@ class IndexService { /** * @param IFullTextSearchPlatform $platform - * @param IFullTextSearchProvider $provider * @param IndexDocument $document * - * @return + * @return IIndex * @throws Exception */ - public function indexDocument( - IFullTextSearchPlatform $platform, IFullTextSearchProvider $provider, $document - ) { + public function indexDocument(IFullTextSearchPlatform $platform, $document) { $this->updateRunnerAction('indexDocument', true); $this->updateRunnerInfoArray( [ @@ -356,13 +354,14 @@ class IndexService { ] ); - $index = null; try { - $index = $platform->indexDocument($provider, $document); + $index = $platform->indexDocument($document); + + return $index; } catch (Exception $e) { + throw new IndexDoesNotExistException(); } - return $index; } @@ -421,7 +420,7 @@ class IndexService { * * @throws DatabaseException */ - public function updateIndexes($indexes) { + public function updateIndexes(array $indexes) { try { foreach ($indexes as $index) { $this->updateIndex($index); @@ -434,16 +433,17 @@ class IndexService { /** - * @param Index $index + * @param IIndex $index * * @throws Exception */ - private function updateIndex(Index $index) { + private function updateIndex(IIndex $index) { + /** @var Index $index */ $this->updateIndexError($index); - if ($index->isStatus(Index::INDEX_REMOVE)) { + if ($index->isStatus(IIndex::INDEX_REMOVE)) { - if ($index->isStatus(Index::INDEX_DONE)) { + if ($index->isStatus(IIndex::INDEX_DONE)) { $this->indexesRequest->deleteIndex($index); return; @@ -454,8 +454,8 @@ class IndexService { return; } - if ($index->isStatus(Index::INDEX_DONE)) { - $index->setStatus(Index::INDEX_OK, true); + if ($index->isStatus(IIndex::INDEX_DONE)) { + $index->setStatus(IIndex::INDEX_OK, true); } if (!$this->indexesRequest->update($index)) { @@ -464,7 +464,7 @@ class IndexService { } - private function updateIndexError(Index $index) { + private function updateIndexError(IIndex $index) { } @@ -477,7 +477,9 @@ class IndexService { * * @throws DatabaseException */ - public function updateIndexesStatus($providerId, $documentIds, $status, $reset = false) { + public function updateIndexesStatus( + string $providerId, array $documentIds, int $status, bool $reset = false + ) { if ($reset === true) { $this->indexesRequest->updateStatus($providerId, $documentIds, $status); @@ -526,7 +528,7 @@ class IndexService { /** - * @return ExtendedIndex[] + * @return Index[] */ public function getErrorIndexes() { return $this->indexesRequest->getErrorIndexes(); @@ -537,7 +539,7 @@ class IndexService { * @param string $providerId * @param array $documentId * - * @return ExtendedIndex[] + * @return Index[] * @throws IndexDoesNotExistException */ public function getIndexes($providerId, $documentId) { @@ -587,4 +589,27 @@ class IndexService { } + /** + * @param string $providerId + * @param string $documentId + * + * @return IIndex + * @throws IndexDoesNotExistException + */ + public function getIndex(string $providerId, string $documentId): IIndex { + return $this->indexesRequest->getIndex($providerId, $documentId); + } + + + /** + * @param string $providerId + * @param $documentId + * @param int $status + * @param bool $reset + */ + public function updateIndexStatus( + string $providerId, $documentId, int $status, bool $reset = false + ) { + // TODO: Implement updateIndexStatus() method. + } } diff --git a/lib/Service/PlatformService.php b/lib/Service/PlatformService.php index 3962681..44cd71e 100644 --- a/lib/Service/PlatformService.php +++ b/lib/Service/PlatformService.php @@ -31,9 +31,9 @@ use OC\App\AppManager; use OCA\FullTextSearch\Exceptions\PlatformDoesNotExistException; use OCA\FullTextSearch\Exceptions\PlatformIsNotCompatibleException; use OCA\FullTextSearch\Exceptions\PlatformNotSelectedException; -use OCA\FullTextSearch\IFullTextSearchPlatform; use OCA\FullTextSearch\Model\PlatformWrapper; use OCP\AppFramework\QueryException; +use OCP\FullTextSearch\IFullTextSearchPlatform; class PlatformService { @@ -161,7 +161,7 @@ class PlatformService { $platform = \OC::$server->query((string)$selected->getClass()); if (!($platform instanceof IFullTextSearchPlatform)) { throw new PlatformIsNotCompatibleException( - $selected . ' is not a compatible FullTextSearchPlatform' + $selected->getClass() . ' is not a compatible FullTextSearchPlatform' ); } @@ -177,7 +177,7 @@ class PlatformService { * @throws PlatformDoesNotExistException * @throws PlatformNotSelectedException */ - private function getSelectedPlatform() { + private function getSelectedPlatform(): PlatformWrapper { $selected = $this->configService->getAppValue(ConfigService::SEARCH_PLATFORM); if ($selected === '') { diff --git a/lib/Service/ProviderService.php b/lib/Service/ProviderService.php index 692e0bb..691e3d3 100644 --- a/lib/Service/ProviderService.php +++ b/lib/Service/ProviderService.php @@ -28,15 +28,19 @@ namespace OCA\FullTextSearch\Service; use Exception; use OC\App\AppManager; +use OCA\FullTextSearch\AppInfo\Application; use OCA\FullTextSearch\Exceptions\ProviderDoesNotExistException; use OCA\FullTextSearch\Exceptions\ProviderIsNotCompatibleException; use OCA\FullTextSearch\Exceptions\ProviderIsNotUniqueException; use OCA\FullTextSearch\Exceptions\ProviderOptionsDoesNotExistException; -use OCA\FullTextSearch\IFullTextSearchProvider; use OCA\FullTextSearch\Model\ProviderWrapper; use OCP\AppFramework\QueryException; +use OCP\FullTextSearch\IFullTextSearchProvider; +use OCP\FullTextSearch\Service\IProviderService; +use OCP\Util; -class ProviderService { + +class ProviderService implements IProviderService { /** @var AppManager */ private $appManager; @@ -205,7 +209,7 @@ class ProviderService { * * @return bool */ - public function isProviderIndexed($providerId) { + public function isProviderIndexed(string $providerId) { try { $indexed = $this->configService->getProviderOptions( $providerId, ConfigService::PROVIDER_INDEXED @@ -308,4 +312,19 @@ class ProviderService { return $arr; } + + /** + * + */ + public function addJavascriptAPI() { + Util::addStyle(Application::APP_NAME, 'fulltextsearch'); + Util::addScript(Application::APP_NAME, 'fulltextsearch.v1.api'); + Util::addScript(Application::APP_NAME, 'fulltextsearch.v1.settings'); + Util::addScript(Application::APP_NAME, 'fulltextsearch.v1.searchbox'); + Util::addScript(Application::APP_NAME, 'fulltextsearch.v1.result'); + Util::addScript(Application::APP_NAME, 'fulltextsearch.v1.navigation'); + Util::addScript(Application::APP_NAME, 'fulltextsearch.v1'); + } + + } diff --git a/lib/Service/RunningService.php b/lib/Service/RunningService.php index 53ea6dc..aa953be 100644 --- a/lib/Service/RunningService.php +++ b/lib/Service/RunningService.php @@ -30,7 +30,7 @@ use OCA\FullTextSearch\Db\TickRequest; use OCA\FullTextSearch\Exceptions\RunnerAlreadyUpException; use OCA\FullTextSearch\Exceptions\TickDoesNotExistException; use OCA\FullTextSearch\Exceptions\TickIsNotAliveException; -use OCA\FullTextSearch\Model\ExtendedTick; +use OCA\FullTextSearch\Model\Tick; use OCA\FullTextSearch\Model\Runner; class RunningService { @@ -74,7 +74,7 @@ class RunningService { throw new RunnerAlreadyUpException('Index is already running'); } - $tick = new ExtendedTick($source); + $tick = new Tick($source); $tick->setStatus('run') ->setTick() ->setFirstTick() @@ -164,13 +164,13 @@ class RunningService { /** - * @param ExtendedTick $tick + * @param Tick $tick * @param bool $exception * * @return bool * @throws TickIsNotAliveException */ - public function isStillAlive(ExtendedTick $tick, $exception = false) { + public function isStillAlive(Tick $tick, $exception = false) { if ($tick->getStatus() !== 'run') { if ($exception) { throw new TickIsNotAliveException(); @@ -217,10 +217,10 @@ class RunningService { /** - * @param ExtendedTick $tick + * @param Tick $tick * @param string $action */ - private function assignActionToTick(ExtendedTick &$tick, $action) { + private function assignActionToTick(Tick &$tick, $action) { $now = microtime(true); $preAction = $tick->getAction(); @@ -240,4 +240,4 @@ class RunningService { } -} \ No newline at end of file +} diff --git a/lib/Service/SearchService.php b/lib/Service/SearchService.php index 5552b5c..3dfa85e 100644 --- a/lib/Service/SearchService.php +++ b/lib/Service/SearchService.php @@ -32,17 +32,20 @@ use OC\User\NoUserException; use OCA\Circles\Api\v1\Circles; use OCA\FullTextSearch\Exceptions\EmptySearchException; use OCA\FullTextSearch\Exceptions\ProviderDoesNotExistException; -use OCA\FullTextSearch\IFullTextSearchPlatform; -use OCA\FullTextSearch\IFullTextSearchProvider; -use OCA\FullTextSearch\Model\DocumentAccess; use OCA\FullTextSearch\Model\SearchRequest; use OCA\FullTextSearch\Model\SearchResult; +use OCP\FullTextSearch\IFullTextSearchPlatform; +use OCP\FullTextSearch\IFullTextSearchProvider; +use OCP\FullTextSearch\Model\DocumentAccess; +use OCP\FullTextSearch\Model\ISearchRequest; +use OCP\FullTextSearch\Model\ISearchResult; +use OCP\FullTextSearch\Service\ISearchService; use OCP\IGroupManager; use OCP\IUser; use OCP\IUserManager; -class SearchService { +class SearchService implements ISearchService { /** @var string */ private $userId; @@ -98,19 +101,30 @@ class SearchService { } + /** + * @param array $request + * + * @return ISearchRequest + */ + public function generateSearchRequest(array $request): ISearchRequest { + return SearchRequest::fromArray($request); + } + + /** * @param string $userId - * @param SearchRequest $request + * @param ISearchRequest $request * + * @return ISearchResult[] * @throws EmptySearchException * @throws Exception * @throws ProviderDoesNotExistException */ - public function search($userId, SearchRequest $request) { + public function search(string $userId, ISearchRequest $request): array { $this->searchRequestCannotBeEmpty($request); - if ($userId === null) { + if ($userId === '') { $userId = $this->userId; } @@ -119,6 +133,7 @@ class SearchService { throw new NoUserException('User does not exist'); } + /** @var $request SearchRequest */ $request->setAuthor($user->getUID()); $request->cleanSearch(); @@ -139,11 +154,11 @@ class SearchService { /** - * @param SearchRequest $request + * @param ISearchRequest $request * * @throws EmptySearchException */ - private function searchRequestCannotBeEmpty(SearchRequest $request) { + private function searchRequestCannotBeEmpty(ISearchRequest $request) { if ($request === null || strlen($request->getSearch()) < 1) { throw new EmptySearchException('search cannot be empty'); } @@ -156,7 +171,7 @@ class SearchService { * @param IFullTextSearchProvider[] $providers * @param SearchRequest $request * - * @return SearchResult[] + * @return ISearchResult[] */ private function searchFromProviders( IFullTextSearchPlatform $platform, $providers, DocumentAccess $access, diff --git a/lib/Service/TestService.php b/lib/Service/TestService.php index 2954a99..f362d88 100644 --- a/lib/Service/TestService.php +++ b/lib/Service/TestService.php @@ -26,10 +26,10 @@ namespace OCA\FullTextSearch\Service; -use OCA\FullTextSearch\Model\DocumentAccess; -use OCA\FullTextSearch\Model\IndexDocument; -use OCA\FullTextSearch\Model\IndexOptions; use OCA\FullTextSearch\Provider\TestProvider; +use OCP\FullTextSearch\Model\DocumentAccess; +use OCP\FullTextSearch\Model\IIndexOptions; +use OCP\FullTextSearch\Model\IndexDocument; class TestService { @@ -65,11 +65,11 @@ class TestService { /** - * @param IndexOptions $options + * @param IIndexOptions $options * * @return IndexDocument */ - public function generateIndexDocumentContentLicense(IndexOptions $options = null) { + public function generateIndexDocumentContentLicense(IIndexOptions $options) { $indexDocument = $this->generateIndexDocument(self::DOCUMENT_TYPE_LICENSE); $content = file_get_contents(__DIR__ . '/../../LICENSE'); @@ -92,11 +92,11 @@ class TestService { /** - * @param IndexOptions $options + * @param IIndexOptions $options * * @return IndexDocument */ - public function generateIndexDocumentSimple(IndexOptions $options) { + public function generateIndexDocumentSimple(IIndexOptions $options) { $indexDocument = $this->generateIndexDocument(self::DOCUMENT_TYPE_SIMPLE); $indexDocument->setContent('document is a simple test'); -- cgit v1.2.3 From 6a0c412ff3c422262d1b8e7a8760a174433d46fa Mon Sep 17 00:00:00 2001 From: Maxence Lange Date: Tue, 30 Oct 2018 22:54:33 +0100 Subject: Exit process on Ctrl-C Signed-off-by: Maxence Lange --- lib/ACommandBase.php | 45 +++++++++++++++++++++++++++++++++++++++++++++ lib/Command/Index.php | 18 ++++++++++++------ lib/Command/Live.php | 17 +++++++++++++---- lib/Command/Reset.php | 16 +++++++++++++--- lib/Model/Runner.php | 27 ++++++++++++--------------- 5 files changed, 95 insertions(+), 28 deletions(-) create mode 100644 lib/ACommandBase.php (limited to 'lib') diff --git a/lib/ACommandBase.php b/lib/ACommandBase.php new file mode 100644 index 0000000..56d5129 --- /dev/null +++ b/lib/ACommandBase.php @@ -0,0 +1,45 @@ + + * @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; + + +use OC\Core\Command\Base; + + +/** + * Abstract class ICommandBase + */ +abstract class ACommandBase extends Base { + + abstract public function abort(); + +} + diff --git a/lib/Command/Index.php b/lib/Command/Index.php index f6c5105..a80d1ef 100644 --- a/lib/Command/Index.php +++ b/lib/Command/Index.php @@ -27,8 +27,9 @@ namespace OCA\FullTextSearch\Command; use Exception; +use OC\Core\Command\InterruptedException; +use OCA\FullTextSearch\ACommandBase; use OCA\FullTextSearch\Exceptions\TickDoesNotExistException; -use OC\Core\Command\Base; use OCA\FullTextSearch\Model\Index as ModelIndex; use OCA\FullTextSearch\Model\IndexOptions; use OCA\FullTextSearch\Model\Runner; @@ -47,7 +48,7 @@ use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Terminal; -class Index extends Base { +class Index extends ACommandBase { // '%job:1s%%message:-40s%%current:6s%/%max:6s% [%bar%] %percent:3s%% \n %duration% %infos:-12s% %jvm:-30s% ' const PANEL_RUN = 'run'; @@ -176,8 +177,6 @@ class Index extends Base { } - - /** * @param InputInterface $input * @param OutputInterface $output @@ -215,7 +214,7 @@ class Index extends Base { $this->runner->setInfo('options', json_encode($options)); try { - $this->runner->sourceIsCommandLine($output); + $this->runner->sourceIsCommandLine($this, $output); $this->runner->start(); if ($options->getOption('errors') === 'reset') { @@ -823,7 +822,14 @@ class Index extends Base { $this->displayError(); } -} + + /** + * @throws InterruptedException + */ + public function abort() { + $this->abortIfInterrupted(); + } +} diff --git a/lib/Command/Live.php b/lib/Command/Live.php index dc1a187..ffdcc40 100644 --- a/lib/Command/Live.php +++ b/lib/Command/Live.php @@ -27,7 +27,8 @@ namespace OCA\FullTextSearch\Command; use Exception; -use OC\Core\Command\Base; +use OC\Core\Command\InterruptedException; +use OCA\FullTextSearch\ACommandBase; use OCA\FullTextSearch\Exceptions\TickDoesNotExistException; use OCA\FullTextSearch\Model\Index as ModelIndex; use OCA\FullTextSearch\Model\Runner; @@ -45,7 +46,7 @@ use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Terminal; -class Live extends Base { +class Live extends ACommandBase { const CYCLE_DELAY = 300000; @@ -216,7 +217,7 @@ class Live extends Base { try { - $this->runner->sourceIsCommandLine($output); + $this->runner->sourceIsCommandLine($this, $output); $this->runner->start(); $this->cliService->runDisplay($output); @@ -720,7 +721,15 @@ class Live extends Base { $this->displayError(); } -} + /** + * @throws InterruptedException + */ + public function abort() { + $this->abortIfInterrupted(); + } + + +} diff --git a/lib/Command/Reset.php b/lib/Command/Reset.php index 42349e1..8d87b0d 100644 --- a/lib/Command/Reset.php +++ b/lib/Command/Reset.php @@ -27,7 +27,8 @@ namespace OCA\FullTextSearch\Command; use Exception; -use OC\Core\Command\Base; +use OC\Core\Command\InterruptedException; +use OCA\FullTextSearch\ACommandBase; use OCA\FullTextSearch\Model\Runner; use OCA\FullTextSearch\Service\IndexService; use OCA\FullTextSearch\Service\MiscService; @@ -37,7 +38,7 @@ use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; -class Reset extends Base { +class Reset extends ACommandBase { /** @var IndexService */ private $indexService; @@ -85,7 +86,7 @@ class Reset extends Base { protected function execute(InputInterface $input, OutputInterface $output) { try { - $this->runner->sourceIsCommandLine($output); + $this->runner->sourceIsCommandLine($this, $output); $this->runner->start(); $this->runner->output('reset.'); @@ -119,6 +120,15 @@ class Reset extends Base { return $providerId; } + + + /** + * @throws InterruptedException + */ + public function abort() { + $this->abortIfInterrupted(); + } + } diff --git a/lib/Model/Runner.php b/lib/Model/Runner.php index 04f1d4e..3106573 100644 --- a/lib/Model/Runner.php +++ b/lib/Model/Runner.php @@ -27,6 +27,7 @@ namespace OCA\FullTextSearch\Model; +use OCA\FullTextSearch\ACommandBase; use OCA\FullTextSearch\Exceptions\RunnerAlreadyUpException; use OCA\FullTextSearch\Exceptions\TickDoesNotExistException; use OCA\FullTextSearch\Exceptions\TickIsNotAliveException; @@ -57,6 +58,9 @@ class Runner implements IRunner { /** @var int */ private $tickId; + /** @var ACommandBase */ + private $base = null; + /** @var OutputInterface */ private $outputInterface = null; @@ -131,6 +135,9 @@ class Runner implements IRunner { * @throws \Exception */ public function updateAction(string $action = '', bool $force = false): string { + + $this->base->abort(); + $n = ''; if (sizeof($this->methodOnKeyPress) > 0) { $n = fread(STDIN, 9999); @@ -145,13 +152,6 @@ class Runner implements IRunner { } $tick = time(); -// try { -// $this->hasBeenInterrupted(); -// } catch (InterruptException $e) { -// $this->stop(); -// throw $e; -// } - if ($this->oldAction !== $action || $force) { while (true) { if (!$this->isPaused()) { @@ -163,7 +163,9 @@ class Runner implements IRunner { if ($pressed === $this->keys['nextStep']) { break; } + usleep(300000); + $this->base->abort(); } $this->pauseRunning(false); @@ -408,9 +410,11 @@ class Runner implements IRunner { /** + * @param ACommandBase $base * @param OutputInterface $output */ - public function sourceIsCommandLine(OutputInterface $output) { + public function sourceIsCommandLine(ACommandBase $base, OutputInterface $output) { + $this->base = $base; $this->outputInterface = $output; } @@ -445,13 +449,6 @@ class Runner implements IRunner { } -// /** -// * @return bool -// */ -// public function isStrict() { -// return $this->strict; -// } - /** * @param string $line */ -- cgit v1.2.3 From f750fef8d19a4460db813f799383adbb50ff02be Mon Sep 17 00:00:00 2001 From: Maxence Lange Date: Wed, 31 Oct 2018 09:23:47 +0100 Subject: migrating to php7 Signed-off-by: Maxence Lange --- lib/Command/Index.php | 89 +++++++++++++++++++++++++++++++-------------------- lib/Command/Live.php | 60 ++++++++++++++++++++-------------- 2 files changed, 90 insertions(+), 59 deletions(-) (limited to 'lib') diff --git a/lib/Command/Index.php b/lib/Command/Index.php index a80d1ef..6fa14d1 100644 --- a/lib/Command/Index.php +++ b/lib/Command/Index.php @@ -1,4 +1,7 @@ errors[] = $error; $this->displayError(); } @@ -331,7 +342,7 @@ class Index extends ACommandBase { /** * @param array $result */ - public function onNewIndexResult($result) { + public function onNewIndexResult(array $result) { $this->results[] = $result; $this->displayResult(); } @@ -381,7 +392,6 @@ class Index extends ACommandBase { } $this->providerService->setProviderAsIndexed($provider, true); - } @@ -390,8 +400,13 @@ class Index extends ACommandBase { * * @return IndexOptions */ - private function generateIndexOptions(InputInterface $input) { + private function generateIndexOptions(InputInterface $input): IndexOptions { $jsonOptions = $input->getArgument('options'); + + if (!is_string($jsonOptions)) { + return new IndexOptions([]); + } + $options = json_decode($jsonOptions, true); if (!is_array($options)) { @@ -408,14 +423,14 @@ class Index extends ACommandBase { * * @return bool */ - private function isIncludedProvider(IndexOptions $options, $providerId) { + private function isIncludedProvider(IndexOptions $options, string $providerId): bool { if ($options->getOption('provider', '') !== '' && $options->getOption('provider') !== $providerId) { return false; } if ($options->getOptionArray('providers', []) !== []) { - return (in_array($providerId, $options->getOptionArray('providers'))); + return (in_array($providerId, $options->getOptionArray('providers', []))); } return true; @@ -427,7 +442,7 @@ class Index extends ACommandBase { * * @return array */ - private function generateUserList(IndexOptions $options) { + private function generateUserList(IndexOptions $options): array { if ($options->getOption('user', '') !== '') { return [$this->userManager->get($options->getOption('user'))]; } @@ -565,7 +580,7 @@ class Index extends ACommandBase { /** * @param int $pos */ - private function displayError($pos = 0) { + private function displayError(int $pos = 0) { $total = sizeof($this->errors); if ($total === 0) { @@ -579,11 +594,11 @@ class Index extends ACommandBase { return; } - $current = key($this->errors) + 1; - $error = $this->getNavigationError($pos, ($current === 1), ($current === $total)); - $current = key($this->errors) + 1; - - if ($error === false) { + try { + $current = key($this->errors) + 1; + $error = $this->getNavigationError($pos, ($current === 1), ($current === $total)); + $current = key($this->errors) + 1; + } catch (OutOfBoundsException $e) { return; } @@ -617,7 +632,7 @@ class Index extends ACommandBase { /** * @param int $pos */ - private function displayResult($pos = 0) { + private function displayResult(int $pos = 0) { $total = sizeof($this->results); if ($total === 0) { @@ -631,11 +646,11 @@ class Index extends ACommandBase { return; } - $current = key($this->results) + 1; - $result = $this->getNavigationResult($pos, ($current === 1), ($current === $total)); - $current = key($this->results) + 1; - - if ($result === false) { + try { + $current = key($this->results) + 1; + $result = $this->getNavigationResult($pos, ($current === 1), ($current === $total)); + $current = key($this->results) + 1; + } catch (OutOfBoundsException $e) { return; } @@ -649,10 +664,9 @@ class Index extends ACommandBase { $width = $this->terminal->getWidth() - 13; $message = MiscService::get('message', $result, ''); - $msg1 = substr($message, 0, $width); - $msg2 = substr($message, $width, $width + 10); - $msg3 = substr($message, $width + $width + 10, $width + 10); - + $msg1 = (string) substr($message, 0, $width); + $msg2 = (string) substr($message, $width, $width + 10); + $msg3 = (string) substr($message, $width + $width + 10, $width + 10); $status = MiscService::get('status', $result, ''); $type = MiscService::get('type', $result, ''); @@ -677,9 +691,10 @@ class Index extends ACommandBase { * @param bool $isFirst * @param bool $isLast * - * @return bool|array + * @throw OutOfBoundsException + * @return array */ - private function getNavigationError($pos, $isFirst, $isLast) { + private function getNavigationError(int $pos, bool $isFirst, bool $isLast): array { if ($pos === 0) { if ($this->navigateLastError === true) { @@ -708,7 +723,7 @@ class Index extends ACommandBase { return end($this->errors); } - return false; + throw new OutOfBoundsException(); } @@ -717,9 +732,10 @@ class Index extends ACommandBase { * @param bool $isFirst * @param bool $isLast * - * @return bool|array + * @throw OutOfBoundsException + * @return array */ - private function getNavigationResult($pos, $isFirst, $isLast) { + private function getNavigationResult(int $pos, bool $isFirst, bool $isLast): array { if ($pos === 0) { if ($this->navigateLastResult === true) { @@ -748,7 +764,7 @@ class Index extends ACommandBase { return end($this->results); } - return false; + throw new OutOfBoundsException(); } @@ -769,8 +785,6 @@ class Index extends ACommandBase { } } - - } @@ -824,10 +838,15 @@ class Index extends ACommandBase { /** - * @throws InterruptedException + * @throws TickDoesNotExistException */ public function abort() { - $this->abortIfInterrupted(); + try { + $this->abortIfInterrupted(); + } catch (InterruptedException $e) { + $this->runner->stop(); + exit(); + } } diff --git a/lib/Command/Live.php b/lib/Command/Live.php index ffdcc40..45125aa 100644 --- a/lib/Command/Live.php +++ b/lib/Command/Live.php @@ -1,4 +1,7 @@ errors[] = $error; $this->displayError(); } @@ -342,7 +348,7 @@ class Live extends ACommandBase { /** * @param array $result */ - public function onNewIndexResult($result) { + public function onNewIndexResult(array $result) { $this->results[] = $result; $this->displayResult(); } @@ -488,7 +494,7 @@ class Live extends ACommandBase { /** * @param int $pos */ - private function displayResult($pos = 0) { + private function displayResult(int $pos = 0) { $total = sizeof($this->results); if ($total === 0) { @@ -502,11 +508,11 @@ class Live extends ACommandBase { return; } - $current = key($this->results) + 1; - $result = $this->getNavigationResult($pos, ($current === 1), ($current === $total)); - $current = key($this->results) + 1; - - if ($result === false) { + try { + $current = key($this->results) + 1; + $result = $this->getNavigationResult($pos, ($current === 1), ($current === $total)); + $current = key($this->results) + 1; + } catch (OutOfBoundsException $e) { return; } @@ -545,7 +551,7 @@ class Live extends ACommandBase { /** * @param int $pos */ - private function displayError($pos = 0) { + private function displayError(int $pos = 0) { $total = sizeof($this->errors); if ($total === 0) { @@ -559,11 +565,11 @@ class Live extends ACommandBase { return; } - $current = key($this->errors) + 1; - $error = $this->getNavigationError($pos, ($current === 1), ($current === $total)); - $current = key($this->errors) + 1; - - if ($error === false) { + try { + $current = key($this->errors) + 1; + $error = $this->getNavigationError($pos, ($current === 1), ($current === $total)); + $current = key($this->errors) + 1; + } catch (OutOfBoundsException $e) { return; } @@ -599,9 +605,10 @@ class Live extends ACommandBase { * @param bool $isFirst * @param bool $isLast * - * @return bool|array + * @return array + * @throws OutOfBoundsException */ - private function getNavigationResult($pos, $isFirst, $isLast) { + private function getNavigationResult(int $pos, bool $isFirst, bool $isLast): array { if ($pos === 0) { if ($this->navigateLastResult === true) { @@ -630,7 +637,7 @@ class Live extends ACommandBase { return end($this->results); } - return false; + throw new OutOfBoundsException(); } @@ -639,9 +646,9 @@ class Live extends ACommandBase { * @param bool $isFirst * @param bool $isLast * - * @return bool|array + * @return array */ - private function getNavigationError($pos, $isFirst, $isLast) { + private function getNavigationError(int $pos, bool $isFirst, bool $isLast): array { if ($pos === 0) { if ($this->navigateLastError === true) { @@ -670,7 +677,7 @@ class Live extends ACommandBase { return end($this->errors); } - return false; + throw new OutOfBoundsException(); } @@ -724,10 +731,15 @@ class Live extends ACommandBase { /** - * @throws InterruptedException + * @throws TickDoesNotExistException */ public function abort() { - $this->abortIfInterrupted(); + try { + $this->abortIfInterrupted(); + } catch (InterruptedException $e) { + $this->runner->stop(); + exit(); + } } -- cgit v1.2.3 From 063b5bb56127e2b896dc30d81e542f58889650e2 Mon Sep 17 00:00:00 2001 From: Maxence Lange Date: Wed, 31 Oct 2018 10:25:15 +0100 Subject: migrating to php7 Signed-off-by: Maxence Lange --- lib/Command/Check.php | 13 ++-- lib/Command/Configure.php | 11 +++- lib/Command/DocumentPlatform.php | 6 +- lib/Command/DocumentProvider.php | 13 +++- lib/Command/Live.php | 5 ++ lib/Command/Reset.php | 27 ++++++-- lib/Command/Search.php | 15 ++++- lib/Command/Stop.php | 18 ++++++ lib/Command/Test.php | 130 ++++++++++++++++++++++++--------------- 9 files changed, 174 insertions(+), 64 deletions(-) (limited to 'lib') diff --git a/lib/Command/Check.php b/lib/Command/Check.php index 81ee47f..8d7af2f 100644 --- a/lib/Command/Check.php +++ b/lib/Command/Check.php @@ -1,4 +1,7 @@ setName('fulltextsearch:reset') @@ -80,7 +95,6 @@ class Reset extends ACommandBase { * @param InputInterface $input * @param OutputInterface $output * - * @return int|null|void * @throws Exception */ protected function execute(InputInterface $input, OutputInterface $output) { @@ -112,7 +126,7 @@ class Reset extends ACommandBase { * * @return string */ - private function getProviderIdFromArgument(InputInterface $input) { + private function getProviderIdFromArgument(InputInterface $input): string { $providerId = $input->getArgument('provider'); if ($providerId === null) { $providerId = ''; @@ -123,10 +137,15 @@ class Reset extends ACommandBase { /** - * @throws InterruptedException + * @throws TickDoesNotExistException */ public function abort() { - $this->abortIfInterrupted(); + try { + $this->abortIfInterrupted(); + } catch (InterruptedException $e) { + $this->runner->stop(); + exit(); + } } } diff --git a/lib/Command/Search.php b/lib/Command/Search.php index bd0ff28..0480b5e 100644 --- a/lib/Command/Search.php +++ b/lib/Command/Search.php @@ -1,4 +1,7 @@ setName('fulltextsearch:search') @@ -75,10 +88,10 @@ class Search extends Base { /** + * * @param InputInterface $input * @param OutputInterface $output * - * @return int|null|void * @throws Exception */ protected function execute(InputInterface $input, OutputInterface $output) { diff --git a/lib/Command/Stop.php b/lib/Command/Stop.php index a25a568..ac884f9 100644 --- a/lib/Command/Stop.php +++ b/lib/Command/Stop.php @@ -1,4 +1,7 @@ setName('fulltextsearch:stop') @@ -63,6 +77,10 @@ class Stop extends Base { } + /** + * @param InputInterface $input + * @param OutputInterface $output + */ protected function execute(InputInterface $input, OutputInterface $output) { $output->writeln('stopping all running indexes'); diff --git a/lib/Command/Test.php b/lib/Command/Test.php index c49055c..feb38f2 100644 --- a/lib/Command/Test.php +++ b/lib/Command/Test.php @@ -1,4 +1,7 @@ testLoadingPlatform($output); $this->testLockingProcess($output, $testPlatform, $testProvider); } catch (Exception $e) { - $this->output($output, false); + $this->outputResult($output, false); throw $e; } @@ -166,10 +176,10 @@ class Test extends Base { $this->testResetTest($output, $testProvider); $this->testUnlockingProcess($output); } catch (Exception $e) { - $this->output($output, false); + $this->outputResult($output, false); $this->output($output, 'Error detected, unlocking process'); $this->runner->stop(); - $this->output($output, true); + $this->outputResult($output, true); throw $e; } @@ -185,7 +195,7 @@ class Test extends Base { * @throws ProviderDoesNotExistException * @throws ProviderIsNotUniqueException */ - private function generateMockProvider() { + private function generateMockProvider(): IFullTextSearchProvider { $this->providerService->loadProvider( 'fulltextsearch', 'OCA\FullTextSearch\Provider\TestProvider' ); @@ -197,11 +207,10 @@ class Test extends Base { /** * @param OutputInterface $output - * @param string|bool $line + * @param string $line * @param bool $isNewLine */ - private function output(OutputInterface $output, $line, $isNewLine = true) { - $line = $this->convertBoolToLine($line, $isNewLine); + private function output(OutputInterface $output, string $line, bool $isNewLine = true) { if ($isNewLine) { $output->write(' ', true); } @@ -211,18 +220,25 @@ class Test extends Base { /** - * @param string|bool $line - * @param $isNewLine + * @param OutputInterface $output + * @param bool $result + */ + private function outputResult(OutputInterface $output, bool $result) { + $line = $this->convertBoolToLine($result, $isNewLine); + + $this->output($output, $line, $isNewLine); + } + + + /** + * @param bool $result + * @param bool $isNewLine * * @return string */ - private function convertBoolToLine($line, &$isNewLine) { - if (!is_bool($line)) { - return $line; - } - + private function convertBoolToLine(bool $result, bool &$isNewLine): string { $isNewLine = false; - if ($line === false) { + if ($result === false) { return 'fail'; } @@ -231,7 +247,7 @@ class Test extends Base { /** - * @param $output + * @param OutputInterface $output * * @return IFullTextSearchProvider * @throws ProviderDoesNotExistException @@ -239,48 +255,50 @@ class Test extends Base { * @throws ProviderIsNotUniqueException * @throws QueryException */ - private function testCreatingProvider($output) { + private function testCreatingProvider(OutputInterface $output): IFullTextSearchProvider { $this->output($output, 'Creating mocked content provider.'); $testProvider = $this->generateMockProvider(); - $this->output($output, true); + $this->outputResult($output, true); return $testProvider; } /** - * @param $output + * @param OutputInterface $output * @param IFullTextSearchProvider $testProvider */ - private function testMockedProvider($output, IFullTextSearchProvider $testProvider) { + private function testMockedProvider( + OutputInterface $output, IFullTextSearchProvider $testProvider + ) { $this->output($output, 'Testing mocked provider: get indexable documents.'); $testProvider->setIndexOptions(new IndexOptions()); $indexableDocuments = $testProvider->generateIndexableDocuments(TestService::DOCUMENT_USER1); $this->output($output, '(' . sizeof($indexableDocuments) . ' items)', false); - $this->output($output, true); + $this->outputResult($output, true); } /** - * @param $output + * @param OutputInterface $output * * @return IFullTextSearchPlatform * @throws Exception */ - private function testLoadingPlatform($output) { + private function testLoadingPlatform(OutputInterface $output): IFullTextSearchPlatform { $this->output($output, 'Loading search platform.'); $wrapper = $this->platformService->getPlatform(); $testPlatform = $wrapper->getPlatform(); $this->output($output, '(' . $testPlatform->getName() . ')', false); - $this->output($output, true); + $this->outputResult($output, true); $this->output($output, 'Testing search platform.'); if (!$testPlatform->testPlatform()) { throw new Exception ('Search platform (' . $testPlatform->getName() . ') down ?'); } - $this->output($output, true); + $this->outputResult($output, true); return $testPlatform; } @@ -298,11 +316,12 @@ class Test extends Base { ) { $this->output($output, 'Locking process'); $this->runner = new Runner($this->runningService, 'test'); + $this->runner->sourceIsCommandLine($this, $output); $this->runner->start(); $this->indexService->setRunner($this->runner); $testPlatform->setRunner($this->runner); $testProvider->setRunner($this->runner); - $this->output($output, true); + $this->outputResult($output, true); } @@ -316,7 +335,7 @@ class Test extends Base { ) { $this->output($output, 'Removing test.'); $this->indexService->resetIndex($testProvider->getId()); - $this->output($output, true); + $this->outputResult($output, true); } @@ -328,7 +347,7 @@ class Test extends Base { ) { $this->output($output, 'Initializing index mapping.'); $testPlatform->initializeIndex(); - $this->output($output, true); + $this->outputResult($output, true); } @@ -352,7 +371,7 @@ class Test extends Base { $this->indexService->indexProviderContentFromUser( $testPlatform, $testProvider, TestService::DOCUMENT_USER1, $options ); - $this->output($output, true); + $this->outputResult($output, true); } @@ -375,7 +394,7 @@ class Test extends Base { $this->output( $output, '(size: ' . $indexDocument->getContentSize() . ')', false ); - $this->output($output, true); + $this->outputResult($output, true); } catch (Exception $e) { throw new Exception( "Issue while getting test document '" . TestService::DOCUMENT_TYPE_LICENSE @@ -388,14 +407,13 @@ class Test extends Base { $this->testService->generateIndexDocumentContentLicense(new IndexOptions()), $indexDocument ); - $this->output($output, true); + $this->outputResult($output, true); } /** * @param OutputInterface $output * @param IFullTextSearchPlatform $testPlatform - * * @param IFullTextSearchProvider $testProvider * * @throws Exception @@ -456,7 +474,7 @@ class Test extends Base { $this->output($output, 'Updating documents access.'); $options = new IndexOptions( [ - 'provider' => TestProvider::TEST_PROVIDER_ID, + 'provider' => TestProvider::TEST_PROVIDER_ID, TestService::DOCUMENT_INDEXING_OPTION => TestService::DOCUMENT_INDEXING_ACCESS ] ); @@ -464,14 +482,13 @@ class Test extends Base { $this->indexService->indexProviderContentFromUser( $testPlatform, $testProvider, TestService::DOCUMENT_USER1, $options ); - $this->output($output, true); + $this->outputResult($output, true); } /** * @param OutputInterface $output * @param IFullTextSearchPlatform $platform - * * @param IFullTextSearchProvider $provider * * @throws Exception @@ -480,7 +497,6 @@ class Test extends Base { OutputInterface $output, IFullTextSearchPlatform $platform, IFullTextSearchProvider $provider ) { - $this->output($output, 'Searching with group access rights:'); $this->searchGroups($output, $platform, $provider, [], []); @@ -505,7 +521,6 @@ class Test extends Base { /** * @param OutputInterface $output * @param IFullTextSearchPlatform $platform - * * @param IFullTextSearchProvider $provider * * @throws Exception @@ -531,7 +546,7 @@ class Test extends Base { private function testUnlockingProcess(OutputInterface $output) { $this->output($output, 'Unlocking process'); $this->runner->stop(); - $this->output($output, true); + $this->outputResult($output, true); } @@ -549,7 +564,7 @@ class Test extends Base { private function search( OutputInterface $output, IFullTextSearchPlatform $testPlatform, IFullTextSearchProvider $testProvider, - DocumentAccess $access, $search, $expected, $moreOutput = '' + DocumentAccess $access, string $search, array $expected, string $moreOutput = '' ) { $this->output( $output, @@ -571,7 +586,7 @@ class Test extends Base { false ); $this->compareSearchResult($searchResult, $expected); - $this->output($output, true); + $this->outputResult($output, true); } @@ -586,7 +601,7 @@ class Test extends Base { */ private function searchGroups( OutputInterface $output, IFullTextSearchPlatform $testPlatform, - IFullTextSearchProvider $testProvider, $groups, $expected + IFullTextSearchProvider $testProvider, array $groups, array $expected ) { $access = new DocumentAccess(); @@ -611,7 +626,7 @@ class Test extends Base { */ private function searchUsers( OutputInterface $output, IFullTextSearchPlatform $testPlatform, - IFullTextSearchProvider $testProvider, $user, $expected + IFullTextSearchProvider $testProvider, string $user, array $expected ) { $access = new DocumentAccess(); $access->setViewerId($user); @@ -624,11 +639,11 @@ class Test extends Base { /** * @param SearchResult $searchResult - * @param $entries + * @param array $entries * * @throws Exception */ - private function compareSearchResult(SearchResult $searchResult, $entries) { + private function compareSearchResult(SearchResult $searchResult, array $entries) { $documents = $searchResult->getDocuments(); if (sizeof($documents) !== sizeof($entries)) { throw new \Exception('Unexpected SearchResult: ' . json_encode($searchResult)); @@ -648,7 +663,7 @@ class Test extends Base { * * @throws InterruptException */ - private function pause(OutputInterface $output, $s) { + private function pause(OutputInterface $output, int $s) { $this->output($output, 'Pausing ' . $s . ' seconds'); for ($i = 1; $i <= $s; $i++) { @@ -656,10 +671,23 @@ class Test extends Base { throw new InterruptException('Interrupted by user'); } - $this->output($output, $i, false); + $this->output($output, (string)$i, false); } - $this->output($output, true); + $this->outputResult($output, true); + } + + + /** + * @throws TickDoesNotExistException + */ + public function abort() { + try { + $this->abortIfInterrupted(); + } catch (InterruptedException $e) { + $this->runner->stop(); + exit(); + } } } -- cgit v1.2.3 From d75d0c868fe2c13a7885733031d0a7b65716c440 Mon Sep 17 00:00:00 2001 From: Maxence Lange Date: Wed, 31 Oct 2018 10:25:33 +0100 Subject: assure Base is not null Signed-off-by: Maxence Lange --- lib/Model/Runner.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/Model/Runner.php b/lib/Model/Runner.php index 3106573..37ae39c 100644 --- a/lib/Model/Runner.php +++ b/lib/Model/Runner.php @@ -136,7 +136,9 @@ class Runner implements IRunner { */ public function updateAction(string $action = '', bool $force = false): string { - $this->base->abort(); + if ($this->base !== null) { + $this->base->abort(); + } $n = ''; if (sizeof($this->methodOnKeyPress) > 0) { -- cgit v1.2.3 From 41bbf7c16c715de4aca54b413ccbfe1d526e73b4 Mon Sep 17 00:00:00 2001 From: Maxence Lange Date: Wed, 31 Oct 2018 10:32:28 +0100 Subject: compat NC15, no need for local API anymore Signed-off-by: Maxence Lange --- lib/Api/v1/FullTextSearch.php | 191 ------------------------------------------ 1 file changed, 191 deletions(-) delete mode 100644 lib/Api/v1/FullTextSearch.php (limited to 'lib') diff --git a/lib/Api/v1/FullTextSearch.php b/lib/Api/v1/FullTextSearch.php deleted file mode 100644 index 5d25f1d..0000000 --- a/lib/Api/v1/FullTextSearch.php +++ /dev/null @@ -1,191 +0,0 @@ - - * @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\Api\v1; - - -use OCA\FullTextSearch\Service\ConfigService; -use OCA\FullTextSearch\AppInfo\Application; -use OCA\FullTextSearch\Model\Index; -use OCA\FullTextSearch\Service\IndexService; -use OCA\FullTextSearch\Service\ProviderService; -use OCA\FullTextSearch\Service\SearchService; -use OCP\AppFramework\QueryException; -use OCP\Util; - -class FullTextSearch { - - const API_VERSION = [0, 1, 0]; - - protected static function getContainer() { - $app = new Application(); - - return $app->getContainer(); - } - - - /** - * returns app name - * - * @return string - */ - public static function appName() { - return Application::APP_NAME; - } - - - /** - * FullTextSearch::version(); - * - * returns the current version of the API - * - * @return array - * @throws QueryException - */ - public static function version() { - $c = self::getContainer(); - - return [ - [ - 'fulltextsearch' => $c->query(ConfigService::class) - ->getAppValue('installed_version') - ], - ['api' => self::API_VERSION] - ]; - } - - - /** - * - */ - public static function addJavascriptAPI() { - Util::addStyle(Application::APP_NAME, 'fulltextsearch'); - Util::addScript(Application::APP_NAME, 'fulltextsearch.v1.api'); - Util::addScript(Application::APP_NAME, 'fulltextsearch.v1.settings'); - Util::addScript(Application::APP_NAME, 'fulltextsearch.v1.searchbox'); - Util::addScript(Application::APP_NAME, 'fulltextsearch.v1.result'); - Util::addScript(Application::APP_NAME, 'fulltextsearch.v1.navigation'); - Util::addScript(Application::APP_NAME, 'fulltextsearch.v1'); - } - - - /** - * @param string $providerId - * @param string|int $documentId - * - * @return Index - * @throws QueryException - */ - public static function getIndex($providerId, $documentId) { - $c = self::getContainer(); - - return $c->query(IndexService::class) - ->getIndex($providerId, $documentId); - } - - - /** - * @param string $providerId - * @param string|int $documentId - * @param string $ownerId - * @param int $status - * - * @return mixed - * @throws QueryException - */ - public static function createIndex($providerId, $documentId, $ownerId, $status = 0) { - $index = new Index($providerId, $documentId); - $index->setOwnerId($ownerId); - $index->setStatus($status); - - return self::updateIndexes([$index]); - } - - - /** - * @param string $providerId - * @param string|int|array $documentIds - * @param int $status - * @param bool $reset - * - * @return mixed - * @throws QueryException - */ - public static function updateIndexStatus($providerId, $documentIds, $status, $reset = false) { - $c = self::getContainer(); - - if (!is_array($documentIds)) { - $documentIds = [$documentIds]; - } - - return $c->query(IndexService::class) - ->updateIndexesStatus($providerId, $documentIds, $status, $reset); - } - - - /** - * @param Index[] $indexes - * - * @return mixed - * @throws QueryException - */ - public static function updateIndexes($indexes) { - $c = self::getContainer(); - - return $c->query(IndexService::class) - ->updateIndexes($indexes); - } - - - /** - * @param string $providerId - * @param string|int $search - * - * @return mixed - * @throws QueryException - */ - public static function search($providerId, $search) { - $c = self::getContainer(); - - return $c->query(SearchService::class) - ->search($providerId, null, $search); - } - - - /** - * @param $providerId - * - * @return mixed - * @throws QueryException - */ - public static function isProviderIndexed($providerId) { - $c = self::getContainer(); - - return $c->query(ProviderService::class) - ->isProviderIndexed($providerId); - - } -} -- cgit v1.2.3 From 2fc15a8ea64385ecc2edbc74ba5ea618f1e203b2 Mon Sep 17 00:00:00 2001 From: Maxence Lange Date: Wed, 31 Oct 2018 10:33:02 +0100 Subject: migrating to php7 Signed-off-by: Maxence Lange --- lib/AppInfo/Application.php | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-) (limited to 'lib') diff --git a/lib/AppInfo/Application.php b/lib/AppInfo/Application.php index 61122c6..76f89db 100644 --- a/lib/AppInfo/Application.php +++ b/lib/AppInfo/Application.php @@ -1,4 +1,7 @@ container = $this->getContainer(); $this->container->registerCapability(Capabilities::class); - - $this->registerHooks(); - } - - - /** - * Register Hooks - */ - public function registerHooks() { } @@ -88,7 +89,6 @@ class Application extends App { * @throws QueryException */ public function registerNavigation() { - /** @var ConfigService $configService */ $configService = $this->container->query(ConfigService::class); if ($configService->getAppValue(ConfigService::APP_NAVIGATION) !== '1') { @@ -101,7 +101,10 @@ class Application extends App { } - private function fullTextSearchNavigation() { + /** + * @return array + */ + private function fullTextSearchNavigation(): array { $urlGen = \OC::$server->getURLGenerator(); $navName = \OC::$server->getL10N(self::APP_NAME) ->t('Full text search'); @@ -116,9 +119,5 @@ class Application extends App { } - public function registerSettingsAdmin() { - // \OCP\App::registerAdmin(self::APP_NAME, 'lib/admin'); - } - } -- cgit v1.2.3 From 759ad720b82f0d8e09ae819a69fce7af2597db25 Mon Sep 17 00:00:00 2001 From: Maxence Lange Date: Wed, 31 Oct 2018 11:20:15 +0100 Subject: using my-small-php-tools Signed-off-by: Maxence Lange --- lib/Controller/ApiController.php | 51 ++++++++++++++-------------------------- 1 file changed, 17 insertions(+), 34 deletions(-) (limited to 'lib') diff --git a/lib/Controller/ApiController.php b/lib/Controller/ApiController.php index 1c3b0e4..f973ea9 100644 --- a/lib/Controller/ApiController.php +++ b/lib/Controller/ApiController.php @@ -1,4 +1,7 @@ searchDocuments(SearchRequest::fromJSON($request)); } @@ -90,7 +100,7 @@ class ApiController extends Controller { * * @return DataResponse */ - public function searchFromRemote($request) { + public function searchFromRemote(string $request): DataResponse { return $this->searchDocuments(SearchRequest::fromJSON($request)); } @@ -100,54 +110,27 @@ class ApiController extends Controller { * * @return DataResponse */ - private function searchDocuments(SearchRequest $request) { + private function searchDocuments(SearchRequest $request): DataResponse { try { $result = $this->searchService->search('', $request); return $this->success( + $result, [ 'request' => $request, - 'result' => $result, 'version' => $this->configService->getAppValue('installed_version') ] ); } catch (Exception $e) { return $this->fail( + $e->getMessage(), [ 'request' => $request, - 'error' => $e->getMessage(), 'version' => $this->configService->getAppValue('installed_version') ] ); } } - - /** - * @param $data - * - * @return DataResponse - */ - protected function fail($data) { - $this->miscService->log(json_encode($data)); - - return new DataResponse( - array_merge($data, array('status' => 0)), - Http::STATUS_NON_AUTHORATIVE_INFORMATION - ); - } - - - /** - * @param $data - * - * @return DataResponse - */ - protected function success($data) { - return new DataResponse( - array_merge($data, array('status' => 1)), - Http::STATUS_CREATED - ); - } - } + -- cgit v1.2.3 From 8c675cf9af177965204dc70403f881457b619a8a Mon Sep 17 00:00:00 2001 From: Maxence Lange Date: Wed, 31 Oct 2018 11:20:38 +0100 Subject: some fixes Signed-off-by: Maxence Lange --- lib/Command/Index.php | 6 +++--- lib/Command/Live.php | 12 ++++++------ 2 files changed, 9 insertions(+), 9 deletions(-) (limited to 'lib') diff --git a/lib/Command/Index.php b/lib/Command/Index.php index 6fa14d1..b92d2fa 100644 --- a/lib/Command/Index.php +++ b/lib/Command/Index.php @@ -611,9 +611,9 @@ class Index extends ACommandBase { $width = $this->terminal->getWidth() - 13; $message = MiscService::get('message', $error, ''); - $err1 = substr($message, 0, $width); - $err2 = substr($message, $width, $width + 10); - $err3 = substr($message, $width + $width + 10, $width + 10); + $err1 = (string) substr($message, 0, $width); + $err2 = (string) substr($message, $width, $width + 10); + $err3 = (string) substr($message, $width + $width + 10, $width + 10); $this->runner->setInfoArray( [ diff --git a/lib/Command/Live.php b/lib/Command/Live.php index 0f3ffbc..0e213de 100644 --- a/lib/Command/Live.php +++ b/lib/Command/Live.php @@ -531,9 +531,9 @@ class Live extends ACommandBase { $width = $this->terminal->getWidth() - 13; $message = MiscService::get('message', $result, ''); - $msg1 = substr($message, 0, $width); - $msg2 = substr($message, $width, $width + 10); - $msg3 = substr($message, $width + $width + 10, $width + 10); + $msg1 = (string) substr($message, 0, $width); + $msg2 = (string) substr($message, $width, $width + 10); + $msg3 = (string) substr($message, $width + $width + 10, $width + 10); $status = MiscService::get('status', $result, ''); @@ -587,9 +587,9 @@ class Live extends ACommandBase { $width = $this->terminal->getWidth() - 13; $message = MiscService::get('message', $error, ''); - $err1 = substr($message, 0, $width); - $err2 = substr($message, $width, $width + 10); - $err3 = substr($message, $width + $width + 10, $width + 10); + $err1 = (string) substr($message, 0, $width); + $err2 = (string) substr($message, $width, $width + 10); + $err3 = (string) substr($message, $width + $width + 10, $width + 10); $this->runner->setInfoArray( [ -- cgit v1.2.3 From 7b75f049ee5f32ee552a4ec6812073e28c5b2494 Mon Sep 17 00:00:00 2001 From: Maxence Lange Date: Wed, 31 Oct 2018 11:24:31 +0100 Subject: migrating to php7 Signed-off-by: Maxence Lange --- lib/Controller/ApiController.php | 5 +++++ lib/Controller/NavigationController.php | 16 ++++++++++++++-- lib/Controller/SettingsController.php | 15 +++++++++++++-- lib/Controller/TemplatesController.php | 17 ++++++++++++++--- 4 files changed, 46 insertions(+), 7 deletions(-) (limited to 'lib') diff --git a/lib/Controller/ApiController.php b/lib/Controller/ApiController.php index f973ea9..2b3ff55 100644 --- a/lib/Controller/ApiController.php +++ b/lib/Controller/ApiController.php @@ -43,6 +43,11 @@ use OCP\AppFramework\Http\DataResponse; use OCP\IRequest; +/** + * Class ApiController + * + * @package OCA\FullTextSearch\Controller + */ class ApiController extends Controller { diff --git a/lib/Controller/NavigationController.php b/lib/Controller/NavigationController.php index d18e600..da2977a 100644 --- a/lib/Controller/NavigationController.php +++ b/lib/Controller/NavigationController.php @@ -1,4 +1,7 @@ config->getAppValue('theming', 'name', 'Nextcloud'); @@ -81,4 +93,4 @@ class NavigationController extends Controller { } -} \ No newline at end of file +} diff --git a/lib/Controller/SettingsController.php b/lib/Controller/SettingsController.php index 52e6b72..ea5c1bf 100644 --- a/lib/Controller/SettingsController.php +++ b/lib/Controller/SettingsController.php @@ -1,4 +1,7 @@ configService->getConfig(); $this->settingsService->completeSettings($data); @@ -93,4 +104,4 @@ class SettingsController extends Controller { return $this->getSettingsAdmin(); } -} \ No newline at end of file +} diff --git a/lib/Controller/TemplatesController.php b/lib/Controller/TemplatesController.php index 5364e20..9157742 100644 --- a/lib/Controller/TemplatesController.php +++ b/lib/Controller/TemplatesController.php @@ -1,4 +1,7 @@ providerService->getProvider($providerId); $provider = $providerWrapper->getProvider(); @@ -118,7 +129,7 @@ class TemplatesController extends Controller { * @return DataResponse * @throws Exception */ - public function getNavigationPanels() { + public function getNavigationPanels(): DataResponse { $providers = $this->providerService->getProviders(); $ret = []; -- cgit v1.2.3 From 8c74cc866d5f48ecff844afb41715560ce7fd568 Mon Sep 17 00:00:00 2001 From: Maxence Lange Date: Wed, 31 Oct 2018 11:33:15 +0100 Subject: compat NC15 Signed-off-by: Maxence Lange --- lib/Controller/NavigationController.php | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/Controller/NavigationController.php b/lib/Controller/NavigationController.php index da2977a..97a51e2 100644 --- a/lib/Controller/NavigationController.php +++ b/lib/Controller/NavigationController.php @@ -36,6 +36,7 @@ use OCA\FullTextSearch\Service\ConfigService; use OCA\FullTextSearch\Service\MiscService; use OCP\AppFramework\Controller; use OCP\AppFramework\Http\TemplateResponse; +use OCP\FullTextSearch\IFullTextSearchManager; use OCP\IConfig; use OCP\IRequest; @@ -51,6 +52,9 @@ class NavigationController extends Controller { /** @var IConfig */ private $config; + /** @var IFullTextSearchManager */ + private $fullTextSearchManager; + /** @var ConfigService */ private $configService; @@ -67,10 +71,12 @@ class NavigationController extends Controller { * @param MiscService $miscService */ public function __construct( - IRequest $request, IConfig $config, ConfigService $configService, MiscService $miscService + IRequest $request, IConfig $config, IFullTextSearchManager $fullTextSearchManager, + ConfigService $configService, MiscService $miscService ) { parent::__construct(Application::APP_NAME, $request); $this->config = $config; + $this->fullTextSearchManager = $fullTextSearchManager; $this->configService = $configService; $this->miscService = $miscService; } @@ -87,7 +93,11 @@ class NavigationController extends Controller { $themingName = $this->config->getAppValue('theming', 'name', 'Nextcloud'); - $data = ['themingName' => $themingName]; + $data = [ + 'themingName' => $themingName + ]; + + $this->fullTextSearchManager->addJavascriptAPI(); return new TemplateResponse(Application::APP_NAME, 'navigate', $data); } -- cgit v1.2.3 From 6bc1ffdef4a90317c79a6e8e87ef3d03ee5e090d Mon Sep 17 00:00:00 2001 From: Maxence Lange Date: Wed, 31 Oct 2018 15:19:03 +0100 Subject: not relevant anymore Signed-off-by: Maxence Lange --- lib/Migration/ResetIndexes.php | 102 ----------------------------------------- 1 file changed, 102 deletions(-) delete mode 100644 lib/Migration/ResetIndexes.php (limited to 'lib') diff --git a/lib/Migration/ResetIndexes.php b/lib/Migration/ResetIndexes.php deleted file mode 100644 index 7bc1389..0000000 --- a/lib/Migration/ResetIndexes.php +++ /dev/null @@ -1,102 +0,0 @@ - - * @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\Migration; - -use OCA\FullTextSearch\Db\IndexesRequest; -use OCA\FullTextSearch\Service\ProviderService; -use OCP\Migration\IOutput; -use OCP\Migration\IRepairStep; - -/** - * Class ResetDatabase - * - * @package OCA\FullTextSearch\Migration - */ -class ResetIndexes implements IRepairStep { - - /** @var IndexesRequest */ - protected $indexRequest; - - /** @var ProviderService */ - protected $providerService; - - - /** - * ResetDatabase constructor. - * - * @param IndexesRequest $indexRequest - * @param ProviderService $providerService - */ - public function __construct(IndexesRequest $indexRequest, ProviderService $providerService) { - $this->indexRequest = $indexRequest; - $this->providerService = $providerService; - } - - - /** - * Returns the step's name - * - * @return string - * @since 9.1.0 - */ - public function getName() { - return 'Reset index'; - } - - - /** - * @param IOutput $output - */ - public function run(IOutput $output) { - - $oldVersion = explode( - '.', \OC::$server->getConfig() - ->getAppValue('fulltextsearch', 'installed_version', '') - ); - - if ((int)$oldVersion[0] === 0 - && (int)$oldVersion[1] < 6) { - $this->resetIndexes($output); - } - - } - - - /** - * @param IOutput $output - */ - public function resetIndexes(IOutput $output) { - $output->info('Reset database'); - -// $this->indexRequest->reset(); -// $this->providerService->setProvidersAsNotIndexed(); - - - $output->finishProgress(); - } - -} -- cgit v1.2.3 From a8117742614b5b4df6fc8a2877d1c373bf2db37e Mon Sep 17 00:00:00 2001 From: Maxence Lange Date: Wed, 31 Oct 2018 15:19:19 +0100 Subject: strict Signed-off-by: Maxence Lange --- lib/Cron/Index.php | 8 ++++++-- lib/Exceptions/DatabaseException.php | 5 +++++ lib/Exceptions/EmptySearchException.php | 5 +++++ lib/Exceptions/IndexDoesNotExistException.php | 5 +++++ lib/Exceptions/InterruptException.php | 5 +++++ lib/Exceptions/MissingDocumentException.php | 5 +++++ lib/Exceptions/NoResultException.php | 5 +++++ lib/Exceptions/NotIndexableDocumentException.php | 5 +++++ lib/Exceptions/PlatformDoesNotExistException.php | 5 +++++ lib/Exceptions/PlatformIsNotCompatibleException.php | 5 +++++ lib/Exceptions/PlatformMustBeSingleException.php | 5 +++++ lib/Exceptions/PlatformNotDefinedException.php | 5 +++++ lib/Exceptions/PlatformNotSelectedException.php | 5 +++++ lib/Exceptions/ProviderDoesNotExistException.php | 5 +++++ lib/Exceptions/ProviderIsNotCompatibleException.php | 5 +++++ lib/Exceptions/ProviderIsNotUniqueException.php | 5 +++++ lib/Exceptions/ProviderOptionsDoesNotExistException.php | 5 +++++ lib/Exceptions/RunnerAlreadyUpException.php | 5 +++++ lib/Exceptions/TickDoesNotExistException.php | 5 +++++ lib/Exceptions/TickIsNotAliveException.php | 5 +++++ lib/Model/SearchRequest.php | 2 +- 21 files changed, 102 insertions(+), 3 deletions(-) (limited to 'lib') diff --git a/lib/Cron/Index.php b/lib/Cron/Index.php index 4cf8497..f54d47b 100644 --- a/lib/Cron/Index.php +++ b/lib/Cron/Index.php @@ -1,4 +1,6 @@ configService->getAppValue(ConfigService::CRON_LAST_ERR_RESET); if ($lastErrReset === 0) { diff --git a/lib/Exceptions/DatabaseException.php b/lib/Exceptions/DatabaseException.php index b285337..81c82c6 100644 --- a/lib/Exceptions/DatabaseException.php +++ b/lib/Exceptions/DatabaseException.php @@ -1,4 +1,7 @@ Date: Wed, 31 Oct 2018 15:57:15 +0100 Subject: migrating to php7 Signed-off-by: Maxence Lange --- lib/Db/CoreRequestBuilder.php | 67 +++++++++++++++++++++++++++++++--------- lib/Db/IndexesRequest.php | 59 ++++++++++++++++++++++++++--------- lib/Db/IndexesRequestBuilder.php | 38 ++++++++++------------- lib/Db/TickRequest.php | 21 +++++++++---- lib/Db/TickRequestBuilder.php | 36 ++++++++++----------- 5 files changed, 144 insertions(+), 77 deletions(-) (limited to 'lib') diff --git a/lib/Db/CoreRequestBuilder.php b/lib/Db/CoreRequestBuilder.php index d1223e4..d90054c 100644 --- a/lib/Db/CoreRequestBuilder.php +++ b/lib/Db/CoreRequestBuilder.php @@ -1,4 +1,7 @@ limitToDBField($qb, 'id', $id); + protected function limitToId(IQueryBuilder &$qb, int $id) { + $this->limitToDBFieldInt($qb, 'id', $id); } @@ -92,18 +102,18 @@ class CoreRequestBuilder { * @param IQueryBuilder $qb * @param string $userId */ - protected function limitToOwnerId(IQueryBuilder &$qb, $userId) { + protected function limitToOwnerId(IQueryBuilder &$qb, string $userId) { $this->limitToDBField($qb, 'owner_id', $userId); } /** - * Limit to the type + * Limit to the providerId * * @param IQueryBuilder $qb * @param string $providerId */ - protected function limitToProviderId(IQueryBuilder &$qb, $providerId) { + protected function limitToProviderId(IQueryBuilder &$qb, string $providerId) { $this->limitToDBField($qb, 'provider_id', $providerId); } @@ -114,13 +124,13 @@ class CoreRequestBuilder { * @param IQueryBuilder $qb * @param string $documentId */ - protected function limitToDocumentId(IQueryBuilder &$qb, $documentId) { + protected function limitToDocumentId(IQueryBuilder &$qb, string $documentId) { $this->limitToDBField($qb, 'document_id', $documentId); } /** - * Limit to the documentId + * Limit to the entry with at least one Error * * @param IQueryBuilder $qb */ @@ -131,7 +141,7 @@ class CoreRequestBuilder { /** - * Limit to the documentId + * Limit to the entry with no error * * @param IQueryBuilder $qb */ @@ -147,39 +157,66 @@ class CoreRequestBuilder { * @param IQueryBuilder $qb * @param array $documentIds */ - protected function limitToDocumentIds(IQueryBuilder &$qb, $documentIds) { - $this->limitToDBField($qb, 'document_id', $documentIds); + protected function limitToDocumentIds(IQueryBuilder &$qb, array $documentIds) { + $this->limitToDBFieldArray($qb, 'document_id', $documentIds); } /** - * Limit the request to the Source + * Limit the request to source * * @param IQueryBuilder $qb * @param string $source */ - protected function limitToSource(IQueryBuilder &$qb, $source) { + protected function limitToSource(IQueryBuilder &$qb, string $source) { $this->limitToDBField($qb, 'id', $source); } /** - * Limit the request to the Source + * Limit the request to status * * @param IQueryBuilder $qb * @param string $status */ - protected function limitToStatus(IQueryBuilder &$qb, $status) { + protected function limitToStatus(IQueryBuilder &$qb, string $status) { $this->limitToDBField($qb, 'status', $status); } + /** + * @param IQueryBuilder $qb + * @param string $field + * @param string $value + */ + private function limitToDBField(IQueryBuilder &$qb, string $field, string $value) { + $expr = $qb->expr(); + $pf = ($qb->getType() === QueryBuilder::SELECT) ? $this->defaultSelectAlias . '.' : ''; + $field = $pf . $field; + + $qb->andWhere($expr->eq($field, $qb->createNamedParameter($value))); + } + + /** + * @param IQueryBuilder $qb + * @param string $field + * @param int $value + */ + private function limitToDBFieldInt(IQueryBuilder &$qb, string $field, int $value) { + $expr = $qb->expr(); + $pf = ($qb->getType() === QueryBuilder::SELECT) ? $this->defaultSelectAlias . '.' : ''; + $field = $pf . $field; + + $qb->andWhere($expr->eq($field, $qb->createNamedParameter($value))); + } + + /** * @param IQueryBuilder $qb * @param string $field * @param string|integer|array $values */ - private function limitToDBField(IQueryBuilder &$qb, $field, $values) { + private function limitToDBFieldArray(IQueryBuilder &$qb, string $field, array $values) { $expr = $qb->expr(); $pf = ($qb->getType() === QueryBuilder::SELECT) ? $this->defaultSelectAlias . '.' : ''; $field = $pf . $field; diff --git a/lib/Db/IndexesRequest.php b/lib/Db/IndexesRequest.php index 2eb225c..4b5b45f 100644 --- a/lib/Db/IndexesRequest.php +++ b/lib/Db/IndexesRequest.php @@ -1,4 +1,7 @@ getIndexesInsertSql(); @@ -69,7 +78,7 @@ class IndexesRequest extends IndexesRequestBuilder { * * @return bool */ - public function resetError(Index $index) { + public function resetError(Index $index): bool { try { $this->getIndex($index->getProviderId(), $index->getDocumentId()); @@ -105,7 +114,7 @@ class IndexesRequest extends IndexesRequestBuilder { /** * @return Index[] */ - public function getErrorIndexes() { + public function getErrorIndexes(): array { $qb = $this->getIndexesSelectSql(); $this->limitToErr($qb); @@ -126,7 +135,7 @@ class IndexesRequest extends IndexesRequestBuilder { * * @return bool */ - public function update(Index $index) { + public function update(Index $index): bool { try { $this->getIndex($index->getProviderId(), $index->getDocumentId()); @@ -159,12 +168,32 @@ class IndexesRequest extends IndexesRequestBuilder { } - public function updateStatus($providerId, $indexes, $status) { + /** + * @param string $providerId + * @param string $documentId + * @param int $status + */ + public function updateStatus(string $providerId, string $documentId, int $status) { + $qb = $this->getIndexesUpdateSql(); + $qb->set('status', $qb->createNamedParameter($status)); + + $this->limitToProviderId($qb, $providerId); + $this->limitToDocumentId($qb, $documentId); + + $qb->execute(); + } + + /** + * @param string $providerId + * @param array $indexes + * @param int $status + */ + public function updateStatuses(string $providerId, array $indexes, int $status) { $qb = $this->getIndexesUpdateSql(); $qb->set('status', $qb->createNamedParameter($status)); $this->limitToProviderId($qb, $providerId); - $this->limitToDocumentId($qb, $indexes); + $this->limitToDocumentIds($qb, $indexes); $qb->execute(); } @@ -185,7 +214,7 @@ class IndexesRequest extends IndexesRequestBuilder { /** * @param string $providerId */ - public function deleteFromProviderId($providerId) { + public function deleteFromProviderId(string $providerId) { $qb = $this->getIndexesDeleteSql(); $this->limitToProviderId($qb, $providerId); @@ -207,12 +236,12 @@ class IndexesRequest extends IndexesRequestBuilder { * return index. * * @param string $providerId - * @param string|int $documentId + * @param string $documentId * * @return Index * @throws IndexDoesNotExistException */ - public function getIndex($providerId, $documentId): Index { + public function getIndex(string $providerId, string $documentId): Index { $qb = $this->getIndexesSelectSql(); $this->limitToProviderId($qb, $providerId); $this->limitToDocumentId($qb, $documentId); @@ -238,7 +267,7 @@ class IndexesRequest extends IndexesRequestBuilder { * @return Index[] * @throws IndexDoesNotExistException */ - public function getIndexes($providerId, $documentIds) { + public function getIndexes(string $providerId, array $documentIds): array { $qb = $this->getIndexesSelectSql(); $this->limitToProviderId($qb, $providerId); $this->limitToDocumentIds($qb, $documentIds); @@ -263,7 +292,7 @@ class IndexesRequest extends IndexesRequestBuilder { * * @return Index[] */ - public function getQueuedIndexes($all = false) { + public function getQueuedIndexes(bool $all = false): array { $qb = $this->getIndexesSelectSql(); $this->limitToQueuedIndexes($qb); if ($all === false) { @@ -284,13 +313,13 @@ class IndexesRequest extends IndexesRequestBuilder { /** * return list of last indexes from a providerId. * - * @param IFullTextSearchProvider $provider + * @param string $providerId * * @return Index[] */ - public function getIndexesFromProvider(IFullTextSearchProvider $provider) { + public function getIndexesFromProvider(string $providerId): array { $qb = $this->getIndexesSelectSql(); - $this->limitToProviderId($qb, $provider->getId()); + $this->limitToProviderId($qb, $providerId); $indexes = []; $cursor = $qb->execute(); diff --git a/lib/Db/IndexesRequestBuilder.php b/lib/Db/IndexesRequestBuilder.php index 0eb47c2..0eb72ce 100644 --- a/lib/Db/IndexesRequestBuilder.php +++ b/lib/Db/IndexesRequestBuilder.php @@ -1,4 +1,7 @@ dbConnection->getQueryBuilder(); $qb->insert(self::TABLE_INDEXES); @@ -68,7 +61,7 @@ class IndexesRequestBuilder extends CoreRequestBuilder { * * @return IQueryBuilder */ - protected function getIndexesUpdateSql() { + protected function getIndexesUpdateSql(): IQueryBuilder { $qb = $this->dbConnection->getQueryBuilder(); $qb->update(self::TABLE_INDEXES); @@ -81,7 +74,7 @@ class IndexesRequestBuilder extends CoreRequestBuilder { * * @return IQueryBuilder */ - protected function getIndexesSelectSql() { + protected function getIndexesSelectSql(): IQueryBuilder { $qb = $this->dbConnection->getQueryBuilder(); /** @noinspection PhpMethodParametersCountMismatchInspection */ @@ -102,7 +95,7 @@ class IndexesRequestBuilder extends CoreRequestBuilder { * * @return IQueryBuilder */ - protected function getIndexesDeleteSql() { + protected function getIndexesDeleteSql(): IQueryBuilder { $qb = $this->dbConnection->getQueryBuilder(); $qb->delete(self::TABLE_INDEXES); @@ -115,7 +108,7 @@ class IndexesRequestBuilder extends CoreRequestBuilder { * * @return Index */ - protected function parseIndexesSelectSql($data) { + protected function parseIndexesSelectSql(array $data): Index { $index = new Index($data['provider_id'], $data['document_id']); $index->setStatus($data['status']) ->setSource($data['source']) @@ -129,3 +122,4 @@ class IndexesRequestBuilder extends CoreRequestBuilder { } } + diff --git a/lib/Db/TickRequest.php b/lib/Db/TickRequest.php index 4338450..6e50678 100644 --- a/lib/Db/TickRequest.php +++ b/lib/Db/TickRequest.php @@ -1,4 +1,7 @@ getTickInsertSql(); @@ -65,7 +74,7 @@ class TickRequest extends TickRequestBuilder { * * @return bool */ - public function update(Tick $tick) { + public function update(Tick $tick): bool { try { $this->getTickById($tick->getId()); @@ -117,7 +126,7 @@ class TickRequest extends TickRequestBuilder { * @return Tick * @throws TickDoesNotExistException */ - public function getTickById($id) { + public function getTickById(int $id): Tick { $qb = $this->getTickSelectSql(); $this->limitToId($qb, $id); @@ -134,13 +143,13 @@ class TickRequest extends TickRequestBuilder { /** - * return tick. + * return ticks. * * @param string $status * * @return Tick[] */ - public function getTickByStatus($status) { + public function getTicksByStatus(string $status): array { $ticks = []; @@ -162,7 +171,7 @@ class TickRequest extends TickRequestBuilder { * * @return Tick[] */ - public function getTickBySource($source) { + public function getTicksBySource(string $source): array { $qb = $this->getTickSelectSql(); $this->limitToSource($qb, $source); diff --git a/lib/Db/TickRequestBuilder.php b/lib/Db/TickRequestBuilder.php index cd3cf09..e19ca84 100644 --- a/lib/Db/TickRequestBuilder.php +++ b/lib/Db/TickRequestBuilder.php @@ -1,4 +1,7 @@ dbConnection->getQueryBuilder(); $qb->insert(self::TABLE_TICKS); @@ -67,7 +65,7 @@ class TickRequestBuilder extends CoreRequestBuilder { * * @return IQueryBuilder */ - protected function getTickUpdateSql() { + protected function getTickUpdateSql(): IQueryBuilder { $qb = $this->dbConnection->getQueryBuilder(); $qb->update(self::TABLE_TICKS); @@ -80,7 +78,7 @@ class TickRequestBuilder extends CoreRequestBuilder { * * @return IQueryBuilder */ - protected function getTickSelectSql() { + protected function getTickSelectSql(): IQueryBuilder { $qb = $this->dbConnection->getQueryBuilder(); /** @noinspection PhpMethodParametersCountMismatchInspection */ @@ -100,7 +98,7 @@ class TickRequestBuilder extends CoreRequestBuilder { * * @return IQueryBuilder */ - protected function getTickDeleteSql() { + protected function getTickDeleteSql(): IQueryBuilder { $qb = $this->dbConnection->getQueryBuilder(); $qb->delete(self::TABLE_INDEXES); @@ -113,12 +111,12 @@ class TickRequestBuilder extends CoreRequestBuilder { * * @return Tick */ - protected function parseTickSelectSql($data) { + protected function parseTickSelectSql(array $data): Tick { $tick = new Tick($data['source'], $data['id']); $tick->setData(json_decode($data['data'], true)) ->setTick($data['tick']) - ->setFirstTick($data['first_tick']) - ->setStatus($data['status']) + ->setFirstTick($data['first_tick']) + ->setStatus($data['status']) ->setAction($data['action']); return $tick; -- cgit v1.2.3 From f60c1b1f740bd28efc10d7715184115193e6a9a0 Mon Sep 17 00:00:00 2001 From: Maxence Lange Date: Wed, 31 Oct 2018 16:03:33 +0100 Subject: migrating to php7 Signed-off-by: Maxence Lange --- lib/Capabilities.php | 13 ++++++++++--- lib/Provider/TestProvider.php | 12 ++++++++++-- lib/Settings/Admin.php | 20 ++++++++++++++++---- lib/Settings/AdminSection.php | 23 ++++++++++++++++++----- 4 files changed, 54 insertions(+), 14 deletions(-) (limited to 'lib') diff --git a/lib/Capabilities.php b/lib/Capabilities.php index dbfdd5e..d662ae8 100644 --- a/lib/Capabilities.php +++ b/lib/Capabilities.php @@ -1,4 +1,7 @@ > * @throws Exception */ - public function getCapabilities() { + public function getCapabilities(): array { $providers = $this->providerService->getConfiguredProviders(); diff --git a/lib/Provider/TestProvider.php b/lib/Provider/TestProvider.php index 1247faf..360c12b 100644 --- a/lib/Provider/TestProvider.php +++ b/lib/Provider/TestProvider.php @@ -1,4 +1,7 @@ testService->generateIndexDocumentContentLicense($this->indexOptions); $result[] = $this->testService->generateIndexDocumentSimple($this->indexOptions); -// $result[] = $this->testService->generateIndexDocuments(TestService::DOCUMENT_TEST_INDEX3); - return $result; } diff --git a/lib/Settings/Admin.php b/lib/Settings/Admin.php index 3ab45dc..23c9b47 100644 --- a/lib/Settings/Admin.php +++ b/lib/Settings/Admin.php @@ -1,4 +1,7 @@ l10n = $l10n; $this->urlGenerator = $urlGenerator; @@ -70,7 +82,7 @@ class Admin implements ISettings { * @return TemplateResponse * @throws Exception */ - public function getForm() { + public function getForm(): TemplateResponse { return new TemplateResponse(Application::APP_NAME, 'settings.admin', []); } @@ -78,7 +90,7 @@ class Admin implements ISettings { /** * @return string the section ID, e.g. 'sharing' */ - public function getSection() { + public function getSection(): string { return Application::APP_NAME; } @@ -90,7 +102,7 @@ class Admin implements ISettings { * * keep the server setting at the top, right after "server settings" */ - public function getPriority() { + public function getPriority(): int { return 0; } diff --git a/lib/Settings/AdminSection.php b/lib/Settings/AdminSection.php index 9365477..ed8d487 100644 --- a/lib/Settings/AdminSection.php +++ b/lib/Settings/AdminSection.php @@ -1,4 +1,7 @@ . - * + * */ + namespace OCA\FullTextSearch\Settings; + use OCA\FullTextSearch\AppInfo\Application; use OCP\IL10N; use OCP\IURLGenerator; use OCP\Settings\IIconSection; + +/** + * Class AdminSection + * + * @package OCA\FullTextSearch\Settings + */ class AdminSection implements IIconSection { + /** @var IL10N */ private $l10n; /** @var IURLGenerator */ private $urlGenerator; + /** * @param IL10N $l10n * @param IURLGenerator $urlGenerator @@ -51,28 +64,28 @@ class AdminSection implements IIconSection { /** * {@inheritdoc} */ - public function getID() { + public function getID(): string { return Application::APP_NAME; } /** * {@inheritdoc} */ - public function getName() { + public function getName(): string { return $this->l10n->t('Full text search'); } /** * {@inheritdoc} */ - public function getPriority() { + public function getPriority(): int { return 55; } /** * {@inheritdoc} */ - public function getIcon() { + public function getIcon(): string { return $this->urlGenerator->imagePath(Application::APP_NAME, 'fulltextsearch_black.svg'); } } -- cgit v1.2.3 From 57f01b5e0635291e7334293a929b005c5172af8c Mon Sep 17 00:00:00 2001 From: Maxence Lange Date: Wed, 31 Oct 2018 18:40:45 +0100 Subject: migrating php7 Signed-off-by: Maxence Lange --- lib/Model/Index.php | 36 +++++++++------- lib/Model/IndexOptions.php | 49 +++++++++++---------- lib/Model/PlatformWrapper.php | 16 ++++--- lib/Model/ProviderIndexes.php | 15 ++++++- lib/Model/ProviderWrapper.php | 18 +++++--- lib/Model/Runner.php | 70 ++++++++++++++++++------------ lib/Model/SearchRequest.php | 80 ++++++++++++++++++---------------- lib/Model/SearchResult.php | 76 +++++++++++++++++++-------------- lib/Model/Tick.php | 99 +++++++++++++++++++++++++++++++------------ 9 files changed, 282 insertions(+), 177 deletions(-) (limited to 'lib') diff --git a/lib/Model/Index.php b/lib/Model/Index.php index 34ba9dc..dd25e68 100644 --- a/lib/Model/Index.php +++ b/lib/Model/Index.php @@ -30,13 +30,23 @@ declare(strict_types=1); namespace OCA\FullTextSearch\Model; + +use daita\MySmallPhpTools\Traits\TArrayTools; use JsonSerializable; use OCP\FullTextSearch\Model\IIndex; +/** + * Class Index + * + * @package OCA\FullTextSearch\Model + */ class Index implements IIndex, JsonSerializable { + use TArrayTools; + + /** @var string */ private $providerId; @@ -229,11 +239,7 @@ class Index implements IIndex, JsonSerializable { * @return string */ public function getOption(string $option, string $default = ''): string { - if (!array_key_exists($option, $this->options)) { - return $default; - } - - return $this->options[$option]; + return $this->get($option, $this->options, $default); } @@ -244,13 +250,10 @@ class Index implements IIndex, JsonSerializable { * @return int */ public function getOptionInt(string $option, int $default = 0): int { - if (!array_key_exists($option, $this->options)) { - return $default; - } - - return $this->options[$option]; + return $this->getInt($option, $this->options, $default); } + /** * @param int $err * @@ -276,9 +279,8 @@ class Index implements IIndex, JsonSerializable { return array_values(array_slice($this->errors, -1))[0]; } - /** - * + * @return IIndex */ public function resetErrors(): IIndex { $this->setErrors([]); @@ -351,9 +353,9 @@ class Index implements IIndex, JsonSerializable { /** - * @return array + * @return array */ - public function jsonSerialize() { + public function jsonSerialize(): array { return [ 'ownerId' => $this->getOwnerId(), 'providerId' => $this->getProviderId(), @@ -368,14 +370,18 @@ class Index implements IIndex, JsonSerializable { } + /** + * + */ public function __destruct() { unset($this->providerId); unset($this->documentId); + unset($this->source); unset($this->ownerId); unset($this->status); unset($this->options); unset($this->err); - unset($this->message); + unset($this->errors); unset($this->lastIndex); } diff --git a/lib/Model/IndexOptions.php b/lib/Model/IndexOptions.php index 1261bab..e5fdd25 100644 --- a/lib/Model/IndexOptions.php +++ b/lib/Model/IndexOptions.php @@ -1,4 +1,7 @@ options = $options; } + /** * @return array */ @@ -104,14 +125,9 @@ class IndexOptions implements IIndexOptions, JsonSerializable { * @return string */ public function getOption(string $option, string $default = ''): string { - if (array_key_exists($option, $this->options)) { - return $this->options[$option]; - } - - return $default; + return $this->get($option, $this->options, $default); } - /** * @param string $option * @param array $default @@ -119,14 +135,7 @@ class IndexOptions implements IIndexOptions, JsonSerializable { * @return array */ public function getOptionArray(string $option, array $default = []): array { - if (array_key_exists($option, $this->options)) { - $options = $this->options[$option]; - if (is_array($options)) { - return $this->options[$option]; - } - } - - return $default; + return $this->getArray($option, $this->options, $default); } @@ -137,21 +146,15 @@ class IndexOptions implements IIndexOptions, JsonSerializable { * @return bool */ public function getOptionBool(string $option, bool $default): bool { - if (array_key_exists($option, $this->options)) { - $options = $this->options[$option]; - if (is_bool($options)) { - return $this->options[$option]; - } - } - - return $default; + return $this->getBool($option, $this->options, $default); } /** * @return array */ - public function jsonSerialize() { + public function jsonSerialize(): array { return $this->options; } } + diff --git a/lib/Model/PlatformWrapper.php b/lib/Model/PlatformWrapper.php index 6a9673a..2c57dba 100644 --- a/lib/Model/PlatformWrapper.php +++ b/lib/Model/PlatformWrapper.php @@ -1,4 +1,7 @@ class; } @@ -94,7 +98,7 @@ class PlatformWrapper { * * @return PlatformWrapper */ - public function setClass($class) { + public function setClass(string $class): PlatformWrapper { $this->class = $class; return $this; @@ -104,7 +108,7 @@ class PlatformWrapper { /** * @return IFullTextSearchPlatform */ - public function getPlatform() { + public function getPlatform(): IFullTextSearchPlatform { return $this->platform; } @@ -113,7 +117,7 @@ class PlatformWrapper { * * @return PlatformWrapper */ - public function setPlatform($platform) { + public function setPlatform(IFullTextSearchPlatform $platform): PlatformWrapper { $this->platform = $platform; return $this; @@ -123,7 +127,7 @@ class PlatformWrapper { /** * @return string */ - public function getVersion() { + public function getVersion(): string { return $this->version; } @@ -132,7 +136,7 @@ class PlatformWrapper { * * @return PlatformWrapper */ - public function setVersion($version) { + public function setVersion(string $version): PlatformWrapper { $this->version = $version; return $this; diff --git a/lib/Model/ProviderIndexes.php b/lib/Model/ProviderIndexes.php index 3177066..1475631 100644 --- a/lib/Model/ProviderIndexes.php +++ b/lib/Model/ProviderIndexes.php @@ -1,4 +1,7 @@ indexes = $indexes; } @@ -44,7 +55,7 @@ class ProviderIndexes { /** * @return IIndex[] */ - public function getIndexes():array { + public function getIndexes(): array { return $this->indexes; } diff --git a/lib/Model/ProviderWrapper.php b/lib/Model/ProviderWrapper.php index d1de140..05ed653 100644 --- a/lib/Model/ProviderWrapper.php +++ b/lib/Model/ProviderWrapper.php @@ -1,4 +1,7 @@ appId = $appId; $this->provider = $provider; } @@ -63,7 +66,7 @@ class ProviderWrapper { /** * @return string */ - public function getAppId() { + public function getAppId(): string { return $this->appId; } @@ -72,7 +75,7 @@ class ProviderWrapper { * * @return ProviderWrapper */ - public function setAppId($appId) { + public function setAppId(string $appId): ProviderWrapper { $this->appId = $appId; return $this; @@ -82,7 +85,7 @@ class ProviderWrapper { /** * @return IFullTextSearchProvider */ - public function getProvider() { + public function getProvider(): IFullTextSearchProvider { return $this->provider; } @@ -91,7 +94,7 @@ class ProviderWrapper { * * @return ProviderWrapper */ - public function setProvider($provider) { + public function setProvider(IFullTextSearchProvider $provider): ProviderWrapper { $this->provider = $provider; return $this; @@ -101,7 +104,7 @@ class ProviderWrapper { /** * @return string */ - public function getVersion() { + public function getVersion(): string { return $this->version; } @@ -110,7 +113,7 @@ class ProviderWrapper { * * @return ProviderWrapper */ - public function setVersion($version) { + public function setVersion(string $version): ProviderWrapper { $this->version = $version; return $this; @@ -118,3 +121,4 @@ class ProviderWrapper { } + diff --git a/lib/Model/Runner.php b/lib/Model/Runner.php index 37ae39c..ac78684 100644 --- a/lib/Model/Runner.php +++ b/lib/Model/Runner.php @@ -1,4 +1,7 @@ runningService = $runningService; $this->source = $source; @@ -122,7 +133,6 @@ class Runner implements IRunner { * @throws RunnerAlreadyUpException */ public function start() { -// $this->strict = $strict; $this->tickId = $this->runningService->start($this->source); } @@ -167,7 +177,9 @@ class Runner implements IRunner { } usleep(300000); - $this->base->abort(); + if ($this->base !== null) { + $this->base->abort(); + } } $this->pauseRunning(false); @@ -205,7 +217,6 @@ class Runner implements IRunner { */ public function setInfoArray(array $data) { $keys = array_keys($data); - //$this->info['info'] = ''; foreach ($keys as $k) { $this->info[$k] = $data[$k]; } @@ -243,39 +254,37 @@ class Runner implements IRunner { if ($color !== '') { $this->info[$info . 'Colored'] = '<' . $color . '>' . $value . ''; } - - } /** * @return array */ - public function getInfoAll() { + public function getInfoAll(): array { return $this->info; } /** - * @param string $k + * @param string $info * * @return string */ - public function getInfo($k) { - return MiscService::get($k, $this->info, ''); + public function getInfo(string $info): string { + return $this->get($info, $this->info, ''); } /** * @param array $method */ - public function onKeyPress($method) { + public function onKeyPress(array $method) { $this->methodOnKeyPress[] = $method; } /** - * @param $key + * @param string $key */ - public function keyPressed($key) { + public function keyPressed(string $key) { foreach ($this->methodOnKeyPress as $method) { call_user_func($method, $key); } @@ -285,11 +294,14 @@ class Runner implements IRunner { /** * @param array $method */ - public function onInfoUpdate($method) { + public function onInfoUpdate(array $method) { $this->methodOnInfoUpdate[] = $method; } + /** + * + */ public function infoUpdated() { foreach ($this->methodOnInfoUpdate as $method) { call_user_func($method, $this->info); @@ -300,7 +312,7 @@ class Runner implements IRunner { /** * @param array $method */ - public function onNewIndexError($method) { + public function onNewIndexError(array $method) { $this->methodOnIndexError[] = $method; } @@ -328,7 +340,7 @@ class Runner implements IRunner { /** * @param array $method */ - public function onNewIndexResult($method) { + public function onNewIndexResult(array $method) { $this->methodOnIndexResult[] = $method; } @@ -359,7 +371,7 @@ class Runner implements IRunner { * * @throws TickDoesNotExistException */ - private function updateTick($tick, $action) { + private function updateTick(int $tick, string $action) { if ($this->oldAction === $action && ($this->tickUpdate + self::TICK_UPDATE > $tick)) { return; } @@ -376,9 +388,9 @@ class Runner implements IRunner { /** - * @param $tick + * @param int $tick */ - private function updateRamInfo($tick) { + private function updateRamInfo(int $tick) { if (($this->ramUpdate + self::MEMORY_UPDATE) > $tick) { return; } @@ -424,7 +436,7 @@ class Runner implements IRunner { /** * @param bool $pause */ - public function pause($pause) { + public function pause(bool $pause) { $this->paused = $pause; $this->infoUpdated(); } @@ -432,7 +444,7 @@ class Runner implements IRunner { /** * @return bool */ - public function isPaused() { + public function isPaused(): bool { return $this->paused; } @@ -440,13 +452,15 @@ class Runner implements IRunner { /** * @param bool $running */ - public function pauseRunning($running) { + public function pauseRunning(bool $running) { $this->pauseRunning = $running; $this->infoUpdated(); } - - public function isPauseRunning() { + /** + * @return bool + */ + public function isPauseRunning(): bool { return $this->pauseRunning; } @@ -454,7 +468,7 @@ class Runner implements IRunner { /** * @param string $line */ - public function output($line) { + public function output(string $line) { if ($this->outputInterface === null) { return; } diff --git a/lib/Model/SearchRequest.php b/lib/Model/SearchRequest.php index f5730be..bc98d05 100644 --- a/lib/Model/SearchRequest.php +++ b/lib/Model/SearchRequest.php @@ -1,4 +1,7 @@ options)) { - return $this->options[$option]; - } - - return $default; + return $this->get($option, $this->options, $default); } @@ -331,14 +342,7 @@ class SearchRequest implements ISearchRequest, JsonSerializable { * @return array */ public function getOptionArray(string $option, array $default = []): array { - if (array_key_exists($option, $this->options)) { - $options = $this->options[$option]; - if (is_array($options)) { - return $this->options[$option]; - } - } - - return $default; + return $this->getArray($option, $this->options, $default); } @@ -648,7 +652,7 @@ class SearchRequest implements ISearchRequest, JsonSerializable { /** * @return array */ - public function jsonSerialize() { + public function jsonSerialize(): array { return [ 'providers' => $this->getProviders(), 'author' => $this->getAuthor(), @@ -664,40 +668,42 @@ class SearchRequest implements ISearchRequest, JsonSerializable { } - /** - * @param string $json - * - * @return SearchRequest - */ - public static function fromJSON(string $json): SearchRequest { - return self::fromArray(json_decode($json, true)); - } - /** * @param array $arr * * @return SearchRequest */ - public static function fromArray($arr): SearchRequest { + public function importFromArray($arr): SearchRequest { $providers = $arr['providers']; if (!is_array($providers)) { $providers = [$providers]; } - $request = new SearchRequest(); - $request->setProviders($providers); - $request->setAuthor(MiscService::get('author', $arr, '')); - $request->setSearch(MiscService::get('search', $arr, '')); - $request->setPage(MiscService::get('page', $arr, 0)); - $request->setParts(MiscService::get('parts', $arr, [])); - $request->setSize(MiscService::get('size', $arr, 10)); - $request->setOptions(MiscService::get('options', $arr, [])); - $request->setMetaTags(MiscService::get('metatags', $arr, [])); - $request->setSubTags(MiscService::get('subtags', $arr, [])); - $request->setTags(MiscService::get('tags', $arr, [])); + $this->setProviders($providers); + $this->setAuthor($this->get('author', $arr, '')); + $this->setSearch($this->get('search', $arr, '')); + $this->setPage($this->getInt('page', $arr, 0)); + $this->setParts($this->getArray('parts', $arr, [])); + $this->setSize($this->getInt('size', $arr, 10)); + $this->setOptions($this->getArray('options', $arr, [])); + $this->setMetaTags($this->getArray('metatags', $arr, [])); + $this->setSubTags($this->getArray('subtags', $arr, [])); + $this->setTags($this->getArray('tags', $arr, [])); - return $request; + return $this; } + /** + * @param string $json + * + * @return SearchRequest + */ + public static function fromJSON(string $json): SearchRequest { + $searchRequest = new SearchRequest(); + $searchRequest->importFromArray(json_decode($json, true)); + + return $searchRequest; + } + } diff --git a/lib/Model/SearchResult.php b/lib/Model/SearchResult.php index f51a7f0..4d77445 100644 --- a/lib/Model/SearchResult.php +++ b/lib/Model/SearchResult.php @@ -30,6 +30,7 @@ declare(strict_types=1); namespace OCA\FullTextSearch\Model; + use JsonSerializable; use OCP\FullTextSearch\IFullTextSearchPlatform; use OCP\FullTextSearch\IFullTextSearchProvider; @@ -38,6 +39,11 @@ use OCP\FullTextSearch\Model\ISearchRequest; use OCP\FullTextSearch\Model\ISearchResult; +/** + * Class SearchResult + * + * @package OCA\FullTextSearch\Model + */ class SearchResult implements ISearchResult, JsonSerializable { /** @var IndexDocument[] */ @@ -68,7 +74,12 @@ class SearchResult implements ISearchResult, JsonSerializable { private $request; - public function __construct(SearchRequest $searchRequest = null) { + /** + * SearchResult constructor. + * + * @param SearchRequest $searchRequest + */ + public function __construct(SearchRequest $searchRequest) { $this->request = $searchRequest; } @@ -160,7 +171,7 @@ class SearchResult implements ISearchResult, JsonSerializable { * * @return ISearchResult */ - public function setPlatform($platform): ISearchResult { + public function setPlatform(IFullTextSearchPlatform $platform): ISearchResult { $this->platform = $platform; return $this; @@ -263,9 +274,38 @@ class SearchResult implements ISearchResult, JsonSerializable { /** - * @return array|IndexDocument[]|integer> + * @since 15.0.0 + * + * @param string $category + * @param string $value + * @param int $count + * + * @return ISearchResult */ - public function jsonSerialize() { + public function addAggregation(string $category, string $value, int $count): ISearchResult { + // TODO: Implement addAggregation() method. + + return $this; + } + + /** + * @since 15.0.0 + * + * @param string $category + * + * @return array + */ + public function getAggregations(string $category): array { + // TODO: Implement getAggregations() method. + + return []; + } + + + /** + * @return array + */ + public function jsonSerialize(): array { $providerObj = $this->getProvider(); $provider = []; @@ -300,31 +340,5 @@ class SearchResult implements ISearchResult, JsonSerializable { ]; } - /** - * @since 15.0.0 - * - * @param string $category - * @param string $value - * @param int $count - * - * @return ISearchResult - */ - public function addAggregation(string $category, string $value, int $count): ISearchResult { - // TODO: Implement addAggregation() method. - - return $this; - } - - /** - * @since 15.0.0 - * - * @param string $category - * - * @return array - */ - public function getAggregations(string $category): array { - // TODO: Implement getAggregations() method. - - return []; - } } + diff --git a/lib/Model/Tick.php b/lib/Model/Tick.php index bd7649d..46bb7b2 100644 --- a/lib/Model/Tick.php +++ b/lib/Model/Tick.php @@ -1,4 +1,7 @@ source = $source; $this->id = $id; } @@ -61,7 +81,7 @@ class Tick { /** * @return int */ - public function getId() { + public function getId(): int { return $this->id; } @@ -70,7 +90,7 @@ class Tick { * * @return $this */ - public function setId($id) { + public function setId(int $id): Tick { $this->id = $id; return $this; @@ -80,7 +100,7 @@ class Tick { /** * @return string */ - public function getSource() { + public function getSource(): string { return $this->source; } @@ -88,7 +108,7 @@ class Tick { /** * @return array */ - public function getData() { + public function getData(): array { return $this->data; } @@ -97,7 +117,7 @@ class Tick { * * @return $this */ - public function setData($data) { + public function setData(array $data): Tick { $this->data = $data; return $this; @@ -107,7 +127,7 @@ class Tick { /** * @return int */ - public function getTick() { + public function getTick(): int { return $this->tick; } @@ -116,7 +136,7 @@ class Tick { * * @return $this */ - public function setTick($tick = 0) { + public function setTick(int $tick = 0): Tick { if ($tick === 0) { $tick = time(); } @@ -130,7 +150,7 @@ class Tick { /** * @return int */ - public function getFirstTick() { + public function getFirstTick(): int { return $this->firstTick; } @@ -139,7 +159,7 @@ class Tick { * * @return $this */ - public function setFirstTick($tick = 0) { + public function setFirstTick(int $tick = 0): Tick { if ($tick === 0) { $tick = time(); } @@ -153,7 +173,7 @@ class Tick { /** * @return string */ - public function getStatus() { + public function getStatus(): string { return $this->status; } @@ -162,7 +182,7 @@ class Tick { * * @return $this */ - public function setStatus($status) { + public function setStatus(string $status): Tick { $this->status = $status; return $this; @@ -172,7 +192,7 @@ class Tick { /** * @return string */ - public function getAction() { + public function getAction(): string { return $this->action; } @@ -181,7 +201,7 @@ class Tick { * * @return $this */ - public function setAction($action) { + public function setAction(string $action): Tick { $this->action = $action; return $this; @@ -189,33 +209,56 @@ class Tick { /** - * @param string $key - * @param string|int $value + * @param string $info + * @param string $value + * + * @return $this + */ + public function setInfo(string $info, string $value): Tick { + $this->data[$info] = $value; + + return $this; + } + + /** + * @param string $info + * @param int $value * * @return $this */ - public function setInfo($key, $value) { - $this->data[$key] = $value; + public function setInfoInt(string $info, int $value): Tick { + $this->data[$info] = $value; return $this; } - public function unsetInfo($key) { - unset($this->data[$key]); + /** + * @param string $info + */ + public function unsetInfo(string $info) { + unset($this->data[$info]); } /** - * @param $key - * @param int|string $default + * @param string $info + * @param string $default * - * @return int|string + * @return string */ - public function getInfo($key, $default = '') { - if (!array_key_exists($key, $this->data)) { - return $default; - } + public function getInfo(string $info, string $default = ''): string { + return $this->get($info, $this->data, $default); + } - return $this->data[$key]; + /** + * @param string $info + * @param int $default + * + * @return int + */ + public function getInfoInt(string $info, int $default = 0): int { + return $this->getInt($info, $this->data, $default); } + } + -- cgit v1.2.3 From 59049ced6ab33ad34a31eda1c38c857a3c55f4c0 Mon Sep 17 00:00:00 2001 From: Maxence Lange Date: Wed, 31 Oct 2018 18:41:26 +0100 Subject: switch toTArrayTools Signed-off-by: Maxence Lange --- lib/Command/Index.php | 27 ++++++++++++++++----------- lib/Command/Live.php | 28 +++++++++++++++++----------- 2 files changed, 33 insertions(+), 22 deletions(-) (limited to 'lib') diff --git a/lib/Command/Index.php b/lib/Command/Index.php index b92d2fa..fe7aa3e 100644 --- a/lib/Command/Index.php +++ b/lib/Command/Index.php @@ -31,6 +31,7 @@ declare(strict_types=1); namespace OCA\FullTextSearch\Command; +use daita\MySmallPhpTools\Traits\TArrayTools; use Exception; use OC\Core\Command\InterruptedException; use OCA\FullTextSearch\ACommandBase; @@ -61,6 +62,10 @@ use Symfony\Component\Console\Terminal; */ class Index extends ACommandBase { + + use TArrayTools; + + // '%job:1s%%message:-40s%%current:6s%/%max:6s% [%bar%] %percent:3s%% \n %duration% %infos:-12s% %jvm:-30s% ' const PANEL_RUN = 'run'; const PANEL_RUN_LINE_OPTIONS = 'Options: %options%'; @@ -610,10 +615,10 @@ class Index extends ACommandBase { } $width = $this->terminal->getWidth() - 13; - $message = MiscService::get('message', $error, ''); - $err1 = (string) substr($message, 0, $width); - $err2 = (string) substr($message, $width, $width + 10); - $err3 = (string) substr($message, $width + $width + 10, $width + 10); + $message = $this->get('message', $error, ''); + $err1 = (string)substr($message, 0, $width); + $err2 = (string)substr($message, $width, $width + 10); + $err3 = (string)substr($message, $width + $width + 10, $width + 10); $this->runner->setInfoArray( [ @@ -622,7 +627,7 @@ class Index extends ACommandBase { 'errorMessageA' => trim($err1), 'errorMessageB' => trim($err2), 'errorMessageC' => trim($err3), - 'errorException' => MiscService::get('exception', $error, ''), + 'errorException' => $this->get('exception', $error, ''), 'errorIndex' => $errorIndex ] ); @@ -663,13 +668,13 @@ class Index extends ACommandBase { $width = $this->terminal->getWidth() - 13; - $message = MiscService::get('message', $result, ''); - $msg1 = (string) substr($message, 0, $width); - $msg2 = (string) substr($message, $width, $width + 10); - $msg3 = (string) substr($message, $width + $width + 10, $width + 10); + $message = $this->get('message', $result, ''); + $msg1 = (string)substr($message, 0, $width); + $msg2 = (string)substr($message, $width, $width + 10); + $msg3 = (string)substr($message, $width + $width + 10, $width + 10); - $status = MiscService::get('status', $result, ''); - $type = MiscService::get('type', $result, ''); + $status = $this->get('status', $result, ''); + $type = $this->getInt('type', $result, 0); $this->runner->setInfoArray( [ diff --git a/lib/Command/Live.php b/lib/Command/Live.php index 0e213de..0c42737 100644 --- a/lib/Command/Live.php +++ b/lib/Command/Live.php @@ -31,6 +31,7 @@ declare(strict_types=1); namespace OCA\FullTextSearch\Command; +use daita\MySmallPhpTools\Traits\TArrayTools; use Exception; use OC\Core\Command\InterruptedException; use OCA\FullTextSearch\ACommandBase; @@ -59,6 +60,10 @@ use Symfony\Component\Console\Terminal; */ class Live extends ACommandBase { + + use TArrayTools; + + const CYCLE_DELAY = 300000; const PANEL_RUN = 'run'; @@ -530,14 +535,15 @@ class Live extends ACommandBase { $width = $this->terminal->getWidth() - 13; - $message = MiscService::get('message', $result, ''); - $msg1 = (string) substr($message, 0, $width); - $msg2 = (string) substr($message, $width, $width + 10); - $msg3 = (string) substr($message, $width + $width + 10, $width + 10); + $message = $this->get('message', $result, ''); + $msg1 = (string)substr($message, 0, $width); + $msg2 = (string)substr($message, $width, $width + 10); + $msg3 = (string)substr($message, $width + $width + 10, $width + 10); + + $status = $this->get('status', $result, ''); + $type = $this->getInt('type', $result, 0); - $status = MiscService::get('status', $result, ''); - $type = MiscService::get('type', $result, ''); $this->runner->setInfoArray( [ @@ -586,10 +592,10 @@ class Live extends ACommandBase { } $width = $this->terminal->getWidth() - 13; - $message = MiscService::get('message', $error, ''); - $err1 = (string) substr($message, 0, $width); - $err2 = (string) substr($message, $width, $width + 10); - $err3 = (string) substr($message, $width + $width + 10, $width + 10); + $message = $this->get('message', $error, ''); + $err1 = (string)substr($message, 0, $width); + $err2 = (string)substr($message, $width, $width + 10); + $err3 = (string)substr($message, $width + $width + 10, $width + 10); $this->runner->setInfoArray( [ @@ -598,7 +604,7 @@ class Live extends ACommandBase { 'errorMessageA' => trim($err1), 'errorMessageB' => trim($err2), 'errorMessageC' => trim($err3), - 'errorException' => MiscService::get('exception', $error, ''), + 'errorException' => $this->get('exception', $error, ''), 'errorIndex' => $errorIndex ] ); -- cgit v1.2.3 From 2c6d77cb788d8ae0939608d465f8565111d8c26d Mon Sep 17 00:00:00 2001 From: Maxence Lange Date: Wed, 31 Oct 2018 18:42:06 +0100 Subject: adapt searchRequest Signed-off-by: Maxence Lange --- lib/Command/Search.php | 5 +++-- lib/Service/SearchService.php | 5 ++++- 2 files changed, 7 insertions(+), 3 deletions(-) (limited to 'lib') diff --git a/lib/Command/Search.php b/lib/Command/Search.php index 0480b5e..0568e27 100644 --- a/lib/Command/Search.php +++ b/lib/Command/Search.php @@ -97,7 +97,8 @@ class Search extends Base { protected function execute(InputInterface $input, OutputInterface $output) { $output->writeln('search'); - $request = SearchRequest::fromArray( + $searchRequest = new SearchRequest(); + $searchRequest->importFromArray( [ 'providers' => 'all', 'search' => $input->getArgument('string') @@ -105,7 +106,7 @@ class Search extends Base { ); try { - $result = $this->searchService->search($input->getArgument('user'), $request); + $result = $this->searchService->search($input->getArgument('user'), $searchRequest); foreach ($result as $searchResult) { $this->displaySearchResult($searchResult); diff --git a/lib/Service/SearchService.php b/lib/Service/SearchService.php index 3dfa85e..5dc489d 100644 --- a/lib/Service/SearchService.php +++ b/lib/Service/SearchService.php @@ -107,7 +107,10 @@ class SearchService implements ISearchService { * @return ISearchRequest */ public function generateSearchRequest(array $request): ISearchRequest { - return SearchRequest::fromArray($request); + $searchRequest = new SearchRequest(); + $searchRequest->importFromArray($request); + + return $searchRequest; } -- cgit v1.2.3 From b5fe0d8c4c41bf6dce5a8a99f6815736283a5da6 Mon Sep 17 00:00:00 2001 From: Maxence Lange Date: Wed, 31 Oct 2018 18:42:36 +0100 Subject: update single status Signed-off-by: Maxence Lange --- lib/Service/IndexService.php | 55 ++++++++++++++++++++++++++++---------------- 1 file changed, 35 insertions(+), 20 deletions(-) (limited to 'lib') diff --git a/lib/Service/IndexService.php b/lib/Service/IndexService.php index 42d6d44..6972eb9 100644 --- a/lib/Service/IndexService.php +++ b/lib/Service/IndexService.php @@ -191,8 +191,7 @@ class IndexService implements IIndexService { private function updateDocumentsWithCurrIndex( IFullTextSearchProvider $provider, array $documents, IIndexOptions $options ) { - - $currIndex = $this->getProviderIndexFromProvider($provider); + $currIndex = $this->getProviderIndexFromProvider($provider->getId()); $result = []; $count = 0; foreach ($documents as $document) { @@ -254,12 +253,12 @@ class IndexService implements IIndexService { /** - * @param IFullTextSearchProvider $provider + * @param string $providerId * * @return ProviderIndexes */ - private function getProviderIndexFromProvider(IFullTextSearchProvider $provider) { - $indexes = $this->indexesRequest->getIndexesFromProvider($provider); + private function getProviderIndexFromProvider(string $providerId) { + $indexes = $this->indexesRequest->getIndexesFromProvider($providerId); return new ProviderIndexes($indexes); } @@ -274,7 +273,7 @@ class IndexService implements IIndexService { * @throws Exception */ private function indexDocuments( - IFullTextSearchPlatform $platform, IFullTextSearchProvider $provider, $documents, + IFullTextSearchPlatform $platform, IFullTextSearchProvider $provider, array $documents, IndexOptions $options ) { while ($document = array_shift($documents)) { @@ -410,7 +409,7 @@ class IndexService implements IIndexService { $document->getIndex() ->resetErrors(); - $index = $platform->indexDocument($provider, $document); + $index = $platform->indexDocument($document); $this->updateIndex($index); } @@ -469,6 +468,34 @@ class IndexService implements IIndexService { } + /** + * @param string $providerId + * @param string $documentId + * @param int $status + * @param bool $reset + * + * @throws Exception + */ + public function updateIndexStatus( + string $providerId, string $documentId, int $status, bool $reset = false + ) { + if ($reset === true) { + $this->indexesRequest->updateStatus($providerId, $documentId, $status); + + return; + } + + try { + $curr = $this->getIndex($providerId, $documentId); + } catch (IndexDoesNotExistException $e) { + return; + } + + $curr->setStatus($status); + $this->updateIndex($curr); + } + + /** * @param string $providerId * @param array $documentIds @@ -481,7 +508,7 @@ class IndexService implements IIndexService { string $providerId, array $documentIds, int $status, bool $reset = false ) { if ($reset === true) { - $this->indexesRequest->updateStatus($providerId, $documentIds, $status); + $this->indexesRequest->updateStatuses($providerId, $documentIds, $status); return; } @@ -496,7 +523,6 @@ class IndexService implements IIndexService { $curr->setStatus($status); $this->updateIndexes([$curr]); } - } @@ -601,15 +627,4 @@ class IndexService implements IIndexService { } - /** - * @param string $providerId - * @param $documentId - * @param int $status - * @param bool $reset - */ - public function updateIndexStatus( - string $providerId, $documentId, int $status, bool $reset = false - ) { - // TODO: Implement updateIndexStatus() method. - } } -- cgit v1.2.3 From 2d027b159a1538ac1e650c7590e3e71284f6153d Mon Sep 17 00:00:00 2001 From: Maxence Lange Date: Wed, 31 Oct 2018 18:43:05 +0100 Subject: using InfoInt Signed-off-by: Maxence Lange --- lib/Service/RunningService.php | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'lib') diff --git a/lib/Service/RunningService.php b/lib/Service/RunningService.php index aa953be..3fe35c4 100644 --- a/lib/Service/RunningService.php +++ b/lib/Service/RunningService.php @@ -78,7 +78,7 @@ class RunningService { $tick->setStatus('run') ->setTick() ->setFirstTick() - ->setInfo('runStart ', time()); + ->setInfoInt('runStart ', time()); return $this->tickRequest->create($tick); } @@ -129,12 +129,12 @@ class RunningService { * * @throws TickDoesNotExistException */ - public function stop($runId, $reason = '') { + public function stop(int $runId, string $reason = '') { $tick = $this->tickRequest->getTickById($runId); $tick->setStatus('stop') ->setTick() - ->setInfo('runStop', time()) - ->setInfo('totalDocuments', 42); + ->setInfoInt('runStop', time()) + ->setInfoInt('totalDocuments', 42); if ($reason !== '') { $tick->setStatus('exception'); @@ -187,7 +187,7 @@ class RunningService { * @return bool */ public function isAlreadyRunning() { - $ticks = $this->tickRequest->getTickByStatus('run'); + $ticks = $this->tickRequest->getTicksByStatus('run'); $isAlreadyRunning = false; foreach ($ticks as $tick) { @@ -207,7 +207,7 @@ class RunningService { * */ public function forceStop() { - $ticks = $this->tickRequest->getTickByStatus('run'); + $ticks = $this->tickRequest->getTicksByStatus('run'); foreach ($ticks as $tick) { $tick->setStatus('forceStop'); @@ -225,18 +225,18 @@ class RunningService { $preAction = $tick->getAction(); if ($preAction !== '') { - $preActionTotal = $tick->getInfo($preAction . 'Total', 0); - $preActionStart = $tick->getInfo($preAction . 'Init', 0); + $preActionTotal = $tick->getInfoInt($preAction . 'Total', 0); + $preActionStart = $tick->getInfoInt($preAction . 'Init', 0); if ($preActionStart > 0) { $preActionTotal += ($now - $preActionStart); - $tick->setInfo($preAction . 'Total', $preActionTotal); + $tick->setInfoInt($preAction . 'Total', $preActionTotal); $tick->unsetInfo($preAction . 'Init'); } } $tick->setAction($action) - ->setInfo($action . 'Init', $now); + ->setInfoInt($action . 'Init', $now); } -- cgit v1.2.3 From 6eca11cbfda997a0a995834d8459efa81d447017 Mon Sep 17 00:00:00 2001 From: Maxence Lange Date: Wed, 31 Oct 2018 19:36:16 +0100 Subject: migrating php7 Signed-off-by: Maxence Lange --- lib/Service/CliService.php | 31 +++++++++++++---- lib/Service/ConfigService.php | 62 +++++++++++++++++---------------- lib/Service/IndexService.php | 40 ++++++++++++++------- lib/Service/MiscService.php | 77 ++++++++++++----------------------------- lib/Service/PlatformService.php | 19 +++++++--- lib/Service/ProviderService.php | 45 +++++++++++++++++------- lib/Service/RunningService.php | 31 ++++++++++++----- lib/Service/SearchService.php | 22 +++++++++--- lib/Service/SettingsService.php | 23 +++++++++--- lib/Service/TestService.php | 17 +++++++-- 10 files changed, 227 insertions(+), 140 deletions(-) (limited to 'lib') diff --git a/lib/Service/CliService.php b/lib/Service/CliService.php index 4ae6bde..1b8b734 100644 --- a/lib/Service/CliService.php +++ b/lib/Service/CliService.php @@ -1,4 +1,7 @@ displayedPanel[] = [ 'slot' => $panelSlot, 'id' => $panelId @@ -109,7 +121,7 @@ class CliService { * * @return string */ - public function currentPanel($panelSlot) { + public function currentPanel(string $panelSlot): string { foreach ($this->displayedPanel as $panel) { if ($panel['slot'] === $panelSlot) { return $panel['id']; @@ -124,7 +136,7 @@ class CliService { * @param string $panelSlot * @param string $panelId */ - public function switchPanel($panelSlot, $panelId) { + public function switchPanel(string $panelSlot, string $panelId) { $this->displayedPanel = array_map( function($item) use ($panelId, $panelSlot) { if ($item['slot'] === $panelSlot) { @@ -167,6 +179,9 @@ class CliService { } + /** + * + */ public function refreshDisplay() { if ($this->display === null) { @@ -187,6 +202,9 @@ class CliService { } + /** + * + */ public function refreshInfo() { if ($this->runner->isPauseRunning()) { $this->display->setMessage('(paused)', '_paused'); @@ -200,7 +218,7 @@ class CliService { /** * @param array $info */ - public function onInfoUpdated($info) { + public function onInfoUpdated(array $info) { if ($this->display === null) { return; } @@ -215,3 +233,4 @@ class CliService { } } + diff --git a/lib/Service/ConfigService.php b/lib/Service/ConfigService.php index 2d5f119..614cd48 100644 --- a/lib/Service/ConfigService.php +++ b/lib/Service/ConfigService.php @@ -1,4 +1,7 @@ '', @@ -47,6 +60,7 @@ class ConfigService { self::CRON_LAST_ERR_RESET => '0' ]; + /** @var IConfig */ private $config; @@ -65,7 +79,7 @@ class ConfigService { * @param MiscService $miscService */ public function __construct( - IConfig $config, $userId, MiscService $miscService + IConfig $config, string $userId, MiscService $miscService ) { $this->config = $config; $this->userId = $userId; @@ -76,7 +90,7 @@ class ConfigService { /** * @return array */ - public function getConfig() { + public function getConfig(): array { $keys = array_keys($this->defaults); $data = []; @@ -91,7 +105,7 @@ class ConfigService { /** * @param array $save */ - public function setConfig($save) { + public function setConfig(array $save) { $keys = array_keys($this->defaults); foreach ($keys as $k) { @@ -121,7 +135,7 @@ class ConfigService { * * @return string */ - public function getAppValue($key) { + public function getAppValue(string $key): string { $defaultValue = null; if (array_key_exists($key, $this->defaults)) { $defaultValue = $this->defaults[$key]; @@ -135,10 +149,8 @@ class ConfigService { * * @param string $key * @param string $value - * - * @return void */ - public function setAppValue($key, $value) { + public function setAppValue(string $key, string $value) { $this->config->setAppValue(Application::APP_NAME, $key, $value); } @@ -146,11 +158,9 @@ class ConfigService { * remove a key * * @param string $key - * - * @return string */ - public function deleteAppValue($key) { - return $this->config->deleteAppValue(Application::APP_NAME, $key); + public function deleteAppValue(string $key) { + $this->config->deleteAppValue(Application::APP_NAME, $key); } /** @@ -160,7 +170,7 @@ class ConfigService { * * @return string */ - public function getUserValue($key) { + public function getUserValue(string $key): string { $defaultValue = null; if (array_key_exists($key, $this->defaults)) { $defaultValue = $this->defaults[$key]; @@ -177,11 +187,10 @@ class ConfigService { * @param string $key * @param string $value * - * @return string * @throws PreConditionNotMetException */ - public function setUserValue($key, $value) { - return $this->config->setUserValue($this->userId, Application::APP_NAME, $key, $value); + public function setUserValue(string $key, string $value) { + $this->config->setUserValue($this->userId, Application::APP_NAME, $key, $value); } /** @@ -192,7 +201,7 @@ class ConfigService { * * @return string */ - public function getValueForUser($userId, $key) { + public function getValueForUser(string $userId, string $key) { return $this->config->getUserValue($userId, Application::APP_NAME, $key); } @@ -206,8 +215,8 @@ class ConfigService { * @return string * @throws PreConditionNotMetException */ - public function setValueForUser($userId, $key, $value) { - return $this->config->setUserValue($userId, Application::APP_NAME, $key, $value); + public function setValueForUser(string $userId, string $key, string $value) { + $this->config->setUserValue($userId, Application::APP_NAME, $key, $value); } @@ -216,7 +225,7 @@ class ConfigService { * @param string $options * @param string $value */ - public function setProviderOptions($providerId, $options, $value) { + public function setProviderOptions(string $providerId, string $options, string $value) { $arr = json_decode($this->getAppValue($options), true); if ($arr === null) { $arr = []; @@ -231,7 +240,7 @@ class ConfigService { /** * @param string $options */ - public function resetProviderOptions($options) { + public function resetProviderOptions(string $options) { $this->setAppValue($options, ''); } @@ -243,7 +252,7 @@ class ConfigService { * @return string * @throws ProviderOptionsDoesNotExistException */ - public function getProviderOptions($providerId, $options) { + public function getProviderOptions(string $providerId, string $options): string { $arr = json_decode($this->getAppValue($options), true); if ($arr === null) { $arr = []; @@ -259,19 +268,12 @@ class ConfigService { /** * return the cloud version. - * if $complete is true, return a string x.y.z - * - * @param boolean $complete * - * @return string|integer + * @return int */ - public function getCloudVersion($complete = false) { + public function getCloudVersion(): int { $ver = Util::getVersion(); - if ($complete) { - return implode('.', $ver); - } - return $ver[0]; } } diff --git a/lib/Service/IndexService.php b/lib/Service/IndexService.php index 6972eb9..fd37629 100644 --- a/lib/Service/IndexService.php +++ b/lib/Service/IndexService.php @@ -1,4 +1,7 @@ updateRunnerAction('generateIndex' . $provider->getName()); $this->updateRunnerInfoArray( @@ -190,7 +203,7 @@ class IndexService implements IIndexService { */ private function updateDocumentsWithCurrIndex( IFullTextSearchProvider $provider, array $documents, IIndexOptions $options - ) { + ): array { $currIndex = $this->getProviderIndexFromProvider($provider->getId()); $result = []; $count = 0; @@ -198,7 +211,7 @@ class IndexService implements IIndexService { if ($count % 1000 === 0) { $this->updateRunnerAction('compareWithCurrentIndex', true); - $this->updateRunnerInfo('documentCurrent', $count); + $this->updateRunnerInfo('documentCurrent', (string)$count); } $count++; @@ -214,13 +227,13 @@ class IndexService implements IIndexService { continue; } - if ($options->getOption('force', false) === true) { + if ($options->getOptionBool('force', false) === true) { $index->setStatus(Index::INDEX_FULL); } $index->resetErrors(); $document->setIndex($index); - if ($options->getOption('force', false) === true + if ($options->getOptionBool('force', false) === true || !$this->isDocumentUpToDate($provider, $document)) { $result[] = $document; } @@ -237,7 +250,7 @@ class IndexService implements IIndexService { * @return bool */ private function isDocumentUpToDate(IFullTextSearchProvider $provider, IndexDocument $document - ) { + ): bool { $index = $document->getIndex(); if (!$index->isStatus(Index::INDEX_OK)) { @@ -257,7 +270,7 @@ class IndexService implements IIndexService { * * @return ProviderIndexes */ - private function getProviderIndexFromProvider(string $providerId) { + private function getProviderIndexFromProvider(string $providerId): ProviderIndexes { $indexes = $this->indexesRequest->getIndexesFromProvider($providerId); return new ProviderIndexes($indexes); @@ -343,7 +356,8 @@ class IndexService implements IIndexService { * @return IIndex * @throws Exception */ - public function indexDocument(IFullTextSearchPlatform $platform, $document) { + public function indexDocument(IFullTextSearchPlatform $platform, IndexDocument $document + ): IIndex { $this->updateRunnerAction('indexDocument', true); $this->updateRunnerInfoArray( [ @@ -369,7 +383,6 @@ class IndexService implements IIndexService { * @param IFullTextSearchProvider $provider * @param Index $index * - * @internal param int|string $documentId * @throws Exception */ public function updateDocument( @@ -463,6 +476,9 @@ class IndexService implements IIndexService { } + /** + * @param IIndex $index + */ private function updateIndexError(IIndex $index) { } @@ -556,7 +572,7 @@ class IndexService implements IIndexService { /** * @return Index[] */ - public function getErrorIndexes() { + public function getErrorIndexes(): array { return $this->indexesRequest->getErrorIndexes(); } @@ -578,7 +594,7 @@ class IndexService implements IIndexService { * * @return Index[] */ - public function getQueuedIndexes($all = false) { + public function getQueuedIndexes(bool $all = false): array { return $this->indexesRequest->getQueuedIndexes($all); } @@ -588,7 +604,7 @@ class IndexService implements IIndexService { * * @throws Exception */ - public function resetIndex($providerId = '') { + public function resetIndex(string $providerId = '') { $wrapper = $this->platformService->getPlatform(); $platform = $wrapper->getPlatform(); diff --git a/lib/Service/MiscService.php b/lib/Service/MiscService.php index c5b0d34..c8a608c 100644 --- a/lib/Service/MiscService.php +++ b/lib/Service/MiscService.php @@ -1,4 +1,7 @@ logger = $logger; - } - - public function log($message, $level = 2) { - $data = array( - 'app' => Application::APP_NAME, - 'level' => $level - ); - - $this->logger->log($level, $message, $data); - } /** - * @param $arr - * @param $k + * MiscService constructor. * - * @param string $default - * - * @return array|string|integer + * @param ILogger $logger */ - public static function get($k, $arr, $default = '') { - if ($arr === null) { - return $default; - } - - if (!key_exists($k, $arr)) { - return $default; - } - - return $arr[$k]; - } - - - public static function noEndSlash($path) { - if (substr($path, -1) === '/') { - $path = substr($path, 0, -1); - } - - return $path; + public function __construct(ILogger $logger) { + $this->logger = $logger; } /** - * @param string $time - * - * @return float + * @param string $message + * @param int $level */ - public static function getMicroTime($time) { - list($usec, $sec) = explode(' ', $time); - - return ((float)$usec + (float)$sec); - } - + public function log(string $message, int $level = 2) { + $data = array( + 'app' => Application::APP_NAME, + 'level' => $level + ); - public function addJavascript() { - Util::addStyle(Application::APP_NAME, 'fulltextsearch'); - Util::addScript(Application::APP_NAME, 'fulltextsearch.v1.api'); - Util::addScript(Application::APP_NAME, 'fulltextsearch.v1.settings'); - Util::addScript(Application::APP_NAME, 'fulltextsearch.v1.searchbox'); - Util::addScript(Application::APP_NAME, 'fulltextsearch.v1.result'); - Util::addScript(Application::APP_NAME, 'fulltextsearch.v1.navigation'); - Util::addScript(Application::APP_NAME, 'fulltextsearch.v1'); + $this->logger->log($level, $message, $data); } - } diff --git a/lib/Service/PlatformService.php b/lib/Service/PlatformService.php index 44cd71e..4738f80 100644 --- a/lib/Service/PlatformService.php +++ b/lib/Service/PlatformService.php @@ -1,4 +1,7 @@ loadPlatform(); } catch (Exception $e) { @@ -98,7 +109,7 @@ class PlatformService { * @return PlatformWrapper[] * @throws Exception */ - public function getPlatforms() { + public function getPlatforms(): array { $this->loadPlatforms(); $platforms = []; @@ -201,7 +212,7 @@ class PlatformService { /** * @param string $appId */ - private function loadPlatformsFromApp($appId) { + private function loadPlatformsFromApp(string $appId) { $appInfo = $this->appManager->getAppInfo($appId); if (!is_array($appInfo) || !key_exists('fulltextsearch', $appInfo) || !key_exists('platform', $appInfo['fulltextsearch'])) { diff --git a/lib/Service/ProviderService.php b/lib/Service/ProviderService.php index 691e3d3..6cb5608 100644 --- a/lib/Service/ProviderService.php +++ b/lib/Service/ProviderService.php @@ -1,4 +1,7 @@ query((string)$providerId); if (!($provider instanceof IFullTextSearchProvider)) { @@ -131,7 +141,7 @@ class ProviderService implements IProviderService { * @return ProviderWrapper[] * @throws Exception */ - public function getProviders() { + public function getProviders(): array { $this->loadProviders(); return $this->providers; @@ -141,7 +151,7 @@ class ProviderService implements IProviderService { * @return IFullTextSearchProvider[] * @throws Exception */ - public function getConfiguredProviders() { + public function getConfiguredProviders(): array { $this->loadProviders(); $providers = []; @@ -163,7 +173,7 @@ class ProviderService implements IProviderService { * @throws Exception * @throws ProviderDoesNotExistException */ - public function getFilteredProviders($providerList) { + public function getFilteredProviders(array $providerList): array { $this->loadProviders(); $providers = $this->getConfiguredProviders(); @@ -190,7 +200,7 @@ class ProviderService implements IProviderService { * @throws Exception * @throws ProviderDoesNotExistException */ - public function getProvider($providerId) { + public function getProvider(string $providerId): ProviderWrapper { $providers = $this->getProviders(); foreach ($providers as $providerWrapper) { @@ -209,7 +219,7 @@ class ProviderService implements IProviderService { * * @return bool */ - public function isProviderIndexed(string $providerId) { + public function isProviderIndexed(string $providerId): bool { try { $indexed = $this->configService->getProviderOptions( $providerId, ConfigService::PROVIDER_INDEXED @@ -227,13 +237,20 @@ class ProviderService implements IProviderService { } - public function setProviderAsIndexed(IFullTextSearchProvider $provider, $boolean) { + /** + * @param IFullTextSearchProvider $provider + * @param bool $boolean + */ + public function setProviderAsIndexed(IFullTextSearchProvider $provider, bool $boolean) { $this->configService->setProviderOptions( $provider->getId(), ConfigService::PROVIDER_INDEXED, (($boolean) ? '1' : '0') ); } + /** + * + */ public function setProvidersAsNotIndexed() { $this->configService->resetProviderOptions(ConfigService::PROVIDER_INDEXED); } @@ -246,7 +263,7 @@ class ProviderService implements IProviderService { * @throws ProviderIsNotUniqueException * @throws QueryException */ - private function loadProvidersFromApp($appId) { + private function loadProvidersFromApp(string $appId) { $appInfo = $this->appManager->getAppInfo($appId); if (!is_array($appInfo) || !key_exists('fulltextsearch', $appInfo) || !key_exists('provider', $appInfo['fulltextsearch'])) { @@ -254,19 +271,23 @@ class ProviderService implements IProviderService { } $providers = $appInfo['fulltextsearch']['provider']; + if (!is_array($providers)) { + $providers = [$providers]; + } + $this->loadProvidersFromList($appId, $providers); } /** * @param string $appId - * @param string|array $providers + * @param array $providers * * @throws ProviderIsNotCompatibleException * @throws ProviderIsNotUniqueException * @throws QueryException */ - private function loadProvidersFromList($appId, $providers) { + private function loadProvidersFromList(string $appId, array $providers) { if (!is_array($providers)) { $providers = [$providers]; } @@ -300,7 +321,7 @@ class ProviderService implements IProviderService { * * @return array */ - public function serialize($providers) { + public function serialize(array $providers): array { $arr = []; foreach ($providers as $provider) { $arr[] = [ diff --git a/lib/Service/RunningService.php b/lib/Service/RunningService.php index 3fe35c4..0527a63 100644 --- a/lib/Service/RunningService.php +++ b/lib/Service/RunningService.php @@ -1,4 +1,7 @@ isAlreadyRunning()) { throw new RunnerAlreadyUpException('Index is already running'); @@ -91,7 +103,7 @@ class RunningService { * @throws TickDoesNotExistException * @throws TickIsNotAliveException */ - public function update($runId, $action = '') { + public function update(int $runId, string $action = '') { $tick = $this->tickRequest->getTickById($runId); $this->isStillAlive($tick, true); @@ -107,11 +119,12 @@ class RunningService { /** * @deprecated - verifier l'interet ! + * * @param int $runId * @param string $reason * @param bool $stop */ - public function exception($runId, $reason, $stop = false) { + public function exception(int $runId, string $reason, bool $stop = false) { if ($stop) { try { $this->stop($runId, $reason); @@ -146,12 +159,12 @@ class RunningService { /** - * @param $runId + * @param int $runId * * @return bool * @throws TickIsNotAliveException */ - public function isAlive($runId) { + public function isAlive(int $runId): bool { $tick = null; try { $tick = $this->tickRequest->getTickById($runId); @@ -170,7 +183,7 @@ class RunningService { * @return bool * @throws TickIsNotAliveException */ - public function isStillAlive(Tick $tick, $exception = false) { + public function isStillAlive(Tick $tick, bool $exception = false): bool { if ($tick->getStatus() !== 'run') { if ($exception) { throw new TickIsNotAliveException(); @@ -186,7 +199,7 @@ class RunningService { /** * @return bool */ - public function isAlreadyRunning() { + public function isAlreadyRunning(): bool { $ticks = $this->tickRequest->getTicksByStatus('run'); $isAlreadyRunning = false; @@ -220,7 +233,7 @@ class RunningService { * @param Tick $tick * @param string $action */ - private function assignActionToTick(Tick &$tick, $action) { + private function assignActionToTick(Tick &$tick, string $action) { $now = microtime(true); $preAction = $tick->getAction(); diff --git a/lib/Service/SearchService.php b/lib/Service/SearchService.php index 5dc489d..db36ed9 100644 --- a/lib/Service/SearchService.php +++ b/lib/Service/SearchService.php @@ -1,4 +1,7 @@ improveSearchRequest($request); @@ -203,7 +215,7 @@ class SearchService implements ISearchService { * * @return DocumentAccess */ - private function getDocumentAccessFromUser(IUser $user) { + private function getDocumentAccessFromUser(IUser $user): DocumentAccess { $rights = new DocumentAccess(); $rights->setViewerId($user->getUID()); diff --git a/lib/Service/SettingsService.php b/lib/Service/SettingsService.php index 939db0f..e6b7353 100644 --- a/lib/Service/SettingsService.php +++ b/lib/Service/SettingsService.php @@ -1,4 +1,7 @@ $this->completeSettingsPlatforms(), @@ -86,7 +99,7 @@ class SettingsService { * @return array * @throws Exception */ - private function completeSettingsPlatforms() { + private function completeSettingsPlatforms(): array { $list = []; $platforms = $this->platformService->getPlatforms(); foreach ($platforms as $wrapper) { @@ -105,7 +118,7 @@ class SettingsService { * @return array * @throws Exception */ - private function completeSettingsProviders() { + private function completeSettingsProviders(): array { $list = []; $providers = $this->providerService->getProviders(); foreach ($providers as $providerWrapper) { diff --git a/lib/Service/TestService.php b/lib/Service/TestService.php index f362d88..469933a 100644 --- a/lib/Service/TestService.php +++ b/lib/Service/TestService.php @@ -1,4 +1,7 @@ generateIndexDocument(self::DOCUMENT_TYPE_LICENSE); $content = file_get_contents(__DIR__ . '/../../LICENSE'); @@ -96,7 +107,7 @@ class TestService { * * @return IndexDocument */ - public function generateIndexDocumentSimple(IIndexOptions $options) { + public function generateIndexDocumentSimple(IIndexOptions $options): IndexDocument { $indexDocument = $this->generateIndexDocument(self::DOCUMENT_TYPE_SIMPLE); $indexDocument->setContent('document is a simple test'); @@ -141,7 +152,7 @@ class TestService { * * @return IndexDocument */ - private function generateIndexDocument($documentType) { + private function generateIndexDocument(string $documentType): IndexDocument { $indexDocument = new IndexDocument(TestProvider::TEST_PROVIDER_ID, $documentType); $access = new DocumentAccess(self::DOCUMENT_USER1); -- cgit v1.2.3 From 5ad06f14e53253116e8f1fd7aa5cfcba204ab97a Mon Sep 17 00:00:00 2001 From: Maxence Lange Date: Wed, 31 Oct 2018 19:40:12 +0100 Subject: fixing Signed-off-by: Maxence Lange --- lib/Controller/NavigationController.php | 1 + lib/Cron/Index.php | 2 +- lib/Db/TickRequestBuilder.php | 4 ---- lib/Model/PlatformWrapper.php | 1 - lib/Model/Runner.php | 1 - lib/Service/ConfigService.php | 1 - lib/Service/MiscService.php | 1 - 7 files changed, 2 insertions(+), 9 deletions(-) (limited to 'lib') diff --git a/lib/Controller/NavigationController.php b/lib/Controller/NavigationController.php index 97a51e2..1fbf705 100644 --- a/lib/Controller/NavigationController.php +++ b/lib/Controller/NavigationController.php @@ -67,6 +67,7 @@ class NavigationController extends Controller { * * @param IRequest $request * @param IConfig $config + * @param IFullTextSearchManager $fullTextSearchManager * @param ConfigService $configService * @param MiscService $miscService */ diff --git a/lib/Cron/Index.php b/lib/Cron/Index.php index f54d47b..3614246 100644 --- a/lib/Cron/Index.php +++ b/lib/Cron/Index.php @@ -163,6 +163,6 @@ class Index extends TimedJob { * */ private function setLastErrReset() { - $this->configService->setAppValue(ConfigService::CRON_LAST_ERR_RESET, time()); + $this->configService->setAppValue(ConfigService::CRON_LAST_ERR_RESET, (string) time()); } } diff --git a/lib/Db/TickRequestBuilder.php b/lib/Db/TickRequestBuilder.php index e19ca84..9fa95e7 100644 --- a/lib/Db/TickRequestBuilder.php +++ b/lib/Db/TickRequestBuilder.php @@ -32,11 +32,7 @@ namespace OCA\FullTextSearch\Db; use OCA\FullTextSearch\Model\Tick; -use OCA\FullTextSearch\Service\ConfigService; -use OCA\FullTextSearch\Service\MiscService; use OCP\DB\QueryBuilder\IQueryBuilder; -use OCP\IDBConnection; -use OCP\IL10N; /** diff --git a/lib/Model/PlatformWrapper.php b/lib/Model/PlatformWrapper.php index 2c57dba..6f9f84c 100644 --- a/lib/Model/PlatformWrapper.php +++ b/lib/Model/PlatformWrapper.php @@ -31,7 +31,6 @@ declare(strict_types=1); namespace OCA\FullTextSearch\Model; -use OC\App\Platform; use OCP\FullTextSearch\IFullTextSearchPlatform; diff --git a/lib/Model/Runner.php b/lib/Model/Runner.php index ac78684..4a0ef18 100644 --- a/lib/Model/Runner.php +++ b/lib/Model/Runner.php @@ -36,7 +36,6 @@ use OCA\FullTextSearch\ACommandBase; use OCA\FullTextSearch\Exceptions\RunnerAlreadyUpException; use OCA\FullTextSearch\Exceptions\TickDoesNotExistException; use OCA\FullTextSearch\Exceptions\TickIsNotAliveException; -use OCA\FullTextSearch\Service\MiscService; use OCA\FullTextSearch\Service\RunningService; use OCP\FullTextSearch\Model\IIndex; use OCP\FullTextSearch\Model\IRunner; diff --git a/lib/Service/ConfigService.php b/lib/Service/ConfigService.php index 614cd48..5da4d76 100644 --- a/lib/Service/ConfigService.php +++ b/lib/Service/ConfigService.php @@ -212,7 +212,6 @@ class ConfigService { * @param string $key * @param string $value * - * @return string * @throws PreConditionNotMetException */ public function setValueForUser(string $userId, string $key, string $value) { diff --git a/lib/Service/MiscService.php b/lib/Service/MiscService.php index c8a608c..8927fc8 100644 --- a/lib/Service/MiscService.php +++ b/lib/Service/MiscService.php @@ -33,7 +33,6 @@ namespace OCA\FullTextSearch\Service; use OCA\FullTextSearch\AppInfo\Application; use OCP\ILogger; -use OCP\Util; /** -- cgit v1.2.3 From 8dffae6d2c7be5e767886c5a5a51cd500b1ef1b5 Mon Sep 17 00:00:00 2001 From: Maxence Lange Date: Thu, 1 Nov 2018 21:17:12 +0100 Subject: init and cast Signed-off-by: Maxence Lange --- lib/Db/IndexesRequestBuilder.php | 6 +++--- lib/Db/TickRequestBuilder.php | 6 +++--- lib/Model/Runner.php | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) (limited to 'lib') diff --git a/lib/Db/IndexesRequestBuilder.php b/lib/Db/IndexesRequestBuilder.php index 0eb72ce..b76230d 100644 --- a/lib/Db/IndexesRequestBuilder.php +++ b/lib/Db/IndexesRequestBuilder.php @@ -110,12 +110,12 @@ class IndexesRequestBuilder extends CoreRequestBuilder { */ protected function parseIndexesSelectSql(array $data): Index { $index = new Index($data['provider_id'], $data['document_id']); - $index->setStatus($data['status']) + $index->setStatus((int)$data['status']) ->setSource($data['source']) ->setOwnerId($data['owner_id']) - ->setLastIndex($data['indexed']); + ->setLastIndex((int)$data['indexed']); $index->setOptions(json_decode($data['options'], true)); - $index->setErrorCount($data['err']); + $index->setErrorCount((int)$data['err']); $index->setErrors(json_decode($data['message'], true)); return $index; diff --git a/lib/Db/TickRequestBuilder.php b/lib/Db/TickRequestBuilder.php index 9fa95e7..a90aede 100644 --- a/lib/Db/TickRequestBuilder.php +++ b/lib/Db/TickRequestBuilder.php @@ -108,10 +108,10 @@ class TickRequestBuilder extends CoreRequestBuilder { * @return Tick */ protected function parseTickSelectSql(array $data): Tick { - $tick = new Tick($data['source'], $data['id']); + $tick = new Tick($data['source'], (int) $data['id']); $tick->setData(json_decode($data['data'], true)) - ->setTick($data['tick']) - ->setFirstTick($data['first_tick']) + ->setTick((int) $data['tick']) + ->setFirstTick((int) $data['first_tick']) ->setStatus($data['status']) ->setAction($data['action']); diff --git a/lib/Model/Runner.php b/lib/Model/Runner.php index 4a0ef18..7f17b7f 100644 --- a/lib/Model/Runner.php +++ b/lib/Model/Runner.php @@ -66,7 +66,7 @@ class Runner implements IRunner { private $source; /** @var int */ - private $tickId; + private $tickId = 0; /** @var ACommandBase */ private $base = null; -- cgit v1.2.3 From c14fef4cd5d1d06f590ecdde94246f90b17af69a Mon Sep 17 00:00:00 2001 From: Maxence Lange Date: Thu, 1 Nov 2018 21:17:31 +0100 Subject: better use float Signed-off-by: Maxence Lange --- lib/Model/Tick.php | 24 +++++++++++++++++++++++- lib/Service/RunningService.php | 8 ++++---- 2 files changed, 27 insertions(+), 5 deletions(-) (limited to 'lib') diff --git a/lib/Model/Tick.php b/lib/Model/Tick.php index 46bb7b2..3a9efc2 100644 --- a/lib/Model/Tick.php +++ b/lib/Model/Tick.php @@ -63,7 +63,7 @@ class Tick { private $status; /** @var string */ - private $action; + private $action = ''; /** @@ -232,6 +232,18 @@ class Tick { return $this; } + /** + * @param string $info + * @param float $value + * + * @return $this + */ + public function setInfoFloat(string $info, float $value): Tick { + $this->data[$info] = $value; + + return $this; + } + /** * @param string $info */ @@ -260,5 +272,15 @@ class Tick { return $this->getInt($info, $this->data, $default); } + /** + * @param string $info + * @param float $default + * + * @return float + */ + public function getInfoFloat(string $info, float $default = 0): float { + return $this->getFloat($info, $this->data, $default); + } + } diff --git a/lib/Service/RunningService.php b/lib/Service/RunningService.php index 0527a63..a182f0b 100644 --- a/lib/Service/RunningService.php +++ b/lib/Service/RunningService.php @@ -238,18 +238,18 @@ class RunningService { $preAction = $tick->getAction(); if ($preAction !== '') { - $preActionTotal = $tick->getInfoInt($preAction . 'Total', 0); - $preActionStart = $tick->getInfoInt($preAction . 'Init', 0); + $preActionTotal = $tick->getInfoFloat($preAction . 'Total', 0); + $preActionStart = $tick->getInfoFloat($preAction . 'Init', 0); if ($preActionStart > 0) { $preActionTotal += ($now - $preActionStart); - $tick->setInfoInt($preAction . 'Total', $preActionTotal); + $tick->setInfoFloat($preAction . 'Total', $preActionTotal); $tick->unsetInfo($preAction . 'Init'); } } $tick->setAction($action) - ->setInfoInt($action . 'Init', $now); + ->setInfoFloat($action . 'Init', $now); } -- cgit v1.2.3 From 2c8f5cdaf80799b5ca5cf5bc059889d302230794 Mon Sep 17 00:00:00 2001 From: Maxence Lange Date: Thu, 1 Nov 2018 21:17:51 +0100 Subject: sometime $userId can be null Signed-off-by: Maxence Lange --- lib/Service/ConfigService.php | 4 +--- lib/Service/SearchService.php | 2 +- 2 files changed, 2 insertions(+), 4 deletions(-) (limited to 'lib') diff --git a/lib/Service/ConfigService.php b/lib/Service/ConfigService.php index 5da4d76..00ccbd0 100644 --- a/lib/Service/ConfigService.php +++ b/lib/Service/ConfigService.php @@ -78,9 +78,7 @@ class ConfigService { * @param string $userId * @param MiscService $miscService */ - public function __construct( - IConfig $config, string $userId, MiscService $miscService - ) { + public function __construct(IConfig $config, $userId, MiscService $miscService) { $this->config = $config; $this->userId = $userId; $this->miscService = $miscService; diff --git a/lib/Service/SearchService.php b/lib/Service/SearchService.php index db36ed9..2761f01 100644 --- a/lib/Service/SearchService.php +++ b/lib/Service/SearchService.php @@ -96,7 +96,7 @@ class SearchService implements ISearchService { * @param MiscService $miscService */ public function __construct( - string $userId, AppManager $appManager, IUserManager $userManager, + $userId, AppManager $appManager, IUserManager $userManager, IGroupManager $groupManager, ConfigService $configService, ProviderService $providerService, PlatformService $platformService, -- cgit v1.2.3 From 17392ad232e8f1f39dfcaa2c005511a88ea56e2c Mon Sep 17 00:00:00 2001 From: Maxence Lange Date: Thu, 1 Nov 2018 21:30:03 +0100 Subject: init var Signed-off-by: Maxence Lange --- lib/Command/Test.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/Command/Test.php b/lib/Command/Test.php index feb38f2..1ada38d 100644 --- a/lib/Command/Test.php +++ b/lib/Command/Test.php @@ -224,6 +224,7 @@ class Test extends ACommandBase { * @param bool $result */ private function outputResult(OutputInterface $output, bool $result) { + $isNewLine = false; $line = $this->convertBoolToLine($result, $isNewLine); $this->output($output, $line, $isNewLine); @@ -474,7 +475,7 @@ class Test extends ACommandBase { $this->output($output, 'Updating documents access.'); $options = new IndexOptions( [ - 'provider' => TestProvider::TEST_PROVIDER_ID, + 'provider' => TestProvider::TEST_PROVIDER_ID, TestService::DOCUMENT_INDEXING_OPTION => TestService::DOCUMENT_INDEXING_ACCESS ] ); -- cgit v1.2.3