diff options
author | Maxence Lange <maxence@artificial-owl.com> | 2018-10-26 11:10:16 +0300 |
---|---|---|
committer | Maxence Lange <maxence@artificial-owl.com> | 2018-10-26 11:10:16 +0300 |
commit | 339153942c2b56afef03726caf1d3531bb33bcf4 (patch) | |
tree | f4f231a9c3a18dd8184b1fbe59b22b73aa88b10a | |
parent | 5d7563d1a0bcf1c6dc7ba3320824efa1fe624b4c (diff) |
compat-nc15
Signed-off-by: Maxence Lange <maxence@artificial-owl.com>
50 files changed, 791 insertions, 1872 deletions
@@ -8,9 +8,9 @@ sign_dir=$(build_dir)/sign package_name=$(app_name) cert_dir=$(HOME)/.nextcloud/certificates github_account=nextcloud -branch=stable14 +branch=master codecov_token_dir=$(HOME)/.nextcloud/codecov_token -version+=1.0.3 +version+=1.2.0 all: appstore diff --git a/appinfo/app.php b/appinfo/app.php index a6a971e..74de16e 100644 --- a/appinfo/app.php +++ b/appinfo/app.php @@ -31,6 +31,7 @@ use OCP\AppFramework\QueryException; try { $app = new Application(); + $app->registerServices(); $app->registerNavigation(); $app->registerSettingsAdmin(); } catch (QueryException $e) { diff --git a/appinfo/info.xml b/appinfo/info.xml index 3e95264..6782c38 100644 --- a/appinfo/info.xml +++ b/appinfo/info.xml @@ -10,7 +10,7 @@ Core App of the full-text search framework for your Nextcloud. ]]> </description> - <version>1.0.3</version> + <version>1.2.0</version> <licence>agpl</licence> <author>Maxence Lange</author> <namespace>FullTextSearch</namespace> @@ -23,7 +23,7 @@ Core App of the full-text search framework for your Nextcloud. <repository>https://github.com/nextcloud/fulltextsearch.git</repository> <screenshot>https://raw.githubusercontent.com/nextcloud/fulltextsearch/master/screenshots/0.3.0.png</screenshot> <dependencies> - <nextcloud min-version="13" max-version="14"/> + <nextcloud min-version="15" max-version="15"/> </dependencies> <background-jobs> diff --git a/js/fulltextsearch.v1.navigation.js b/js/fulltextsearch.v1.navigation.js index 8e05d36..2cafd1d 100644 --- a/js/fulltextsearch.v1.navigation.js +++ b/js/fulltextsearch.v1.navigation.js @@ -252,46 +252,46 @@ var nav = { onEntryGenerated: function (divEntry, entry) { - if (settings.parentHasMethod('onEntryGenerated')) { + if (settings.parentHasMethod('onEntryGenerated', window)) { settings.parent.onEntryGenerated(divEntry, entry); } }, onEntrySelected: function (divEntry, event) { - return !!(settings.parentHasMethod('onEntrySelected') && + return !!(settings.parentHasMethod('onEntrySelected', window) && settings.parent.onEntrySelected(divEntry, event)); }, onSearchRequest: function (data) { - if (settings.parentHasMethod('onSearchRequest')) { + if (settings.parentHasMethod('onSearchRequest', window)) { settings.parent.onSearchRequest(data); } }, onSearchReset: function () { - if (settings.parentHasMethod('onSearchReset')) { + if (settings.parentHasMethod('onSearchReset', window)) { settings.parent.onSearchReset(); } }, onResultDisplayed: function (data) { - if (settings.parentHasMethod('onResultDisplayed')) { + if (settings.parentHasMethod('onResultDisplayed', window)) { settings.parent.onResultDisplayed(data); } }, onResultClose: function () { - if (settings.parentHasMethod('onResultClose')) { + if (settings.parentHasMethod('onResultClose', window)) { settings.parent.onResultClose(); } }, onError: function (data) { - if (settings.parentHasMethod('onError')) { + if (settings.parentHasMethod('onError', window)) { settings.parent.onError(data); } }, diff --git a/js/fulltextsearch.v1.settings.js b/js/fulltextsearch.v1.settings.js index 04a7b29..4c364cc 100644 --- a/js/fulltextsearch.v1.settings.js +++ b/js/fulltextsearch.v1.settings.js @@ -49,29 +49,28 @@ var settings = { */ generateDefaultTemplate: function () { - var resultContent = $('<div>', {class: 'result_content'}); - resultContent.append($('<div>', { - id: 'title', - class: 'result_title' - })); - resultContent.append($('<div>', { - id: 'extract', - class: 'result_extract' - })); - - var resultEntry = $('<div>', {class: 'result_entry'}); - resultEntry.append($('<div>', {class: 'result_div_checkbox'})); - - resultEntry.append($('<div>', {class: 'result_div result_div_content'}).append(resultContent)); - - var resultRight = $('<div>', {class: 'result_div result_div_right'}); - resultRight.append($('<div>', {id: 'source'})); - resultRight.append($('<div>', {id: 'info'})); - resultEntry.append(resultRight); - - return $('<div>').append(resultEntry); - }, - + var resultContent = $('<div>', {class: 'result_content'}); + resultContent.append($('<div>', { + id: 'title', + class: 'result_title' + })); + resultContent.append($('<div>', { + id: 'extract', + class: 'result_extract' + })); + + var resultEntry = $('<div>', {class: 'result_entry'}); + resultEntry.append($('<div>', {class: 'result_div_checkbox'})); + + resultEntry.append($('<div>', {class: 'result_div result_div_content'}).append(resultContent)); + + var resultRight = $('<div>', {class: 'result_div result_div_right'}); + resultRight.append($('<div>', {id: 'source'})); + resultRight.append($('<div>', {id: 'info'})); + resultEntry.append(resultRight); + + return $('<div>').append(resultEntry); + }, // var divLeft = $('<div>', {class: 'result_entry_left'}); @@ -156,12 +155,41 @@ var settings = { * check that the app that call the lib contains a specific method * * @param method + * @param context * @returns {boolean} */ - parentHasMethod: function (method) { + parentHasMethod: function (method, context) { if (settings.parent === null) { return false; } - return (typeof eval('settings.parent. ' + method) === "function"); + + var functionName = 'settings.parent.' + method; + var args = Array.prototype.slice.call(arguments, 2); + var namespaces = functionName.split("."); + for (var i = 0; i < namespaces.length; i++) { + if (context[namespaces[i]] === undefined) { + return false; + } + context = context[namespaces[i]]; + } + return true; + }, + + + executeFunction: function (functionName, context) { + var args = Array.prototype.slice.call(arguments, 2); + var namespaces = functionName.split("."); + var func = namespaces.pop(); + for (var i = 0; i < namespaces.length; i++) { + if (context[namespaces[i]] === undefined) { + // console.log('Unknown function \'' + functionName + '\''); + return false; + } + context = context[namespaces[i]]; + } + + return context[func].apply(context, args); } + + }; diff --git a/js/navigate.js b/js/navigate.js index b90e766..fa6fc7f 100644 --- a/js/navigate.js +++ b/js/navigate.js @@ -103,7 +103,6 @@ Navigate.prototype = { initPanels: function () { var self = this; - $.ajax({ method: 'GET', url: OC.generateUrl('/apps/fulltextsearch/navigation/panels') @@ -120,57 +119,59 @@ Navigate.prototype = { for (var i = 0; i < ak.length; i++) { var providerAppId = ak[i]; var title = data[ak[i]]['title']; - var nav = data[ak[i]]['navigation']; + var options = data[ak[i]]['options']; + var css = data[ak[i]]['css']; + var icon = data[ak[i]]['icon']; var providerId = data[ak[i]]['provider']; - if (nav.css !== undefined) { - OC.addStyle(providerAppId, nav.css); + if (css !== '') { + OC.addStyle(providerAppId, css); } var li = $('<li>', {class: (nav.options !== undefined) ? 'collapsible open' : ''}); var aIcon = $('<a>', { href: '#', - class: (nav.icon !== undefined) ? nav.icon : 'search_icon' + class: (icon !== undefined) ? icon : 'search_icon' }); aIcon.text(title); var ul = $('<ul>'); - if (nav.options !== undefined) { - - aIcon.on('click', function () { - var li = $(this).closest('li'); - if (li.hasClass('open')) { - li.removeClass('open'); - } else { - li.addClass('open'); - } - }); - - for (var j = 0; j < nav.options.length; j++) { - var sub = nav.options[j]; - self.displayPanelCheckbox(ul, sub); - self.displayPanelInput(ul, sub); - self.displayPanelTags(ul, sub); - self.displayPanelSearch(providerAppId, ul, sub); - // - // <p id="tag_filter" class="open"> - // <input value="" style="display: none;" type="text"> - // <ul class="tagit ui-widget ui-widget-content ui-corner-all"> - // <li class="tagit-new"> - // <input class="ui-widget-content ui-autocomplete-input" - // placeholder="Filter by tag" autocomplete="off" type="text"> <span role="status" - // aria-live="polite" class="ui-helper-hidden-accessible"> 1 result is available, - // use up and down arrow keys to navigate.</span></li> <li class="tagit-choice - // ui-widget-content ui-state-default ui-corner-all"> <span - // class="tagit-label">test</span><a class="close"><span class="text-icon">×</span> - // <span class="ui-icon ui-icon-close"></span></a></li> <li class="tagit-choice - // ui-widget-content ui-state-default ui-corner-all"> <span - // class="tagit-label">perdu</span><a class="close"><span class="text-icon">×</span> - // <span class="ui-icon ui-icon-close"></span></a></li></ul> </p> + // if (nav.options !== undefined) { + + aIcon.on('click', function () { + var li = $(this).closest('li'); + if (li.hasClass('open')) { + li.removeClass('open'); + } else { + li.addClass('open'); + } + }); + + for (var j = 0; j < options.length; j++) { + var sub = options[j]; + self.displayPanelCheckbox(ul, sub); + self.displayPanelInput(ul, sub); + self.displayPanelTags(ul, sub); + self.displayPanelSearch(providerAppId, ul, sub); + // + // <p id="tag_filter" class="open"> + // <input value="" style="display: none;" type="text"> + // <ul class="tagit ui-widget ui-widget-content ui-corner-all"> + // <li class="tagit-new"> + // <input class="ui-widget-content ui-autocomplete-input" + // placeholder="Filter by tag" autocomplete="off" type="text"> <span role="status" + // aria-live="polite" class="ui-helper-hidden-accessible"> 1 result is available, + // use up and down arrow keys to navigate.</span></li> <li class="tagit-choice + // ui-widget-content ui-state-default ui-corner-all"> <span + // class="tagit-label">test</span><a class="close"><span class="text-icon">×</span> + // <span class="ui-icon ui-icon-close"></span></a></li> <li class="tagit-choice + // ui-widget-content ui-state-default ui-corner-all"> <span + // class="tagit-label">perdu</span><a class="close"><span class="text-icon">×</span> + // <span class="ui-icon ui-icon-close"></span></a></li></ul> </p> - } } + // } li.append(aIcon); var aInput = $('<input>', { 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 { @@ -64,6 +68,25 @@ class Application extends App { * * @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 + * + * @throws QueryException + */ public function registerNavigation() { /** @var ConfigService $configService */ 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 @@ -<?php -/** - * FullTextSearch - Full text search framework for Nextcloud - * - * This file is licensed under the Affero General Public License version 3 or - * later. See the COPYING file. - * - * @author Maxence Lange <maxence@artificial-owl.com> - * @copyright 2018 - * @license GNU AGPL version 3 or any later version - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * - */ - -namespace OCA\FullTextSearch; - - -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 @@ -<?php -/** - * FullTextSearch - Full text search framework for Nextcloud - * - * This file is licensed under the Affero General Public License version 3 or - * later. See the COPYING file. - * - * @author Maxence Lange <maxence@artificial-owl.com> - * @copyright 2018 - * @license GNU AGPL version 3 or any later version - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * - */ - -namespace OCA\FullTextSearch; - -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 @@ -<?php -/** - * FullTextSearch - Full text search framework for Nextcloud - * - * This file is licensed under the Affero General Public License version 3 or - * later. See the COPYING file. - * - * @author Maxence Lange <maxence@artificial-owl.com> - * @copyright 2018 - * @license GNU AGPL version 3 or any later version - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * - */ - -namespace OCA\FullTextSearch\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 @@ -<?php -/** - * FullTextSearch - Full text search framework for Nextcloud - * - * This file is licensed under the Affero General Public License version 3 or - * later. See the COPYING file. - * - * @author Maxence Lange <maxence@artificial-owl.com> - * @copyright 2018 - * @license GNU AGPL version 3 or any later version - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * - */ - - -namespace OCA\FullTextSearch\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 @@ -<?php -/** - * FullTextSearch - Full text search framework for Nextcloud - * - * This file is licensed under the Affero General Public License version 3 or - * later. See the COPYING file. - * - * @author Maxence Lange <maxence@artificial-owl.com> - * @copyright 2018 - * @license GNU AGPL version 3 or any later version - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * - */ - - -namespace OCA\FullTextSearch\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 @@ -<?php -/** - * FullTextSearch - Full text search framework for Nextcloud - * - * This file is licensed under the Affero General Public License version 3 or - * later. See the COPYING file. - * - * @author Maxence Lange <maxence@artificial-owl.com> - * @copyright 2018 - * @license GNU AGPL version 3 or any later version - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * - */ - - -namespace OCA\FullTextSearch\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 @@ <?php +declare(strict_types=1); + + /** - * FullTextSearch - Full text search framework for extcloud + * FullTextSearch - Full text search framework for Nextcloud * * This file is licensed under the Affero General Public License version 3 or * later. See the COPYING file. @@ -24,29 +27,14 @@ * */ -namespace OCA\FullTextSearch\Model; - -class Index implements \JsonSerializable { - const INDEX_OK = 1; - const INDEX_IGNORE = 2; - - const INDEX_META = 4; - const INDEX_CONTENT = 8; - const INDEX_FULL = 12; - const INDEX_REMOVE = 16; +namespace OCA\FullTextSearch\Model; - const INDEX_DONE = 32; - const INDEX_FAILED = 64; +use JsonSerializable; +use OCP\FullTextSearch\Model\IIndex; - const ERROR_FAILED = 1; - const ERROR_FAILED2 = 2; - const ERROR_FAILED3 = 4; - const ERROR_SEV_1 = 1; - const ERROR_SEV_2 = 2; - const ERROR_SEV_3 = 3; - const ERROR_SEV_4 = 4; +class Index implements IIndex, JsonSerializable { /** @var string */ @@ -83,7 +71,7 @@ class Index implements \JsonSerializable { * @param string $providerId * @param string $documentId */ - public function __construct($providerId, $documentId) { + public function __construct(string $providerId, string $documentId) { $this->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 @@ -<?php -/** - * FullTextSearch - Full text search framework for Nextcloud - * - * This file is licensed under the Affero General Public License version 3 or - * later. See the COPYING file. - * - * @author Maxence Lange <maxence@artificial-owl.com> - * @copyright 2018 - * @license GNU AGPL version 3 or any later version - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * - */ - -namespace OCA\FullTextSearch\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<string,string|integer|DocumentAccess|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 <b>json_encode</b>, - * 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 @@ <?php +declare(strict_types=1); + + /** * FullTextSearch - Full text search framework for Nextcloud * @@ -24,12 +27,18 @@ * */ + namespace OCA\FullTextSearch\Model; -use OCA\FullTextSearch\IFullTextSearchPlatform; -use OCA\FullTextSearch\IFullTextSearchProvider; +use JsonSerializable; +use OCP\FullTextSearch\IFullTextSearchPlatform; +use OCP\FullTextSearch\IFullTextSearchProvider; +use OCP\FullTextSearch\Model\IndexDocument; +use OCP\FullTextSearch\Model\ISearchRequest; +use OCP\FullTextSearch\Model\ISearchResult; -class SearchResult implements \JsonSerializable { + +class SearchResult implements ISearchResult, JsonSerializable { /** @var IndexDocument[] */ private $documents = []; @@ -55,7 +64,7 @@ class SearchResult implements \JsonSerializable { /** @var boolean */ private $timedOut; - /** @var SearchRequest */ + /** @var ISearchRequest */ private $request; @@ -67,9 +76,9 @@ class SearchResult implements \JsonSerializable { /** * @param IndexDocument[] $documents * - * @return $this + * @return ISearchResult */ - public function setDocuments($documents) { + public function setDocuments(array $documents): ISearchResult { $this->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); @@ -157,20 +157,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. * * @param IndexDocument $document */ @@ -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; @@ -99,18 +102,29 @@ 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'); |