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

github.com/nextcloud/fulltextsearch.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorMaxence Lange <maxence@artificial-owl.com>2018-11-02 00:03:13 +0300
committerMaxence Lange <maxence@artificial-owl.com>2018-11-02 00:03:13 +0300
commit11c2dbde5593e3289f1e9a8d3268fa6c949117ca (patch)
tree482c19044006ea215be8d2a8d1a17db49fc3bb5e /lib
parent347a517931ced4eed9af10a1148472c00633c977 (diff)
parent17392ad232e8f1f39dfcaa2c005511a88ea56e2c (diff)
Merge branch 'compat-nc15'
Signed-off-by: Maxence Lange <maxence@artificial-owl.com>
Diffstat (limited to 'lib')
-rw-r--r--lib/ACommandBase.php (renamed from lib/Model/ExtendedIndex.php)18
-rw-r--r--lib/Api/v1/FullTextSearch.php192
-rw-r--r--lib/AppInfo/Application.php44
-rw-r--r--lib/Capabilities.php13
-rw-r--r--lib/Command/Check.php17
-rw-r--r--lib/Command/Configure.php15
-rw-r--r--lib/Command/DocumentPlatform.php10
-rw-r--r--lib/Command/DocumentProvider.php17
-rw-r--r--lib/Command/Index.php141
-rw-r--r--lib/Command/Live.php104
-rw-r--r--lib/Command/Reset.php37
-rw-r--r--lib/Command/Search.php30
-rw-r--r--lib/Command/Stop.php22
-rw-r--r--lib/Command/Test.php146
-rw-r--r--lib/Controller/ApiController.php58
-rw-r--r--lib/Controller/NavigationController.php31
-rw-r--r--lib/Controller/SettingsController.php15
-rw-r--r--lib/Controller/TemplatesController.php55
-rw-r--r--lib/Cron/Index.php12
-rw-r--r--lib/Db/CoreRequestBuilder.php67
-rw-r--r--lib/Db/IndexesRequest.php73
-rw-r--r--lib/Db/IndexesRequestBuilder.php56
-rw-r--r--lib/Db/TickRequest.php31
-rw-r--r--lib/Db/TickRequestBuilder.php50
-rw-r--r--lib/Exceptions/DatabaseException.php5
-rw-r--r--lib/Exceptions/EmptySearchException.php5
-rw-r--r--lib/Exceptions/IndexDoesNotExistException.php5
-rw-r--r--lib/Exceptions/InterruptException.php5
-rw-r--r--lib/Exceptions/MissingDocumentException.php5
-rw-r--r--lib/Exceptions/NoResultException.php5
-rw-r--r--lib/Exceptions/NotIndexableDocumentException.php5
-rw-r--r--lib/Exceptions/PlatformDoesNotExistException.php5
-rw-r--r--lib/Exceptions/PlatformIsNotCompatibleException.php5
-rw-r--r--lib/Exceptions/PlatformMustBeSingleException.php5
-rw-r--r--lib/Exceptions/PlatformNotDefinedException.php5
-rw-r--r--lib/Exceptions/PlatformNotSelectedException.php5
-rw-r--r--lib/Exceptions/ProviderDoesNotExistException.php5
-rw-r--r--lib/Exceptions/ProviderIsNotCompatibleException.php5
-rw-r--r--lib/Exceptions/ProviderIsNotUniqueException.php5
-rw-r--r--lib/Exceptions/ProviderOptionsDoesNotExistException.php5
-rw-r--r--lib/Exceptions/RunnerAlreadyUpException.php5
-rw-r--r--lib/Exceptions/TickDoesNotExistException.php5
-rw-r--r--lib/Exceptions/TickIsNotAliveException.php5
-rw-r--r--lib/IFullTextSearchPlatform.php151
-rw-r--r--lib/IFullTextSearchProvider.php169
-rw-r--r--lib/Migration/ResetIndexes.php102
-rw-r--r--lib/Model/DocumentAccess.php192
-rw-r--r--lib/Model/ExtendedBase.php72
-rw-r--r--lib/Model/ExtendedTick.php64
-rw-r--r--lib/Model/Index.php152
-rw-r--r--lib/Model/IndexDocument.php633
-rw-r--r--lib/Model/IndexOptions.php115
-rw-r--r--lib/Model/PlatformWrapper.php25
-rw-r--r--lib/Model/ProviderIndexes.php31
-rw-r--r--lib/Model/ProviderWrapper.php20
-rw-r--r--lib/Model/Runner.php151
-rw-r--r--lib/Model/SearchRequest.php302
-rw-r--r--lib/Model/SearchResult.php151
-rw-r--r--lib/Model/Tick.php128
-rw-r--r--lib/Provider/TestProvider.php80
-rw-r--r--lib/Service/CliService.php34
-rw-r--r--lib/Service/ConfigService.php69
-rw-r--r--lib/Service/IndexService.php184
-rw-r--r--lib/Service/MiscService.php78
-rw-r--r--lib/Service/PlatformService.php25
-rw-r--r--lib/Service/ProviderService.php68
-rw-r--r--lib/Service/RunningService.php61
-rw-r--r--lib/Service/SearchService.php60
-rw-r--r--lib/Service/SettingsService.php23
-rw-r--r--lib/Service/TestService.php27
-rw-r--r--lib/Settings/Admin.php20
-rw-r--r--lib/Settings/AdminSection.php23
72 files changed, 1920 insertions, 2639 deletions
diff --git a/lib/Model/ExtendedIndex.php b/lib/ACommandBase.php
index a26377e..56d5129 100644
--- a/lib/Model/ExtendedIndex.php
+++ b/lib/ACommandBase.php
@@ -1,4 +1,7 @@
<?php
+declare(strict_types=1);
+
+
/**
* FullTextSearch - Full text search framework for Nextcloud
*
@@ -21,15 +24,22 @@
*
* 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;
+namespace OCA\FullTextSearch;
+
+use OC\Core\Command\Base;
-class ExtendedIndex extends Index {
+/**
+ * Abstract class ICommandBase
+ */
+abstract class ACommandBase extends Base {
+
+ abstract public function abort();
+}
-} \ No newline at end of file
diff --git a/lib/Api/v1/FullTextSearch.php b/lib/Api/v1/FullTextSearch.php
deleted file mode 100644
index 6ae451b..0000000
--- a/lib/Api/v1/FullTextSearch.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\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;
-use OCA\FullTextSearch\Service\SearchService;
-use OCP\AppFramework\QueryException;
-use OCP\Util;
-
-class FullTextSearch {
-
- const API_VERSION = [0, 1, 0];
-
- protected static function getContainer() {
- $app = new Application();
-
- return $app->getContainer();
- }
-
-
- /**
- * returns app name
- *
- * @return string
- */
- public static function appName() {
- return Application::APP_NAME;
- }
-
-
- /**
- * FullTextSearch::version();
- *
- * returns the current version of the API
- *
- * @return array
- * @throws QueryException
- */
- public static function version() {
- $c = self::getContainer();
-
- return [
- [
- 'fulltextsearch' => $c->query(ConfigService::class)
- ->getAppValue('installed_version')
- ],
- ['api' => self::API_VERSION]
- ];
- }
-
-
- /**
- *
- */
- public static function addJavascriptAPI() {
- Util::addStyle(Application::APP_NAME, 'fulltextsearch');
- Util::addScript(Application::APP_NAME, 'fulltextsearch.v1.api');
- Util::addScript(Application::APP_NAME, 'fulltextsearch.v1.settings');
- Util::addScript(Application::APP_NAME, 'fulltextsearch.v1.searchbox');
- Util::addScript(Application::APP_NAME, 'fulltextsearch.v1.result');
- Util::addScript(Application::APP_NAME, 'fulltextsearch.v1.navigation');
- Util::addScript(Application::APP_NAME, 'fulltextsearch.v1');
- }
-
-
- /**
- * @param string $providerId
- * @param string|int $documentId
- *
- * @return ExtendedIndex
- * @throws QueryException
- */
- public static function getIndex($providerId, $documentId) {
- $c = self::getContainer();
-
- return $c->query(IndexService::class)
- ->getIndex($providerId, $documentId);
- }
-
-
- /**
- * @param string $providerId
- * @param string|int $documentId
- * @param string $ownerId
- * @param int $status
- *
- * @return mixed
- * @throws QueryException
- */
- public static function createIndex($providerId, $documentId, $ownerId, $status = 0) {
- $index = new Index($providerId, $documentId);
- $index->setOwnerId($ownerId);
- $index->setStatus($status);
-
- return self::updateIndexes([$index]);
- }
-
-
- /**
- * @param string $providerId
- * @param string|int|array $documentIds
- * @param int $status
- * @param bool $reset
- *
- * @return mixed
- * @throws QueryException
- */
- public static function updateIndexStatus($providerId, $documentIds, $status, $reset = false) {
- $c = self::getContainer();
-
- if (!is_array($documentIds)) {
- $documentIds = [$documentIds];
- }
-
- return $c->query(IndexService::class)
- ->updateIndexesStatus($providerId, $documentIds, $status, $reset);
- }
-
-
- /**
- * @param Index[] $indexes
- *
- * @return mixed
- * @throws QueryException
- */
- public static function updateIndexes($indexes) {
- $c = self::getContainer();
-
- return $c->query(IndexService::class)
- ->updateIndexes($indexes);
- }
-
-
- /**
- * @param string $providerId
- * @param string|int $search
- *
- * @return mixed
- * @throws QueryException
- */
- public static function search($providerId, $search) {
- $c = self::getContainer();
-
- return $c->query(SearchService::class)
- ->search($providerId, null, $search);
- }
-
-
- /**
- * @param $providerId
- *
- * @return mixed
- * @throws QueryException
- */
- public static function isProviderIndexed($providerId) {
- $c = self::getContainer();
-
- return $c->query(ProviderService::class)
- ->isProviderIndexed($providerId);
-
- }
-} \ No newline at end of file
diff --git a/lib/AppInfo/Application.php b/lib/AppInfo/Application.php
index 1b81eec..76f89db 100644
--- a/lib/AppInfo/Application.php
+++ b/lib/AppInfo/Application.php
@@ -1,4 +1,7 @@
<?php
+declare(strict_types=1);
+
+
/**
* FullTextSearch - Full text search framework for Nextcloud
*
@@ -24,38 +27,59 @@
*
*/
+
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 {
+
const APP_NAME = 'fulltextsearch';
/** @var IAppContainer */
private $container;
+
/**
+ * Application constructor.
+ *
* @param array $params
*/
- public function __construct(array $params = array()) {
+ public function __construct(array $params = []) {
parent::__construct(self::APP_NAME, $params);
$this->container = $this->getContainer();
$this->container->registerCapability(Capabilities::class);
-
- $this->registerHooks();
}
/**
- * Register Hooks
+ * Register Navigation Tab
+ *
+ * @throws QueryException
*/
- public function registerHooks() {
+ 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);
}
@@ -65,7 +89,6 @@ class Application extends App {
* @throws QueryException
*/
public function registerNavigation() {
-
/** @var ConfigService $configService */
$configService = $this->container->query(ConfigService::class);
if ($configService->getAppValue(ConfigService::APP_NAVIGATION) !== '1') {
@@ -78,7 +101,10 @@ class Application extends App {
}
- private function fullTextSearchNavigation() {
+ /**
+ * @return array
+ */
+ private function fullTextSearchNavigation(): array {
$urlGen = \OC::$server->getURLGenerator();
$navName = \OC::$server->getL10N(self::APP_NAME)
->t('Full text search');
@@ -93,9 +119,5 @@ class Application extends App {
}
- public function registerSettingsAdmin() {
- // \OCP\App::registerAdmin(self::APP_NAME, 'lib/admin');
- }
-
}
diff --git a/lib/Capabilities.php b/lib/Capabilities.php
index dbfdd5e..d662ae8 100644
--- a/lib/Capabilities.php
+++ b/lib/Capabilities.php
@@ -1,4 +1,7 @@
<?php
+declare(strict_types=1);
+
+
/**
* FullTextSearch - Full text search framework for Nextcloud
*
@@ -24,8 +27,10 @@
*
*/
+
namespace OCA\FullTextSearch;
+
use Exception;
use OCA\FullTextSearch\Service\ProviderService;
use OCP\Capabilities\ICapability;
@@ -59,16 +64,18 @@ class Capabilities implements ICapability {
* Result to be expected:
* {"fulltextsearch":{"remote":true,"providers":[{"id":"files","name":"Files"}]}}
*
- * if 'remote' is false, it means administrator does not allow search request with no CSRF check.
+ * if 'remote' is false, it means administrator does not allow search request with no CSRF
+ * check.
*
* 'providers' will returns the list of provider configured for this user.
- * If a provider is not listed, no search will be available on it; so replace the 'files' search
+ * If a provider is not listed, no search will be available on it; so replace the 'files'
+ * search
* only if the 'files' provider is in the list
*
* @return array<string,array<string,boolean|array>>
* @throws Exception
*/
- public function getCapabilities() {
+ public function getCapabilities(): array {
$providers = $this->providerService->getConfiguredProviders();
diff --git a/lib/Command/Check.php b/lib/Command/Check.php
index 8b3aca1..8d7af2f 100644
--- a/lib/Command/Check.php
+++ b/lib/Command/Check.php
@@ -1,4 +1,7 @@
<?php
+declare(strict_types=1);
+
+
/**
* FullTextSearch - Full text search framework for Nextcloud
*
@@ -24,10 +27,12 @@
*
*/
+
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 +42,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;
@@ -88,7 +93,6 @@ class Check extends ExtendedBase {
* @param InputInterface $input
* @param OutputInterface $output
*
- * @return int|null|void
* @throws Exception
*/
protected function execute(InputInterface $input, OutputInterface $output) {
@@ -109,7 +113,10 @@ class Check extends ExtendedBase {
}
- private function displayAsJson() {
+ /**
+ * @return array
+ */
+ private function displayAsJson(): array {
$resultPlatform = [];
@@ -210,5 +217,3 @@ class Check extends ExtendedBase {
}
-
-
diff --git a/lib/Command/Configure.php b/lib/Command/Configure.php
index 7bc71b7..7b763db 100644
--- a/lib/Command/Configure.php
+++ b/lib/Command/Configure.php
@@ -1,4 +1,7 @@
<?php
+declare(strict_types=1);
+
+
/**
* FullTextSearch - Full text search framework for Nextcloud
*
@@ -24,10 +27,12 @@
*
*/
+
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 +40,12 @@ use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
-class Configure extends ExtendedBase {
+/**
+ * Class Configure
+ *
+ * @package OCA\FullTextSearch\Command
+ */
+class Configure extends Base {
/** @var ConfigService */
private $configService;
@@ -73,7 +83,6 @@ class Configure extends ExtendedBase {
* @param InputInterface $input
* @param OutputInterface $output
*
- * @return int|null|void
* @throws Exception
*/
protected function execute(InputInterface $input, OutputInterface $output) {
diff --git a/lib/Command/DocumentPlatform.php b/lib/Command/DocumentPlatform.php
index 72315e0..fc97d3f 100644
--- a/lib/Command/DocumentPlatform.php
+++ b/lib/Command/DocumentPlatform.php
@@ -1,4 +1,7 @@
<?php
+declare(strict_types=1);
+
+
/**
* FullTextSearch - Full text search framework for Nextcloud
*
@@ -24,10 +27,12 @@
*
*/
+
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 +41,7 @@ use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
-class DocumentPlatform extends ExtendedBase {
+class DocumentPlatform extends Base {
/** @var PlatformService */
@@ -77,7 +82,6 @@ class DocumentPlatform extends ExtendedBase {
* @param InputInterface $input
* @param OutputInterface $output
*
- * @return int|null|void
* @throws Exception
*/
protected function execute(InputInterface $input, OutputInterface $output) {
diff --git a/lib/Command/DocumentProvider.php b/lib/Command/DocumentProvider.php
index 583efc1..d975e0c 100644
--- a/lib/Command/DocumentProvider.php
+++ b/lib/Command/DocumentProvider.php
@@ -1,4 +1,7 @@
<?php
+declare(strict_types=1);
+
+
/**
* FullTextSearch - Full text search framework for Nextcloud
*
@@ -24,21 +27,28 @@
*
*/
+
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 OCA\FullTextSearch\Service\MiscService;
use OCA\FullTextSearch\Service\ProviderService;
+use OCP\FullTextSearch\Model\IndexDocument;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
-class DocumentProvider extends ExtendedBase {
+/**
+ * Class DocumentProvider
+ *
+ * @package OCA\FullTextSearch\Command
+ */
+class DocumentProvider extends Base {
/** @var ProviderService */
@@ -81,7 +91,6 @@ class DocumentProvider extends ExtendedBase {
* @param InputInterface $input
* @param OutputInterface $output
*
- * @return int|null|void
* @throws Exception
*/
protected function execute(InputInterface $input, OutputInterface $output) {
diff --git a/lib/Command/Index.php b/lib/Command/Index.php
index 570f041..9427ff5 100644
--- a/lib/Command/Index.php
+++ b/lib/Command/Index.php
@@ -1,4 +1,7 @@
<?php
+declare(strict_types=1);
+
+
/**
* FullTextSearch - Full text search framework for Nextcloud
*
@@ -24,12 +27,15 @@
*
*/
+
namespace OCA\FullTextSearch\Command;
+
+use daita\MySmallPhpTools\Traits\TArrayTools;
use Exception;
+use OC\Core\Command\InterruptedException;
+use OCA\FullTextSearch\ACommandBase;
use OCA\FullTextSearch\Exceptions\TickDoesNotExistException;
-use OCA\FullTextSearch\IFullTextSearchProvider;
-use OCA\FullTextSearch\Model\ExtendedBase;
use OCA\FullTextSearch\Model\Index as ModelIndex;
use OCA\FullTextSearch\Model\IndexOptions;
use OCA\FullTextSearch\Model\Runner;
@@ -39,7 +45,9 @@ 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 OutOfBoundsException;
use Symfony\Component\Console\Formatter\OutputFormatterStyle;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
@@ -49,7 +57,16 @@ use Symfony\Component\Console\Terminal;
use Throwable;
-class Index extends ExtendedBase {
+/**
+ * Class Index
+ *
+ * @package OCA\FullTextSearch\Command
+ */
+class Index extends ACommandBase {
+
+
+ use TArrayTools;
+
const INDEX_OPTION_NO_READLINE = '_no-readline';
@@ -185,16 +202,6 @@ class Index extends ExtendedBase {
/**
- * @throws Exception
- */
- public function interrupted() {
- if ($this->hasBeenInterrupted()) {
- throw new \Exception('ctrl-c');
- }
- }
-
-
- /**
* @param InputInterface $input
* @param OutputInterface $output
*
@@ -289,9 +296,9 @@ class Index extends ExtendedBase {
/**
- * @param $key
+ * @param string $key
*/
- public function onKeyPressed($key) {
+ public function onKeyPressed(string $key) {
$key = strtolower($key);
if ($key === 'q') {
try {
@@ -346,7 +353,7 @@ class Index extends ExtendedBase {
/**
* @param array $error
*/
- public function onNewIndexError($error) {
+ public function onNewIndexError(array $error) {
$this->errors[] = $error;
$this->displayError();
}
@@ -355,7 +362,7 @@ class Index extends ExtendedBase {
/**
* @param array $result
*/
- public function onNewIndexResult($result) {
+ public function onNewIndexResult(array $result) {
$this->results[] = $result;
$this->displayResult();
}
@@ -405,7 +412,6 @@ class Index extends ExtendedBase {
}
$this->providerService->setProviderAsIndexed($provider, true);
-
}
@@ -414,8 +420,13 @@ class Index extends ExtendedBase {
*
* @return IndexOptions
*/
- private function generateIndexOptions(InputInterface $input) {
+ private function generateIndexOptions(InputInterface $input): IndexOptions {
$jsonOptions = $input->getArgument('options');
+
+ if (!is_string($jsonOptions)) {
+ return new IndexOptions([]);
+ }
+
$options = json_decode($jsonOptions, true);
if (!is_array($options)) {
@@ -436,15 +447,14 @@ class Index extends ExtendedBase {
*
* @return bool
*/
- private function isIncludedProvider(IndexOptions $options, $providerId) {
+ private function isIncludedProvider(IndexOptions $options, string $providerId): bool {
if ($options->getOption('provider', '') !== ''
&& $options->getOption('provider') !== $providerId) {
return false;
}
- if ($options->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;
@@ -456,14 +466,13 @@ class Index extends ExtendedBase {
*
* @return array
*/
- private function generateUserList(IndexOptions $options) {
+ private function generateUserList(IndexOptions $options): array {
if ($options->getOption('user', '') !== '') {
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('');
@@ -557,6 +566,7 @@ class Index extends ExtendedBase {
}
}
+ // full list of info that can be edited
$this->runner->setInfoArray(
[
'userId' => '',
@@ -596,7 +606,7 @@ class Index extends ExtendedBase {
/**
* @param int $pos
*/
- private function displayError($pos = 0) {
+ private function displayError(int $pos = 0) {
$total = sizeof($this->errors);
if ($total === 0) {
@@ -610,11 +620,11 @@ class Index extends ExtendedBase {
return;
}
- $current = key($this->errors) + 1;
- $error = $this->getNavigationError($pos, ($current === 1), ($current === $total));
- $current = key($this->errors) + 1;
-
- if ($error === false) {
+ try {
+ $current = key($this->errors) + 1;
+ $error = $this->getNavigationError($pos, ($current === 1), ($current === $total));
+ $current = key($this->errors) + 1;
+ } catch (OutOfBoundsException $e) {
return;
}
@@ -626,10 +636,10 @@ class Index extends ExtendedBase {
}
$width = $this->terminal->getWidth() - 13;
- $message = MiscService::get('message', $error, '');
- $err1 = substr($message, 0, $width);
- $err2 = substr($message, $width, $width + 10);
- $err3 = substr($message, $width + $width + 10, $width + 10);
+ $message = $this->get('message', $error, '');
+ $err1 = (string)substr($message, 0, $width);
+ $err2 = (string)substr($message, $width, $width + 10);
+ $err3 = (string)substr($message, $width + $width + 10, $width + 10);
$this->runner->setInfoArray(
[
@@ -638,7 +648,7 @@ class Index extends ExtendedBase {
'errorMessageA' => trim($err1),
'errorMessageB' => trim($err2),
'errorMessageC' => trim($err3),
- 'errorException' => MiscService::get('exception', $error, ''),
+ 'errorException' => $this->get('exception', $error, ''),
'errorIndex' => $errorIndex
]
);
@@ -648,7 +658,7 @@ class Index extends ExtendedBase {
/**
* @param int $pos
*/
- private function displayResult($pos = 0) {
+ private function displayResult(int $pos = 0) {
$total = sizeof($this->results);
if ($total === 0) {
@@ -662,11 +672,11 @@ class Index extends ExtendedBase {
return;
}
- $current = key($this->results) + 1;
- $result = $this->getNavigationResult($pos, ($current === 1), ($current === $total));
- $current = key($this->results) + 1;
-
- if ($result === false) {
+ try {
+ $current = key($this->results) + 1;
+ $result = $this->getNavigationResult($pos, ($current === 1), ($current === $total));
+ $current = key($this->results) + 1;
+ } catch (OutOfBoundsException $e) {
return;
}
@@ -679,14 +689,13 @@ class Index extends ExtendedBase {
$width = $this->terminal->getWidth() - 13;
- $message = MiscService::get('message', $result, '');
- $msg1 = substr($message, 0, $width);
- $msg2 = substr($message, $width, $width + 10);
- $msg3 = substr($message, $width + $width + 10, $width + 10);
+ $message = $this->get('message', $result, '');
+ $msg1 = (string)substr($message, 0, $width);
+ $msg2 = (string)substr($message, $width, $width + 10);
+ $msg3 = (string)substr($message, $width + $width + 10, $width + 10);
-
- $status = MiscService::get('status', $result, '');
- $type = MiscService::get('type', $result, '');
+ $status = $this->get('status', $result, '');
+ $type = $this->getInt('type', $result, 0);
$this->runner->setInfoArray(
[
@@ -708,9 +717,10 @@ class Index extends ExtendedBase {
* @param bool $isFirst
* @param bool $isLast
*
- * @return bool|array
+ * @throw OutOfBoundsException
+ * @return array
*/
- private function getNavigationError($pos, $isFirst, $isLast) {
+ private function getNavigationError(int $pos, bool $isFirst, bool $isLast): array {
if ($pos === 0) {
if ($this->navigateLastError === true) {
@@ -739,7 +749,7 @@ class Index extends ExtendedBase {
return end($this->errors);
}
- return false;
+ throw new OutOfBoundsException();
}
@@ -748,9 +758,10 @@ class Index extends ExtendedBase {
* @param bool $isFirst
* @param bool $isLast
*
- * @return bool|array
+ * @throw OutOfBoundsException
+ * @return array
*/
- private function getNavigationResult($pos, $isFirst, $isLast) {
+ private function getNavigationResult(int $pos, bool $isFirst, bool $isLast): array {
if ($pos === 0) {
if ($this->navigateLastResult === true) {
@@ -779,7 +790,7 @@ class Index extends ExtendedBase {
return end($this->results);
}
- return false;
+ throw new OutOfBoundsException();
}
@@ -800,8 +811,6 @@ class Index extends ExtendedBase {
}
}
-
-
}
@@ -853,7 +862,19 @@ class Index extends ExtendedBase {
$this->displayError();
}
-}
+ /**
+ * @throws TickDoesNotExistException
+ */
+ public function abort() {
+ try {
+ $this->abortIfInterrupted();
+ } catch (InterruptedException $e) {
+ $this->runner->stop();
+ exit();
+ }
+ }
+}
+
diff --git a/lib/Command/Live.php b/lib/Command/Live.php
index 005b001..c5bfb3c 100644
--- a/lib/Command/Live.php
+++ b/lib/Command/Live.php
@@ -1,4 +1,7 @@
<?php
+declare(strict_types=1);
+
+
/**
* FullTextSearch - Full text search framework for Nextcloud
*
@@ -24,11 +27,15 @@
*
*/
+
namespace OCA\FullTextSearch\Command;
+
+use daita\MySmallPhpTools\Traits\TArrayTools;
use Exception;
+use OC\Core\Command\InterruptedException;
+use OCA\FullTextSearch\ACommandBase;
use OCA\FullTextSearch\Exceptions\TickDoesNotExistException;
-use OCA\FullTextSearch\Model\ExtendedBase;
use OCA\FullTextSearch\Model\Index as ModelIndex;
use OCA\FullTextSearch\Model\Runner;
use OCA\FullTextSearch\Service\CliService;
@@ -39,6 +46,7 @@ use OCA\FullTextSearch\Service\PlatformService;
use OCA\FullTextSearch\Service\ProviderService;
use OCA\FullTextSearch\Service\RunningService;
use OCP\IUserManager;
+use OutOfBoundsException;
use Symfony\Component\Console\Formatter\OutputFormatterStyle;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
@@ -47,7 +55,16 @@ use Symfony\Component\Console\Terminal;
use Throwable;
-class Live extends ExtendedBase {
+/**
+ * Class Live
+ *
+ * @package OCA\FullTextSearch\Command
+ */
+class Live extends ACommandBase {
+
+
+ use TArrayTools;
+
const INDEX_OPTION_NO_READLINE = '_no-readline';
@@ -290,9 +307,9 @@ class Live extends ExtendedBase {
/**
- * @param $key
+ * @param string $key
*/
- public function onKeyPressed($key) {
+ public function onKeyPressed(string $key) {
$key = strtolower($key);
if ($key === 'q') {
try {
@@ -347,7 +364,7 @@ class Live extends ExtendedBase {
/**
* @param array $error
*/
- public function onNewIndexError($error) {
+ public function onNewIndexError(array $error) {
$this->errors[] = $error;
$this->displayError();
}
@@ -355,7 +372,7 @@ class Live extends ExtendedBase {
/**
* @param array $result
*/
- public function onNewIndexResult($result) {
+ public function onNewIndexResult(array $result) {
$this->results[] = $result;
$this->displayResult();
}
@@ -503,7 +520,7 @@ class Live extends ExtendedBase {
/**
* @param int $pos
*/
- private function displayResult($pos = 0) {
+ private function displayResult(int $pos = 0) {
$total = sizeof($this->results);
if ($total === 0) {
@@ -517,11 +534,11 @@ class Live extends ExtendedBase {
return;
}
- $current = key($this->results) + 1;
- $result = $this->getNavigationResult($pos, ($current === 1), ($current === $total));
- $current = key($this->results) + 1;
-
- if ($result === false) {
+ try {
+ $current = key($this->results) + 1;
+ $result = $this->getNavigationResult($pos, ($current === 1), ($current === $total));
+ $current = key($this->results) + 1;
+ } catch (OutOfBoundsException $e) {
return;
}
@@ -534,14 +551,15 @@ class Live extends ExtendedBase {
$width = $this->terminal->getWidth() - 13;
- $message = MiscService::get('message', $result, '');
- $msg1 = substr($message, 0, $width);
- $msg2 = substr($message, $width, $width + 10);
- $msg3 = substr($message, $width + $width + 10, $width + 10);
+ $message = $this->get('message', $result, '');
+ $msg1 = (string)substr($message, 0, $width);
+ $msg2 = (string)substr($message, $width, $width + 10);
+ $msg3 = (string)substr($message, $width + $width + 10, $width + 10);
+
+ $status = $this->get('status', $result, '');
+ $type = $this->getInt('type', $result, 0);
- $status = MiscService::get('status', $result, '');
- $type = MiscService::get('type', $result, '');
$this->runner->setInfoArray(
[
@@ -560,7 +578,7 @@ class Live extends ExtendedBase {
/**
* @param int $pos
*/
- private function displayError($pos = 0) {
+ private function displayError(int $pos = 0) {
$total = sizeof($this->errors);
if ($total === 0) {
@@ -574,11 +592,11 @@ class Live extends ExtendedBase {
return;
}
- $current = key($this->errors) + 1;
- $error = $this->getNavigationError($pos, ($current === 1), ($current === $total));
- $current = key($this->errors) + 1;
-
- if ($error === false) {
+ try {
+ $current = key($this->errors) + 1;
+ $error = $this->getNavigationError($pos, ($current === 1), ($current === $total));
+ $current = key($this->errors) + 1;
+ } catch (OutOfBoundsException $e) {
return;
}
@@ -590,10 +608,10 @@ class Live extends ExtendedBase {
}
$width = $this->terminal->getWidth() - 13;
- $message = MiscService::get('message', $error, '');
- $err1 = substr($message, 0, $width);
- $err2 = substr($message, $width, $width + 10);
- $err3 = substr($message, $width + $width + 10, $width + 10);
+ $message = $this->get('message', $error, '');
+ $err1 = (string)substr($message, 0, $width);
+ $err2 = (string)substr($message, $width, $width + 10);
+ $err3 = (string)substr($message, $width + $width + 10, $width + 10);
$this->runner->setInfoArray(
[
@@ -602,7 +620,7 @@ class Live extends ExtendedBase {
'errorMessageA' => trim($err1),
'errorMessageB' => trim($err2),
'errorMessageC' => trim($err3),
- 'errorException' => MiscService::get('exception', $error, ''),
+ 'errorException' => $this->get('exception', $error, ''),
'errorIndex' => $errorIndex
]
);
@@ -614,9 +632,10 @@ class Live extends ExtendedBase {
* @param bool $isFirst
* @param bool $isLast
*
- * @return bool|array
+ * @return array
+ * @throws OutOfBoundsException
*/
- private function getNavigationResult($pos, $isFirst, $isLast) {
+ private function getNavigationResult(int $pos, bool $isFirst, bool $isLast): array {
if ($pos === 0) {
if ($this->navigateLastResult === true) {
@@ -645,7 +664,7 @@ class Live extends ExtendedBase {
return end($this->results);
}
- return false;
+ throw new OutOfBoundsException();
}
@@ -654,9 +673,9 @@ class Live extends ExtendedBase {
* @param bool $isFirst
* @param bool $isLast
*
- * @return bool|array
+ * @return array
*/
- private function getNavigationError($pos, $isFirst, $isLast) {
+ private function getNavigationError(int $pos, bool $isFirst, bool $isLast): array {
if ($pos === 0) {
if ($this->navigateLastError === true) {
@@ -685,7 +704,7 @@ class Live extends ExtendedBase {
return end($this->errors);
}
- return false;
+ throw new OutOfBoundsException();
}
@@ -736,7 +755,20 @@ class Live extends ExtendedBase {
$this->displayError();
}
-}
+ /**
+ * @throws TickDoesNotExistException
+ */
+ public function abort() {
+ try {
+ $this->abortIfInterrupted();
+ } catch (InterruptedException $e) {
+ $this->runner->stop();
+ exit();
+ }
+ }
+
+
+}
diff --git a/lib/Command/Reset.php b/lib/Command/Reset.php
index 2a7cee1..34f78b0 100644
--- a/lib/Command/Reset.php
+++ b/lib/Command/Reset.php
@@ -1,4 +1,7 @@
<?php
+declare(strict_types=1);
+
+
/**
* FullTextSearch - Full text search framework for Nextcloud
*
@@ -24,10 +27,14 @@
*
*/
+
namespace OCA\FullTextSearch\Command;
+
use Exception;
-use OCA\FullTextSearch\Model\ExtendedBase;
+use OC\Core\Command\InterruptedException;
+use OCA\FullTextSearch\ACommandBase;
+use OCA\FullTextSearch\Exceptions\TickDoesNotExistException;
use OCA\FullTextSearch\Model\Runner;
use OCA\FullTextSearch\Service\IndexService;
use OCA\FullTextSearch\Service\MiscService;
@@ -37,7 +44,13 @@ use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
-class Reset extends ExtendedBase {
+/**
+ * Class Reset
+ *
+ * @package OCA\FullTextSearch\Command
+ */
+class Reset extends ACommandBase {
+
/** @var IndexService */
private $indexService;
@@ -67,6 +80,9 @@ class Reset extends ExtendedBase {
}
+ /**
+ *
+ */
protected function configure() {
parent::configure();
$this->setName('fulltextsearch:reset')
@@ -79,7 +95,6 @@ class Reset extends ExtendedBase {
* @param InputInterface $input
* @param OutputInterface $output
*
- * @return int|null|void
* @throws Exception
*/
protected function execute(InputInterface $input, OutputInterface $output) {
@@ -111,7 +126,7 @@ class Reset extends ExtendedBase {
*
* @return string
*/
- private function getProviderIdFromArgument(InputInterface $input) {
+ private function getProviderIdFromArgument(InputInterface $input): string {
$providerId = $input->getArgument('provider');
if ($providerId === null) {
$providerId = '';
@@ -119,6 +134,20 @@ class Reset extends ExtendedBase {
return $providerId;
}
+
+
+ /**
+ * @throws TickDoesNotExistException
+ */
+ public function abort() {
+ try {
+ $this->abortIfInterrupted();
+ } catch (InterruptedException $e) {
+ $this->runner->stop();
+ exit();
+ }
+ }
+
}
diff --git a/lib/Command/Search.php b/lib/Command/Search.php
index b3eab78..0568e27 100644
--- a/lib/Command/Search.php
+++ b/lib/Command/Search.php
@@ -1,4 +1,7 @@
<?php
+declare(strict_types=1);
+
+
/**
* FullTextSearch - Full text search framework for Nextcloud
*
@@ -24,20 +27,28 @@
*
*/
+
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;
+/**
+ * Class Search
+ *
+ * @package OCA\FullTextSearch\Command
+ */
class Search extends Base {
/** @var SearchService */
@@ -63,6 +74,9 @@ class Search extends Base {
}
+ /**
+ *
+ */
protected function configure() {
parent::configure();
$this->setName('fulltextsearch:search')
@@ -74,16 +88,17 @@ class Search extends Base {
/**
+ *
* @param InputInterface $input
* @param OutputInterface $output
*
- * @return int|null|void
* @throws Exception
*/
protected function execute(InputInterface $input, OutputInterface $output) {
$output->writeln('search');
- $request = SearchRequest::fromArray(
+ $searchRequest = new SearchRequest();
+ $searchRequest->importFromArray(
[
'providers' => 'all',
'search' => $input->getArgument('string')
@@ -91,7 +106,7 @@ class Search extends Base {
);
try {
- $result = $this->searchService->search($input->getArgument('user'), $request);
+ $result = $this->searchService->search($input->getArgument('user'), $searchRequest);
foreach ($result as $searchResult) {
$this->displaySearchResult($searchResult);
@@ -103,8 +118,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..ac884f9 100644
--- a/lib/Command/Stop.php
+++ b/lib/Command/Stop.php
@@ -1,4 +1,7 @@
<?php
+declare(strict_types=1);
+
+
/**
* FullTextSearch - Full text search framework for Nextcloud
*
@@ -24,16 +27,24 @@
*
*/
+
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
+ *
+ * @package OCA\FullTextSearch\Command
+ */
+class Stop extends Base {
+
/** @var RunningService */
private $runningService;
@@ -56,6 +67,9 @@ class Stop extends ExtendedBase {
}
+ /**
+ *
+ */
protected function configure() {
parent::configure();
$this->setName('fulltextsearch:stop')
@@ -63,6 +77,10 @@ class Stop extends ExtendedBase {
}
+ /**
+ * @param InputInterface $input
+ * @param OutputInterface $output
+ */
protected function execute(InputInterface $input, OutputInterface $output) {
$output->writeln('stopping all running indexes');
diff --git a/lib/Command/Test.php b/lib/Command/Test.php
index f560b25..1ada38d 100644
--- a/lib/Command/Test.php
+++ b/lib/Command/Test.php
@@ -1,4 +1,7 @@
<?php
+declare(strict_types=1);
+
+
/**
* FullTextSearch - Full text search framework for Nextcloud
*
@@ -24,19 +27,19 @@
*
*/
+
namespace OCA\FullTextSearch\Command;
+
use Exception;
+use OC\Core\Command\InterruptedException;
+use OCA\FullTextSearch\ACommandBase;
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 +52,20 @@ 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
+ *
+ * @package OCA\FullTextSearch\Command
+ */
+class Test extends ACommandBase {
const DELAY_STABILIZE_PLATFORM = 3;
@@ -80,10 +91,10 @@ class Test extends ExtendedBase {
/** @var Runner */
private $runner;
-
/** @var boolean */
private $isJson = false;
+
/**
* Index constructor.
*
@@ -129,7 +140,6 @@ class Test extends ExtendedBase {
* @param InputInterface $input
* @param OutputInterface $output
*
- * @return int|null|void
* @throws Exception
*/
protected function execute(InputInterface $input, OutputInterface $output) {
@@ -146,7 +156,7 @@ class Test extends ExtendedBase {
$testPlatform = $this->testLoadingPlatform($output);
$this->testLockingProcess($output, $testPlatform, $testProvider);
} catch (Exception $e) {
- $this->output($output, false);
+ $this->outputResult($output, false);
throw $e;
}
@@ -158,7 +168,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);
@@ -167,10 +176,10 @@ class Test extends ExtendedBase {
$this->testResetTest($output, $testProvider);
$this->testUnlockingProcess($output);
} catch (Exception $e) {
- $this->output($output, false);
+ $this->outputResult($output, false);
$this->output($output, 'Error detected, unlocking process');
$this->runner->stop();
- $this->output($output, true);
+ $this->outputResult($output, true);
throw $e;
}
@@ -186,7 +195,7 @@ class Test extends ExtendedBase {
* @throws ProviderDoesNotExistException
* @throws ProviderIsNotUniqueException
*/
- private function generateMockProvider() {
+ private function generateMockProvider(): IFullTextSearchProvider {
$this->providerService->loadProvider(
'fulltextsearch', 'OCA\FullTextSearch\Provider\TestProvider'
);
@@ -198,11 +207,10 @@ class Test extends ExtendedBase {
/**
* @param OutputInterface $output
- * @param string|bool $line
+ * @param string $line
* @param bool $isNewLine
*/
- private function output(OutputInterface $output, $line, $isNewLine = true) {
- $line = $this->convertBoolToLine($line, $isNewLine);
+ private function output(OutputInterface $output, string $line, bool $isNewLine = true) {
if ($isNewLine) {
$output->write(' ', true);
}
@@ -212,18 +220,26 @@ class Test extends ExtendedBase {
/**
- * @param string|bool $line
- * @param $isNewLine
+ * @param OutputInterface $output
+ * @param bool $result
+ */
+ private function outputResult(OutputInterface $output, bool $result) {
+ $isNewLine = false;
+ $line = $this->convertBoolToLine($result, $isNewLine);
+
+ $this->output($output, $line, $isNewLine);
+ }
+
+
+ /**
+ * @param bool $result
+ * @param bool $isNewLine
*
* @return string
*/
- private function convertBoolToLine($line, &$isNewLine) {
- if (!is_bool($line)) {
- return $line;
- }
-
+ private function convertBoolToLine(bool $result, bool &$isNewLine): string {
$isNewLine = false;
- if ($line === false) {
+ if ($result === false) {
return '<error>fail</error>';
}
@@ -232,7 +248,7 @@ class Test extends ExtendedBase {
/**
- * @param $output
+ * @param OutputInterface $output
*
* @return IFullTextSearchProvider
* @throws ProviderDoesNotExistException
@@ -240,47 +256,50 @@ class Test extends ExtendedBase {
* @throws ProviderIsNotUniqueException
* @throws QueryException
*/
- private function testCreatingProvider($output) {
+ private function testCreatingProvider(OutputInterface $output): IFullTextSearchProvider {
$this->output($output, 'Creating mocked content provider.');
$testProvider = $this->generateMockProvider();
- $this->output($output, true);
+ $this->outputResult($output, true);
return $testProvider;
}
/**
- * @param $output
+ * @param OutputInterface $output
* @param IFullTextSearchProvider $testProvider
*/
- private function testMockedProvider($output, IFullTextSearchProvider $testProvider) {
+ private function testMockedProvider(
+ OutputInterface $output, IFullTextSearchProvider $testProvider
+ ) {
$this->output($output, 'Testing mocked provider: get indexable documents.');
+ $testProvider->setIndexOptions(new IndexOptions());
$indexableDocuments =
$testProvider->generateIndexableDocuments(TestService::DOCUMENT_USER1);
$this->output($output, '(' . sizeof($indexableDocuments) . ' items)', false);
- $this->output($output, true);
+ $this->outputResult($output, true);
}
/**
- * @param $output
+ * @param OutputInterface $output
*
* @return IFullTextSearchPlatform
* @throws Exception
*/
- private function testLoadingPlatform($output) {
+ private function testLoadingPlatform(OutputInterface $output): IFullTextSearchPlatform {
$this->output($output, 'Loading search platform.');
$wrapper = $this->platformService->getPlatform();
$testPlatform = $wrapper->getPlatform();
$this->output($output, '(' . $testPlatform->getName() . ')', false);
- $this->output($output, true);
+ $this->outputResult($output, true);
$this->output($output, 'Testing search platform.');
if (!$testPlatform->testPlatform()) {
throw new Exception ('Search platform (' . $testPlatform->getName() . ') down ?');
}
- $this->output($output, true);
+ $this->outputResult($output, true);
return $testPlatform;
}
@@ -298,11 +317,12 @@ class Test extends ExtendedBase {
) {
$this->output($output, 'Locking process');
$this->runner = new Runner($this->runningService, 'test');
+ $this->runner->sourceIsCommandLine($this, $output);
$this->runner->start();
$this->indexService->setRunner($this->runner);
$testPlatform->setRunner($this->runner);
$testProvider->setRunner($this->runner);
- $this->output($output, true);
+ $this->outputResult($output, true);
}
@@ -316,7 +336,7 @@ class Test extends ExtendedBase {
) {
$this->output($output, 'Removing test.');
$this->indexService->resetIndex($testProvider->getId());
- $this->output($output, true);
+ $this->outputResult($output, true);
}
@@ -328,7 +348,7 @@ class Test extends ExtendedBase {
) {
$this->output($output, 'Initializing index mapping.');
$testPlatform->initializeIndex();
- $this->output($output, true);
+ $this->outputResult($output, true);
}
@@ -337,8 +357,7 @@ class Test extends ExtendedBase {
* @param IFullTextSearchPlatform $testPlatform
* @param IFullTextSearchProvider $testProvider
*
- * @throws InterruptException
- * @throws TickDoesNotExistException
+ * @throws Exception
*/
private function testIndexingDocuments(
OutputInterface $output, IFullTextSearchPlatform $testPlatform,
@@ -353,7 +372,7 @@ class Test extends ExtendedBase {
$this->indexService->indexProviderContentFromUser(
$testPlatform, $testProvider, TestService::DOCUMENT_USER1, $options
);
- $this->output($output, true);
+ $this->outputResult($output, true);
}
@@ -376,7 +395,7 @@ class Test extends ExtendedBase {
$this->output(
$output, '(size: ' . $indexDocument->getContentSize() . ')', false
);
- $this->output($output, true);
+ $this->outputResult($output, true);
} catch (Exception $e) {
throw new Exception(
"Issue while getting test document '" . TestService::DOCUMENT_TYPE_LICENSE
@@ -386,16 +405,16 @@ 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);
+ $this->outputResult($output, true);
}
/**
* @param OutputInterface $output
* @param IFullTextSearchPlatform $testPlatform
- *
* @param IFullTextSearchProvider $testProvider
*
* @throws Exception
@@ -447,8 +466,7 @@ class Test extends ExtendedBase {
* @param IFullTextSearchPlatform $testPlatform
* @param IFullTextSearchProvider $testProvider
*
- * @throws InterruptException
- * @throws TickDoesNotExistException
+ * @throws Exception
*/
private function testUpdatingDocumentsAccess(
OutputInterface $output, IFullTextSearchPlatform $testPlatform,
@@ -465,14 +483,13 @@ class Test extends ExtendedBase {
$this->indexService->indexProviderContentFromUser(
$testPlatform, $testProvider, TestService::DOCUMENT_USER1, $options
);
- $this->output($output, true);
+ $this->outputResult($output, true);
}
/**
* @param OutputInterface $output
* @param IFullTextSearchPlatform $platform
- *
* @param IFullTextSearchProvider $provider
*
* @throws Exception
@@ -481,7 +498,6 @@ class Test extends ExtendedBase {
OutputInterface $output, IFullTextSearchPlatform $platform,
IFullTextSearchProvider $provider
) {
-
$this->output($output, 'Searching with group access rights:');
$this->searchGroups($output, $platform, $provider, [], []);
@@ -506,7 +522,6 @@ class Test extends ExtendedBase {
/**
* @param OutputInterface $output
* @param IFullTextSearchPlatform $platform
- *
* @param IFullTextSearchProvider $provider
*
* @throws Exception
@@ -532,7 +547,7 @@ class Test extends ExtendedBase {
private function testUnlockingProcess(OutputInterface $output) {
$this->output($output, 'Unlocking process');
$this->runner->stop();
- $this->output($output, true);
+ $this->outputResult($output, true);
}
@@ -550,7 +565,7 @@ class Test extends ExtendedBase {
private function search(
OutputInterface $output, IFullTextSearchPlatform $testPlatform,
IFullTextSearchProvider $testProvider,
- DocumentAccess $access, $search, $expected, $moreOutput = ''
+ DocumentAccess $access, string $search, array $expected, string $moreOutput = ''
) {
$this->output(
$output,
@@ -572,7 +587,7 @@ class Test extends ExtendedBase {
false
);
$this->compareSearchResult($searchResult, $expected);
- $this->output($output, true);
+ $this->outputResult($output, true);
}
@@ -587,7 +602,7 @@ class Test extends ExtendedBase {
*/
private function searchGroups(
OutputInterface $output, IFullTextSearchPlatform $testPlatform,
- IFullTextSearchProvider $testProvider, $groups, $expected
+ IFullTextSearchProvider $testProvider, array $groups, array $expected
) {
$access = new DocumentAccess();
@@ -612,7 +627,7 @@ class Test extends ExtendedBase {
*/
private function searchUsers(
OutputInterface $output, IFullTextSearchPlatform $testPlatform,
- IFullTextSearchProvider $testProvider, $user, $expected
+ IFullTextSearchProvider $testProvider, string $user, array $expected
) {
$access = new DocumentAccess();
$access->setViewerId($user);
@@ -625,11 +640,11 @@ class Test extends ExtendedBase {
/**
* @param SearchResult $searchResult
- * @param $entries
+ * @param array $entries
*
* @throws Exception
*/
- private function compareSearchResult(SearchResult $searchResult, $entries) {
+ private function compareSearchResult(SearchResult $searchResult, array $entries) {
$documents = $searchResult->getDocuments();
if (sizeof($documents) !== sizeof($entries)) {
throw new \Exception('Unexpected SearchResult: ' . json_encode($searchResult));
@@ -649,7 +664,7 @@ class Test extends ExtendedBase {
*
* @throws InterruptException
*/
- private function pause(OutputInterface $output, $s) {
+ private function pause(OutputInterface $output, int $s) {
$this->output($output, 'Pausing ' . $s . ' seconds');
for ($i = 1; $i <= $s; $i++) {
@@ -657,10 +672,23 @@ class Test extends ExtendedBase {
throw new InterruptException('Interrupted by user');
}
- $this->output($output, $i, false);
+ $this->output($output, (string)$i, false);
}
- $this->output($output, true);
+ $this->outputResult($output, true);
+ }
+
+
+ /**
+ * @throws TickDoesNotExistException
+ */
+ public function abort() {
+ try {
+ $this->abortIfInterrupted();
+ } catch (InterruptedException $e) {
+ $this->runner->stop();
+ exit();
+ }
}
}
diff --git a/lib/Controller/ApiController.php b/lib/Controller/ApiController.php
index e5a2ca5..2b3ff55 100644
--- a/lib/Controller/ApiController.php
+++ b/lib/Controller/ApiController.php
@@ -1,4 +1,7 @@
<?php
+declare(strict_types=1);
+
+
/**
* FullTextSearch - Full text search framework for Nextcloud
*
@@ -24,8 +27,11 @@
*
*/
+
namespace OCA\FullTextSearch\Controller;
+
+use daita\MySmallPhpTools\Traits\TNCDataResponse;
use Exception;
use OCA\FullTextSearch\AppInfo\Application;
use OCA\FullTextSearch\Model\SearchRequest;
@@ -33,12 +39,21 @@ use OCA\FullTextSearch\Service\ConfigService;
use OCA\FullTextSearch\Service\MiscService;
use OCA\FullTextSearch\Service\SearchService;
use OCP\AppFramework\Controller;
-use OCP\AppFramework\Http;
use OCP\AppFramework\Http\DataResponse;
use OCP\IRequest;
+
+/**
+ * Class ApiController
+ *
+ * @package OCA\FullTextSearch\Controller
+ */
class ApiController extends Controller {
+
+ use TNCDataResponse;
+
+
/** @var SearchService */
private $searchService;
@@ -76,7 +91,7 @@ class ApiController extends Controller {
*
* @return DataResponse
*/
- public function search($request) {
+ public function search(string $request): DataResponse {
return $this->searchDocuments(SearchRequest::fromJSON($request));
}
@@ -90,7 +105,7 @@ class ApiController extends Controller {
*
* @return DataResponse
*/
- public function searchFromRemote($request) {
+ public function searchFromRemote(string $request): DataResponse {
return $this->searchDocuments(SearchRequest::fromJSON($request));
}
@@ -100,54 +115,27 @@ class ApiController extends Controller {
*
* @return DataResponse
*/
- private function searchDocuments(SearchRequest $request) {
+ private function searchDocuments(SearchRequest $request): DataResponse {
try {
- $result = $this->searchService->search(null, $request);
+ $result = $this->searchService->search('', $request);
return $this->success(
+ $result,
[
'request' => $request,
- 'result' => $result,
'version' => $this->configService->getAppValue('installed_version')
]
);
} catch (Exception $e) {
return $this->fail(
+ $e->getMessage(),
[
'request' => $request,
- 'error' => $e->getMessage(),
'version' => $this->configService->getAppValue('installed_version')
]
);
}
}
+}
- /**
- * @param $data
- *
- * @return DataResponse
- */
- protected function fail($data) {
- $this->miscService->log(json_encode($data));
-
- return new DataResponse(
- array_merge($data, array('status' => 0)),
- Http::STATUS_NON_AUTHORATIVE_INFORMATION
- );
- }
-
-
- /**
- * @param $data
- *
- * @return DataResponse
- */
- protected function success($data) {
- return new DataResponse(
- array_merge($data, array('status' => 1)),
- Http::STATUS_CREATED
- );
- }
-
-} \ No newline at end of file
diff --git a/lib/Controller/NavigationController.php b/lib/Controller/NavigationController.php
index d18e600..1fbf705 100644
--- a/lib/Controller/NavigationController.php
+++ b/lib/Controller/NavigationController.php
@@ -1,4 +1,7 @@
<?php
+declare(strict_types=1);
+
+
/**
* FullTextSearch - Full text search framework for Nextcloud
*
@@ -24,21 +27,34 @@
*
*/
+
namespace OCA\FullTextSearch\Controller;
+
use OCA\FullTextSearch\AppInfo\Application;
use OCA\FullTextSearch\Service\ConfigService;
use OCA\FullTextSearch\Service\MiscService;
use OCP\AppFramework\Controller;
use OCP\AppFramework\Http\TemplateResponse;
+use OCP\FullTextSearch\IFullTextSearchManager;
use OCP\IConfig;
use OCP\IRequest;
+
+/**
+ * Class NavigationController
+ *
+ * @package OCA\FullTextSearch\Controller
+ */
class NavigationController extends Controller {
+
/** @var IConfig */
private $config;
+ /** @var IFullTextSearchManager */
+ private $fullTextSearchManager;
+
/** @var ConfigService */
private $configService;
@@ -51,14 +67,17 @@ class NavigationController extends Controller {
*
* @param IRequest $request
* @param IConfig $config
+ * @param IFullTextSearchManager $fullTextSearchManager
* @param ConfigService $configService
* @param MiscService $miscService
*/
public function __construct(
- IRequest $request, IConfig $config, ConfigService $configService, MiscService $miscService
+ IRequest $request, IConfig $config, IFullTextSearchManager $fullTextSearchManager,
+ ConfigService $configService, MiscService $miscService
) {
parent::__construct(Application::APP_NAME, $request);
$this->config = $config;
+ $this->fullTextSearchManager = $fullTextSearchManager;
$this->configService = $configService;
$this->miscService = $miscService;
}
@@ -71,14 +90,18 @@ class NavigationController extends Controller {
*
* @return TemplateResponse
*/
- public function navigate() {
+ public function navigate(): TemplateResponse {
$themingName = $this->config->getAppValue('theming', 'name', 'Nextcloud');
- $data = ['themingName' => $themingName];
+ $data = [
+ 'themingName' => $themingName
+ ];
+
+ $this->fullTextSearchManager->addJavascriptAPI();
return new TemplateResponse(Application::APP_NAME, 'navigate', $data);
}
-} \ No newline at end of file
+}
diff --git a/lib/Controller/SettingsController.php b/lib/Controller/SettingsController.php
index 52e6b72..ea5c1bf 100644
--- a/lib/Controller/SettingsController.php
+++ b/lib/Controller/SettingsController.php
@@ -1,4 +1,7 @@
<?php
+declare(strict_types=1);
+
+
/**
* FullTextSearch - Full text search framework for Nextcloud
*
@@ -24,8 +27,10 @@
*
*/
+
namespace OCA\FullTextSearch\Controller;
+
use Exception;
use OCA\FullTextSearch\AppInfo\Application;
use OCA\FullTextSearch\Service\ConfigService;
@@ -36,6 +41,12 @@ use OCP\AppFramework\Http;
use OCP\AppFramework\Http\DataResponse;
use OCP\IRequest;
+
+/**
+ * Class SettingsController
+ *
+ * @package OCA\FullTextSearch\Controller
+ */
class SettingsController extends Controller {
/** @var ConfigService */
@@ -71,7 +82,7 @@ class SettingsController extends Controller {
* @return DataResponse
* @throws Exception
*/
- public function getSettingsAdmin() {
+ public function getSettingsAdmin(): DataResponse {
$data = $this->configService->getConfig();
$this->settingsService->completeSettings($data);
@@ -93,4 +104,4 @@ class SettingsController extends Controller {
return $this->getSettingsAdmin();
}
-} \ No newline at end of file
+}
diff --git a/lib/Controller/TemplatesController.php b/lib/Controller/TemplatesController.php
index 9aea5c7..9157742 100644
--- a/lib/Controller/TemplatesController.php
+++ b/lib/Controller/TemplatesController.php
@@ -1,4 +1,7 @@
<?php
+declare(strict_types=1);
+
+
/**
* FullTextSearch - Full text search framework for Nextcloud
*
@@ -24,13 +27,14 @@
*
*/
+
namespace OCA\FullTextSearch\Controller;
+
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;
@@ -40,8 +44,15 @@ use OCP\AppFramework\Http\TemplateResponse;
use OCP\IConfig;
use OCP\IRequest;
+
+/**
+ * Class TemplatesController
+ *
+ * @package OCA\FullTextSearch\Controller
+ */
class TemplatesController extends Controller {
+
/** @var IConfig */
private $config;
@@ -80,29 +91,32 @@ class TemplatesController extends Controller {
* @NoAdminRequired
* @NoSubAdminRequired
*
- * @param $providerId
+ * @param string $providerId
*
* @return DataResponse
* @throws Exception
* @throws ProviderDoesNotExistException
*/
- public function getOptionsPanel($providerId) {
+ public function getOptionsPanel(string $providerId): DataResponse {
$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);
}
@@ -115,7 +129,7 @@ class TemplatesController extends Controller {
* @return DataResponse
* @throws Exception
*/
- public function getNavigationPanels() {
+ public function getNavigationPanels(): DataResponse {
$providers = $this->providerService->getProviders();
$ret = [];
@@ -123,17 +137,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..3614246 100644
--- a/lib/Cron/Index.php
+++ b/lib/Cron/Index.php
@@ -1,4 +1,6 @@
<?php
+declare(strict_types=1);
+
/**
* FullTextSearch - Full text search framework for Nextcloud
@@ -25,12 +27,13 @@
*
*/
+
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;
@@ -74,7 +77,7 @@ class Index extends TimedJob {
/**
- * @param $argument
+ * @param mixed $argument
*
* @throws QueryException
*/
@@ -105,7 +108,6 @@ class Index extends TimedJob {
/**
* @throws Exception
- * @throws InterruptException
*/
private function liveCycle() {
@@ -139,7 +141,7 @@ class Index extends TimedJob {
/**
* @return bool
*/
- private function shouldWeGetAllIndex() {
+ private function shouldWeGetAllIndex(): bool {
$lastErrReset = (int)$this->configService->getAppValue(ConfigService::CRON_LAST_ERR_RESET);
if ($lastErrReset === 0) {
@@ -161,6 +163,6 @@ class Index extends TimedJob {
*
*/
private function setLastErrReset() {
- $this->configService->setAppValue(ConfigService::CRON_LAST_ERR_RESET, time());
+ $this->configService->setAppValue(ConfigService::CRON_LAST_ERR_RESET, (string) time());
}
}
diff --git a/lib/Db/CoreRequestBuilder.php b/lib/Db/CoreRequestBuilder.php
index d1223e4..d90054c 100644
--- a/lib/Db/CoreRequestBuilder.php
+++ b/lib/Db/CoreRequestBuilder.php
@@ -1,4 +1,7 @@
<?php
+declare(strict_types=1);
+
+
/**
* FullTextSearch - Full text search framework for Nextcloud
*
@@ -24,6 +27,7 @@
*
*/
+
namespace OCA\FullTextSearch\Db;
@@ -35,6 +39,12 @@ use OCP\DB\QueryBuilder\IQueryBuilder;
use OCP\IDBConnection;
use OCP\IL10N;
+
+/**
+ * Class CoreRequestBuilder
+ *
+ * @package OCA\FullTextSearch\Db
+ */
class CoreRequestBuilder {
const TABLE_INDEXES = 'fulltextsearch_indexes';
@@ -81,8 +91,8 @@ class CoreRequestBuilder {
* @param IQueryBuilder $qb
* @param int $id
*/
- protected function limitToId(IQueryBuilder &$qb, $id) {
- $this->limitToDBField($qb, 'id', $id);
+ protected function limitToId(IQueryBuilder &$qb, int $id) {
+ $this->limitToDBFieldInt($qb, 'id', $id);
}
@@ -92,18 +102,18 @@ class CoreRequestBuilder {
* @param IQueryBuilder $qb
* @param string $userId
*/
- protected function limitToOwnerId(IQueryBuilder &$qb, $userId) {
+ protected function limitToOwnerId(IQueryBuilder &$qb, string $userId) {
$this->limitToDBField($qb, 'owner_id', $userId);
}
/**
- * Limit to the type
+ * Limit to the providerId
*
* @param IQueryBuilder $qb
* @param string $providerId
*/
- protected function limitToProviderId(IQueryBuilder &$qb, $providerId) {
+ protected function limitToProviderId(IQueryBuilder &$qb, string $providerId) {
$this->limitToDBField($qb, 'provider_id', $providerId);
}
@@ -114,13 +124,13 @@ class CoreRequestBuilder {
* @param IQueryBuilder $qb
* @param string $documentId
*/
- protected function limitToDocumentId(IQueryBuilder &$qb, $documentId) {
+ protected function limitToDocumentId(IQueryBuilder &$qb, string $documentId) {
$this->limitToDBField($qb, 'document_id', $documentId);
}
/**
- * Limit to the documentId
+ * Limit to the entry with at least one Error
*
* @param IQueryBuilder $qb
*/
@@ -131,7 +141,7 @@ class CoreRequestBuilder {
/**
- * Limit to the documentId
+ * Limit to the entry with no error
*
* @param IQueryBuilder $qb
*/
@@ -147,29 +157,29 @@ class CoreRequestBuilder {
* @param IQueryBuilder $qb
* @param array $documentIds
*/
- protected function limitToDocumentIds(IQueryBuilder &$qb, $documentIds) {
- $this->limitToDBField($qb, 'document_id', $documentIds);
+ protected function limitToDocumentIds(IQueryBuilder &$qb, array $documentIds) {
+ $this->limitToDBFieldArray($qb, 'document_id', $documentIds);
}
/**
- * Limit the request to the Source
+ * Limit the request to source
*
* @param IQueryBuilder $qb
* @param string $source
*/
- protected function limitToSource(IQueryBuilder &$qb, $source) {
+ protected function limitToSource(IQueryBuilder &$qb, string $source) {
$this->limitToDBField($qb, 'id', $source);
}
/**
- * Limit the request to the Source
+ * Limit the request to status
*
* @param IQueryBuilder $qb
* @param string $status
*/
- protected function limitToStatus(IQueryBuilder &$qb, $status) {
+ protected function limitToStatus(IQueryBuilder &$qb, string $status) {
$this->limitToDBField($qb, 'status', $status);
}
@@ -177,9 +187,36 @@ class CoreRequestBuilder {
/**
* @param IQueryBuilder $qb
* @param string $field
+ * @param string $value
+ */
+ private function limitToDBField(IQueryBuilder &$qb, string $field, string $value) {
+ $expr = $qb->expr();
+ $pf = ($qb->getType() === QueryBuilder::SELECT) ? $this->defaultSelectAlias . '.' : '';
+ $field = $pf . $field;
+
+ $qb->andWhere($expr->eq($field, $qb->createNamedParameter($value)));
+ }
+
+ /**
+ * @param IQueryBuilder $qb
+ * @param string $field
+ * @param int $value
+ */
+ private function limitToDBFieldInt(IQueryBuilder &$qb, string $field, int $value) {
+ $expr = $qb->expr();
+ $pf = ($qb->getType() === QueryBuilder::SELECT) ? $this->defaultSelectAlias . '.' : '';
+ $field = $pf . $field;
+
+ $qb->andWhere($expr->eq($field, $qb->createNamedParameter($value)));
+ }
+
+
+ /**
+ * @param IQueryBuilder $qb
+ * @param string $field
* @param string|integer|array $values
*/
- private function limitToDBField(IQueryBuilder &$qb, $field, $values) {
+ private function limitToDBFieldArray(IQueryBuilder &$qb, string $field, array $values) {
$expr = $qb->expr();
$pf = ($qb->getType() === QueryBuilder::SELECT) ? $this->defaultSelectAlias . '.' : '';
$field = $pf . $field;
diff --git a/lib/Db/IndexesRequest.php b/lib/Db/IndexesRequest.php
index edb7eac..4b5b45f 100644
--- a/lib/Db/IndexesRequest.php
+++ b/lib/Db/IndexesRequest.php
@@ -1,4 +1,7 @@
<?php
+declare(strict_types=1);
+
+
/**
* FullTextSearch - Full text search framework for Nextcloud
*
@@ -24,14 +27,20 @@
*
*/
+
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\Model\IIndex;
+
+/**
+ * Class IndexesRequest
+ *
+ * @package OCA\FullTextSearch\Db
+ */
class IndexesRequest extends IndexesRequestBuilder {
@@ -41,7 +50,7 @@ class IndexesRequest extends IndexesRequestBuilder {
* @return bool
* @throws \Exception
*/
- public function create(Index $index) {
+ public function create(Index $index): bool {
try {
$qb = $this->getIndexesInsertSql();
@@ -69,7 +78,7 @@ class IndexesRequest extends IndexesRequestBuilder {
*
* @return bool
*/
- public function resetError(Index $index) {
+ public function resetError(Index $index): bool {
try {
$this->getIndex($index->getProviderId(), $index->getDocumentId());
@@ -103,9 +112,9 @@ class IndexesRequest extends IndexesRequestBuilder {
/**
- * @return ExtendedIndex[]
+ * @return Index[]
*/
- public function getErrorIndexes() {
+ public function getErrorIndexes(): array {
$qb = $this->getIndexesSelectSql();
$this->limitToErr($qb);
@@ -126,7 +135,7 @@ class IndexesRequest extends IndexesRequestBuilder {
*
* @return bool
*/
- public function update(Index $index) {
+ public function update(Index $index): bool {
try {
$this->getIndex($index->getProviderId(), $index->getDocumentId());
@@ -159,21 +168,41 @@ class IndexesRequest extends IndexesRequestBuilder {
}
- public function updateStatus($providerId, $indexes, $status) {
+ /**
+ * @param string $providerId
+ * @param string $documentId
+ * @param int $status
+ */
+ public function updateStatus(string $providerId, string $documentId, int $status) {
$qb = $this->getIndexesUpdateSql();
$qb->set('status', $qb->createNamedParameter($status));
$this->limitToProviderId($qb, $providerId);
- $this->limitToDocumentId($qb, $indexes);
+ $this->limitToDocumentId($qb, $documentId);
+
+ $qb->execute();
+ }
+
+ /**
+ * @param string $providerId
+ * @param array $indexes
+ * @param int $status
+ */
+ public function updateStatuses(string $providerId, array $indexes, int $status) {
+ $qb = $this->getIndexesUpdateSql();
+ $qb->set('status', $qb->createNamedParameter($status));
+
+ $this->limitToProviderId($qb, $providerId);
+ $this->limitToDocumentIds($qb, $indexes);
$qb->execute();
}
/**
- * @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());
@@ -185,7 +214,7 @@ class IndexesRequest extends IndexesRequestBuilder {
/**
* @param string $providerId
*/
- public function deleteFromProviderId($providerId) {
+ public function deleteFromProviderId(string $providerId) {
$qb = $this->getIndexesDeleteSql();
$this->limitToProviderId($qb, $providerId);
@@ -207,12 +236,12 @@ class IndexesRequest extends IndexesRequestBuilder {
* return index.
*
* @param string $providerId
- * @param string|int $documentId
+ * @param string $documentId
*
- * @return ExtendedIndex
+ * @return Index
* @throws IndexDoesNotExistException
*/
- public function getIndex($providerId, $documentId) {
+ public function getIndex(string $providerId, string $documentId): Index {
$qb = $this->getIndexesSelectSql();
$this->limitToProviderId($qb, $providerId);
$this->limitToDocumentId($qb, $documentId);
@@ -235,10 +264,10 @@ class IndexesRequest extends IndexesRequestBuilder {
* @param string $providerId
* @param array $documentIds
*
- * @return ExtendedIndex[]
+ * @return Index[]
* @throws IndexDoesNotExistException
*/
- public function getIndexes($providerId, $documentIds) {
+ public function getIndexes(string $providerId, array $documentIds): array {
$qb = $this->getIndexesSelectSql();
$this->limitToProviderId($qb, $providerId);
$this->limitToDocumentIds($qb, $documentIds);
@@ -263,7 +292,7 @@ class IndexesRequest extends IndexesRequestBuilder {
*
* @return Index[]
*/
- public function getQueuedIndexes($all = false) {
+ public function getQueuedIndexes(bool $all = false): array {
$qb = $this->getIndexesSelectSql();
$this->limitToQueuedIndexes($qb);
if ($all === false) {
@@ -284,13 +313,13 @@ class IndexesRequest extends IndexesRequestBuilder {
/**
* return list of last indexes from a providerId.
*
- * @param IFullTextSearchProvider $provider
+ * @param string $providerId
*
* @return Index[]
*/
- public function getIndexesFromProvider(IFullTextSearchProvider $provider) {
+ public function getIndexesFromProvider(string $providerId): array {
$qb = $this->getIndexesSelectSql();
- $this->limitToProviderId($qb, $provider->getId());
+ $this->limitToProviderId($qb, $providerId);
$indexes = [];
$cursor = $qb->execute();
@@ -303,4 +332,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..b76230d 100644
--- a/lib/Db/IndexesRequestBuilder.php
+++ b/lib/Db/IndexesRequestBuilder.php
@@ -1,4 +1,7 @@
<?php
+declare(strict_types=1);
+
+
/**
* FullTextSearch - Full text search framework for Nextcloud
*
@@ -24,30 +27,20 @@
*
*/
+
namespace OCA\FullTextSearch\Db;
-use OCA\FullTextSearch\Model\ExtendedIndex;
-use OCA\FullTextSearch\Service\ConfigService;
-use OCA\FullTextSearch\Service\MiscService;
+use OCA\FullTextSearch\Model\Index;
use OCP\DB\QueryBuilder\IQueryBuilder;
-use OCP\IDBConnection;
-use OCP\IL10N;
-class IndexesRequestBuilder extends CoreRequestBuilder {
-
- /**
- * WebsitesRequestBuilder constructor.
- *
- * {@inheritdoc}
- */
- public function __construct(
- IL10N $l10n, IDBConnection $connection, ConfigService $configService,
- MiscService $miscService
- ) {
- parent::__construct($l10n, $connection, $configService, $miscService);
- }
+/**
+ * Class IndexesRequestBuilder
+ *
+ * @package OCA\FullTextSearch\Db
+ */
+class IndexesRequestBuilder extends CoreRequestBuilder {
/**
@@ -55,7 +48,7 @@ class IndexesRequestBuilder extends CoreRequestBuilder {
*
* @return IQueryBuilder
*/
- protected function getIndexesInsertSql() {
+ protected function getIndexesInsertSql(): IQueryBuilder {
$qb = $this->dbConnection->getQueryBuilder();
$qb->insert(self::TABLE_INDEXES);
@@ -68,7 +61,7 @@ class IndexesRequestBuilder extends CoreRequestBuilder {
*
* @return IQueryBuilder
*/
- protected function getIndexesUpdateSql() {
+ protected function getIndexesUpdateSql(): IQueryBuilder {
$qb = $this->dbConnection->getQueryBuilder();
$qb->update(self::TABLE_INDEXES);
@@ -81,7 +74,7 @@ class IndexesRequestBuilder extends CoreRequestBuilder {
*
* @return IQueryBuilder
*/
- protected function getIndexesSelectSql() {
+ protected function getIndexesSelectSql(): IQueryBuilder {
$qb = $this->dbConnection->getQueryBuilder();
/** @noinspection PhpMethodParametersCountMismatchInspection */
@@ -102,7 +95,7 @@ class IndexesRequestBuilder extends CoreRequestBuilder {
*
* @return IQueryBuilder
*/
- protected function getIndexesDeleteSql() {
+ protected function getIndexesDeleteSql(): IQueryBuilder {
$qb = $this->dbConnection->getQueryBuilder();
$qb->delete(self::TABLE_INDEXES);
@@ -113,19 +106,20 @@ 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->setStatus($data['status'])
+ protected function parseIndexesSelectSql(array $data): Index {
+ $index = new Index($data['provider_id'], $data['document_id']);
+ $index->setStatus((int)$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']);
+ ->setLastIndex((int)$data['indexed']);
+ $index->setOptions(json_decode($data['options'], true));
+ $index->setErrorCount((int)$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..6e50678 100644
--- a/lib/Db/TickRequest.php
+++ b/lib/Db/TickRequest.php
@@ -1,4 +1,7 @@
<?php
+declare(strict_types=1);
+
+
/**
* FullTextSearch - Full text search framework for Nextcloud
*
@@ -24,13 +27,19 @@
*
*/
+
namespace OCA\FullTextSearch\Db;
use OCA\FullTextSearch\Exceptions\TickDoesNotExistException;
-use OCA\FullTextSearch\Model\ExtendedTick;
use OCA\FullTextSearch\Model\Tick;
+
+/**
+ * Class TickRequest
+ *
+ * @package OCA\FullTextSearch\Db
+ */
class TickRequest extends TickRequestBuilder {
@@ -40,7 +49,7 @@ class TickRequest extends TickRequestBuilder {
* @return int
* @throws \Exception
*/
- public function create(Tick $tick) {
+ public function create(Tick $tick): int {
try {
$qb = $this->getTickInsertSql();
@@ -65,7 +74,7 @@ class TickRequest extends TickRequestBuilder {
*
* @return bool
*/
- public function update(Tick $tick) {
+ public function update(Tick $tick): bool {
try {
$this->getTickById($tick->getId());
@@ -114,10 +123,10 @@ class TickRequest extends TickRequestBuilder {
*
* @param int $id
*
- * @return ExtendedTick
+ * @return Tick
* @throws TickDoesNotExistException
*/
- public function getTickById($id) {
+ public function getTickById(int $id): Tick {
$qb = $this->getTickSelectSql();
$this->limitToId($qb, $id);
@@ -134,13 +143,13 @@ class TickRequest extends TickRequestBuilder {
/**
- * return tick.
+ * return ticks.
*
* @param string $status
*
- * @return ExtendedTick[]
+ * @return Tick[]
*/
- public function getTickByStatus($status) {
+ public function getTicksByStatus(string $status): array {
$ticks = [];
@@ -160,9 +169,9 @@ class TickRequest extends TickRequestBuilder {
/**
* @param string $source
*
- * @return ExtendedTick[]
+ * @return Tick[]
*/
- public function getTickBySource($source) {
+ public function getTicksBySource(string $source): array {
$qb = $this->getTickSelectSql();
$this->limitToSource($qb, $source);
@@ -177,4 +186,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..a90aede 100644
--- a/lib/Db/TickRequestBuilder.php
+++ b/lib/Db/TickRequestBuilder.php
@@ -1,4 +1,7 @@
<?php
+declare(strict_types=1);
+
+
/**
* FullTextSearch - Full text search framework for Nextcloud
*
@@ -24,29 +27,20 @@
*
*/
+
namespace OCA\FullTextSearch\Db;
-use OCA\FullTextSearch\Model\ExtendedTick;
-use OCA\FullTextSearch\Service\ConfigService;
-use OCA\FullTextSearch\Service\MiscService;
+use OCA\FullTextSearch\Model\Tick;
use OCP\DB\QueryBuilder\IQueryBuilder;
-use OCP\IDBConnection;
-use OCP\IL10N;
-class TickRequestBuilder extends CoreRequestBuilder {
-
- /**
- * TicksRequestBuilder constructor.
- *
- * {@inheritdoc}
- */
- public function __construct(
- IL10N $l10n, IDBConnection $connection, ConfigService $configService, MiscService $miscService
- ) {
- parent::__construct($l10n, $connection, $configService, $miscService);
- }
+/**
+ * Class TickRequestBuilder
+ *
+ * @package OCA\FullTextSearch\Db
+ */
+class TickRequestBuilder extends CoreRequestBuilder {
/**
@@ -54,7 +48,7 @@ class TickRequestBuilder extends CoreRequestBuilder {
*
* @return IQueryBuilder
*/
- protected function getTickInsertSql() {
+ protected function getTickInsertSql(): IQueryBuilder {
$qb = $this->dbConnection->getQueryBuilder();
$qb->insert(self::TABLE_TICKS);
@@ -67,7 +61,7 @@ class TickRequestBuilder extends CoreRequestBuilder {
*
* @return IQueryBuilder
*/
- protected function getTickUpdateSql() {
+ protected function getTickUpdateSql(): IQueryBuilder {
$qb = $this->dbConnection->getQueryBuilder();
$qb->update(self::TABLE_TICKS);
@@ -80,7 +74,7 @@ class TickRequestBuilder extends CoreRequestBuilder {
*
* @return IQueryBuilder
*/
- protected function getTickSelectSql() {
+ protected function getTickSelectSql(): IQueryBuilder {
$qb = $this->dbConnection->getQueryBuilder();
/** @noinspection PhpMethodParametersCountMismatchInspection */
@@ -100,7 +94,7 @@ class TickRequestBuilder extends CoreRequestBuilder {
*
* @return IQueryBuilder
*/
- protected function getTickDeleteSql() {
+ protected function getTickDeleteSql(): IQueryBuilder {
$qb = $this->dbConnection->getQueryBuilder();
$qb->delete(self::TABLE_INDEXES);
@@ -111,17 +105,17 @@ class TickRequestBuilder extends CoreRequestBuilder {
/**
* @param array $data
*
- * @return ExtendedTick
+ * @return Tick
*/
- protected function parseTickSelectSql($data) {
- $tick = new ExtendedTick($data['source'], $data['id']);
+ protected function parseTickSelectSql(array $data): Tick {
+ $tick = new Tick($data['source'], (int) $data['id']);
$tick->setData(json_decode($data['data'], true))
- ->setTick($data['tick'])
- ->setFirstTick($data['first_tick'])
- ->setStatus($data['status'])
+ ->setTick((int) $data['tick'])
+ ->setFirstTick((int) $data['first_tick'])
+ ->setStatus($data['status'])
->setAction($data['action']);
return $tick;
}
-} \ No newline at end of file
+}
diff --git a/lib/Exceptions/DatabaseException.php b/lib/Exceptions/DatabaseException.php
index b285337..81c82c6 100644
--- a/lib/Exceptions/DatabaseException.php
+++ b/lib/Exceptions/DatabaseException.php
@@ -1,4 +1,7 @@
<?php
+declare(strict_types=1);
+
+
/**
* FullTextSearch - Full text search framework for Nextcloud
*
@@ -24,8 +27,10 @@
*
*/
+
namespace OCA\FullTextSearch\Exceptions;
+
class DatabaseException extends \Exception {
}
diff --git a/lib/Exceptions/EmptySearchException.php b/lib/Exceptions/EmptySearchException.php
index cfec8d9..c5a63e0 100644
--- a/lib/Exceptions/EmptySearchException.php
+++ b/lib/Exceptions/EmptySearchException.php
@@ -1,4 +1,7 @@
<?php
+declare(strict_types=1);
+
+
/**
* FullTextSearch - Full text search framework for Nextcloud
*
@@ -24,8 +27,10 @@
*
*/
+
namespace OCA\FullTextSearch\Exceptions;
+
class EmptySearchException extends \Exception {
}
diff --git a/lib/Exceptions/IndexDoesNotExistException.php b/lib/Exceptions/IndexDoesNotExistException.php
index d113814..cc65d51 100644
--- a/lib/Exceptions/IndexDoesNotExistException.php
+++ b/lib/Exceptions/IndexDoesNotExistException.php
@@ -1,4 +1,7 @@
<?php
+declare(strict_types=1);
+
+
/**
* FullTextSearch - Full text search framework for Nextcloud
*
@@ -24,8 +27,10 @@
*
*/
+
namespace OCA\FullTextSearch\Exceptions;
+
class IndexDoesNotExistException extends \Exception {
}
diff --git a/lib/Exceptions/InterruptException.php b/lib/Exceptions/InterruptException.php
index 6a6f680..d64eb12 100644
--- a/lib/Exceptions/InterruptException.php
+++ b/lib/Exceptions/InterruptException.php
@@ -1,4 +1,7 @@
<?php
+declare(strict_types=1);
+
+
/**
* FullTextSearch - Full text search framework for Nextcloud
*
@@ -24,8 +27,10 @@
*
*/
+
namespace OCA\FullTextSearch\Exceptions;
+
class InterruptException extends \Exception {
}
diff --git a/lib/Exceptions/MissingDocumentException.php b/lib/Exceptions/MissingDocumentException.php
index 2dfa5ae..6e1d955 100644
--- a/lib/Exceptions/MissingDocumentException.php
+++ b/lib/Exceptions/MissingDocumentException.php
@@ -1,4 +1,7 @@
<?php
+declare(strict_types=1);
+
+
/**
* FullTextSearch - Full text search framework for Nextcloud
*
@@ -24,8 +27,10 @@
*
*/
+
namespace OCA\FullTextSearch\Exceptions;
+
class MissingDocumentException extends \Exception {
}
diff --git a/lib/Exceptions/NoResultException.php b/lib/Exceptions/NoResultException.php
index 5bcefd7..4101e86 100644
--- a/lib/Exceptions/NoResultException.php
+++ b/lib/Exceptions/NoResultException.php
@@ -1,4 +1,7 @@
<?php
+declare(strict_types=1);
+
+
/**
* FullTextSearch - Full text search framework for Nextcloud
*
@@ -24,8 +27,10 @@
*
*/
+
namespace OCA\FullTextSearch\Exceptions;
+
class NoResultException extends \Exception {
}
diff --git a/lib/Exceptions/NotIndexableDocumentException.php b/lib/Exceptions/NotIndexableDocumentException.php
index 8f456d4..e9eb34a 100644
--- a/lib/Exceptions/NotIndexableDocumentException.php
+++ b/lib/Exceptions/NotIndexableDocumentException.php
@@ -1,4 +1,7 @@
<?php
+declare(strict_types=1);
+
+
/**
* FullTextSearch - Full text search framework for Nextcloud
*
@@ -24,8 +27,10 @@
*
*/
+
namespace OCA\FullTextSearch\Exceptions;
+
class NotIndexableDocumentException extends \Exception {
}
diff --git a/lib/Exceptions/PlatformDoesNotExistException.php b/lib/Exceptions/PlatformDoesNotExistException.php
index e69e03a..33540d0 100644
--- a/lib/Exceptions/PlatformDoesNotExistException.php
+++ b/lib/Exceptions/PlatformDoesNotExistException.php
@@ -1,4 +1,7 @@
<?php
+declare(strict_types=1);
+
+
/**
* FullTextSearch - Full text search framework for Nextcloud
*
@@ -24,8 +27,10 @@
*
*/
+
namespace OCA\FullTextSearch\Exceptions;
+
class PlatformDoesNotExistException extends \Exception {
}
diff --git a/lib/Exceptions/PlatformIsNotCompatibleException.php b/lib/Exceptions/PlatformIsNotCompatibleException.php
index ee7ebe2..97d27e5 100644
--- a/lib/Exceptions/PlatformIsNotCompatibleException.php
+++ b/lib/Exceptions/PlatformIsNotCompatibleException.php
@@ -1,4 +1,7 @@
<?php
+declare(strict_types=1);
+
+
/**
* FullTextSearch - Full text search framework for Nextcloud
*
@@ -24,8 +27,10 @@
*
*/
+
namespace OCA\FullTextSearch\Exceptions;
+
class PlatformIsNotCompatibleException extends \Exception {
}
diff --git a/lib/Exceptions/PlatformMustBeSingleException.php b/lib/Exceptions/PlatformMustBeSingleException.php
index 04b386e..ca69a7e 100644
--- a/lib/Exceptions/PlatformMustBeSingleException.php
+++ b/lib/Exceptions/PlatformMustBeSingleException.php
@@ -1,4 +1,7 @@
<?php
+declare(strict_types=1);
+
+
/**
* FullTextSearch - Full text search framework for Nextcloud
*
@@ -24,8 +27,10 @@
*
*/
+
namespace OCA\FullTextSearch\Exceptions;
+
class PlatformMustBeSingleException extends \Exception {
}
diff --git a/lib/Exceptions/PlatformNotDefinedException.php b/lib/Exceptions/PlatformNotDefinedException.php
index 2f8ff37..6b6da2c 100644
--- a/lib/Exceptions/PlatformNotDefinedException.php
+++ b/lib/Exceptions/PlatformNotDefinedException.php
@@ -1,4 +1,7 @@
<?php
+declare(strict_types=1);
+
+
/**
* FullTextSearch - Full text search framework for Nextcloud
*
@@ -24,8 +27,10 @@
*
*/
+
namespace OCA\FullTextSearch\Exceptions;
+
class PlatformNotDefinedException extends \Exception {
}
diff --git a/lib/Exceptions/PlatformNotSelectedException.php b/lib/Exceptions/PlatformNotSelectedException.php
index 3c7025e..85d1f33 100644
--- a/lib/Exceptions/PlatformNotSelectedException.php
+++ b/lib/Exceptions/PlatformNotSelectedException.php
@@ -1,4 +1,7 @@
<?php
+declare(strict_types=1);
+
+
/**
* FullTextSearch - Full text search framework for Nextcloud
*
@@ -24,8 +27,10 @@
*
*/
+
namespace OCA\FullTextSearch\Exceptions;
+
class PlatformNotSelectedException extends \Exception {
}
diff --git a/lib/Exceptions/ProviderDoesNotExistException.php b/lib/Exceptions/ProviderDoesNotExistException.php
index 01f51a1..b8e2388 100644
--- a/lib/Exceptions/ProviderDoesNotExistException.php
+++ b/lib/Exceptions/ProviderDoesNotExistException.php
@@ -1,4 +1,7 @@
<?php
+declare(strict_types=1);
+
+
/**
* FullTextSearch - Full text search framework for Nextcloud
*
@@ -24,8 +27,10 @@
*
*/
+
namespace OCA\FullTextSearch\Exceptions;
+
class ProviderDoesNotExistException extends \Exception {
}
diff --git a/lib/Exceptions/ProviderIsNotCompatibleException.php b/lib/Exceptions/ProviderIsNotCompatibleException.php
index b0d7cca..f77feb7 100644
--- a/lib/Exceptions/ProviderIsNotCompatibleException.php
+++ b/lib/Exceptions/ProviderIsNotCompatibleException.php
@@ -1,4 +1,7 @@
<?php
+declare(strict_types=1);
+
+
/**
* FullTextSearch - Full text search framework for Nextcloud
*
@@ -24,8 +27,10 @@
*
*/
+
namespace OCA\FullTextSearch\Exceptions;
+
class ProviderIsNotCompatibleException extends \Exception {
}
diff --git a/lib/Exceptions/ProviderIsNotUniqueException.php b/lib/Exceptions/ProviderIsNotUniqueException.php
index 13a1032..bd5323b 100644
--- a/lib/Exceptions/ProviderIsNotUniqueException.php
+++ b/lib/Exceptions/ProviderIsNotUniqueException.php
@@ -1,4 +1,7 @@
<?php
+declare(strict_types=1);
+
+
/**
* FullTextSearch - Full text search framework for Nextcloud
*
@@ -24,8 +27,10 @@
*
*/
+
namespace OCA\FullTextSearch\Exceptions;
+
class ProviderIsNotUniqueException extends \Exception {
}
diff --git a/lib/Exceptions/ProviderOptionsDoesNotExistException.php b/lib/Exceptions/ProviderOptionsDoesNotExistException.php
index 305f311..3314072 100644
--- a/lib/Exceptions/ProviderOptionsDoesNotExistException.php
+++ b/lib/Exceptions/ProviderOptionsDoesNotExistException.php
@@ -1,4 +1,7 @@
<?php
+declare(strict_types=1);
+
+
/**
* FullTextSearch - Full text search framework for Nextcloud
*
@@ -24,8 +27,10 @@
*
*/
+
namespace OCA\FullTextSearch\Exceptions;
+
class ProviderOptionsDoesNotExistException extends \Exception {
}
diff --git a/lib/Exceptions/RunnerAlreadyUpException.php b/lib/Exceptions/RunnerAlreadyUpException.php
index 4571740..dbfed8d 100644
--- a/lib/Exceptions/RunnerAlreadyUpException.php
+++ b/lib/Exceptions/RunnerAlreadyUpException.php
@@ -1,4 +1,7 @@
<?php
+declare(strict_types=1);
+
+
/**
* FullTextSearch - Full text search framework for Nextcloud
*
@@ -24,8 +27,10 @@
*
*/
+
namespace OCA\FullTextSearch\Exceptions;
+
class RunnerAlreadyUpException extends \Exception {
}
diff --git a/lib/Exceptions/TickDoesNotExistException.php b/lib/Exceptions/TickDoesNotExistException.php
index 7edbc17..6cc6323 100644
--- a/lib/Exceptions/TickDoesNotExistException.php
+++ b/lib/Exceptions/TickDoesNotExistException.php
@@ -1,4 +1,7 @@
<?php
+declare(strict_types=1);
+
+
/**
* FullTextSearch - Full text search framework for Nextcloud
*
@@ -24,8 +27,10 @@
*
*/
+
namespace OCA\FullTextSearch\Exceptions;
+
class TickDoesNotExistException extends \Exception {
}
diff --git a/lib/Exceptions/TickIsNotAliveException.php b/lib/Exceptions/TickIsNotAliveException.php
index 338a804..1721a37 100644
--- a/lib/Exceptions/TickIsNotAliveException.php
+++ b/lib/Exceptions/TickIsNotAliveException.php
@@ -1,4 +1,7 @@
<?php
+declare(strict_types=1);
+
+
/**
* FullTextSearch - Full text search framework for Nextcloud
*
@@ -24,8 +27,10 @@
*
*/
+
namespace OCA\FullTextSearch\Exceptions;
+
class TickIsNotAliveException extends \Exception {
}
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/Migration/ResetIndexes.php b/lib/Migration/ResetIndexes.php
deleted file mode 100644
index 7bc1389..0000000
--- a/lib/Migration/ResetIndexes.php
+++ /dev/null
@@ -1,102 +0,0 @@
-<?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\Migration;
-
-use OCA\FullTextSearch\Db\IndexesRequest;
-use OCA\FullTextSearch\Service\ProviderService;
-use OCP\Migration\IOutput;
-use OCP\Migration\IRepairStep;
-
-/**
- * Class ResetDatabase
- *
- * @package OCA\FullTextSearch\Migration
- */
-class ResetIndexes implements IRepairStep {
-
- /** @var IndexesRequest */
- protected $indexRequest;
-
- /** @var ProviderService */
- protected $providerService;
-
-
- /**
- * ResetDatabase constructor.
- *
- * @param IndexesRequest $indexRequest
- * @param ProviderService $providerService
- */
- public function __construct(IndexesRequest $indexRequest, ProviderService $providerService) {
- $this->indexRequest = $indexRequest;
- $this->providerService = $providerService;
- }
-
-
- /**
- * Returns the step's name
- *
- * @return string
- * @since 9.1.0
- */
- public function getName() {
- return 'Reset index';
- }
-
-
- /**
- * @param IOutput $output
- */
- public function run(IOutput $output) {
-
- $oldVersion = explode(
- '.', \OC::$server->getConfig()
- ->getAppValue('fulltextsearch', 'installed_version', '')
- );
-
- if ((int)$oldVersion[0] === 0
- && (int)$oldVersion[1] < 6) {
- $this->resetIndexes($output);
- }
-
- }
-
-
- /**
- * @param IOutput $output
- */
- public function resetIndexes(IOutput $output) {
- $output->info('Reset database');
-
-// $this->indexRequest->reset();
-// $this->providerService->setProvidersAsNotIndexed();
-
-
- $output->finishProgress();
- }
-
-}
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/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..dd25e68 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,24 @@
*
*/
+
namespace OCA\FullTextSearch\Model;
-class Index implements \JsonSerializable {
- const INDEX_OK = 1;
- const INDEX_IGNORE = 2;
+use daita\MySmallPhpTools\Traits\TArrayTools;
+use JsonSerializable;
+use OCP\FullTextSearch\Model\IIndex;
- const INDEX_META = 4;
- const INDEX_CONTENT = 8;
- const INDEX_FULL = 12;
- const INDEX_REMOVE = 16;
- const INDEX_DONE = 32;
- const INDEX_FAILED = 64;
+/**
+ * Class Index
+ *
+ * @package OCA\FullTextSearch\Model
+ */
+class Index implements IIndex, JsonSerializable {
- 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;
+ use TArrayTools;
/** @var string */
@@ -83,7 +81,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 +90,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 +105,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 +116,7 @@ class Index implements \JsonSerializable {
/**
* @return string
*/
- public function getSource() {
+ public function getSource(): string {
return $this->source;
}
@@ -126,9 +124,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 +135,7 @@ class Index implements \JsonSerializable {
/**
* @return string
*/
- public function getOwnerId() {
+ public function getOwnerId(): string {
return $this->ownerId;
}
@@ -146,9 +144,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 +159,7 @@ class Index implements \JsonSerializable {
/**
* @return int
*/
- public function getStatus() {
+ public function getStatus(): int {
return $this->status;
}
@@ -170,29 +168,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 +204,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 +216,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 +227,7 @@ class Index implements \JsonSerializable {
/**
* @return array
*/
- public function getOptions() {
+ public function getOptions(): array {
return $this->options;
}
@@ -236,36 +238,28 @@ class Index implements \JsonSerializable {
*
* @return string
*/
- public function getOption($option, $default = '') {
- if (!array_key_exists($option, $this->options)) {
- return $default;
- }
-
- return $this->options[$option];
+ public function getOption(string $option, string $default = ''): string {
+ return $this->get($option, $this->options, $default);
}
-
/**
* @param string $option
* @param int $default
*
* @return int
*/
- public function getOptionInt($option, $default = 0) {
- if (!array_key_exists($option, $this->options)) {
- return $default;
- }
-
- return $this->options[$option];
+ public function getOptionInt(string $option, int $default = 0): int {
+ return $this->getInt($option, $this->options, $default);
}
+
/**
* @param int $err
*
- * @return $this
+ * @return IIndex
*/
- public function setErrorCount($err) {
+ public function setErrorCount(int $err): IIndex {
$this->err = $err;
return $this;
@@ -274,39 +268,40 @@ 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];
}
-
/**
- *
+ * @return IIndex
*/
- 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 +312,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,15 +347,15 @@ class Index implements \JsonSerializable {
/**
* @return int
*/
- public function getLastIndex() {
+ public function getLastIndex(): int {
return $this->lastIndex;
}
/**
- * @return array<string,string|integer>
+ * @return array
*/
- public function jsonSerialize() {
+ public function jsonSerialize(): array {
return [
'ownerId' => $this->getOwnerId(),
'providerId' => $this->getProviderId(),
@@ -370,15 +370,19 @@ class Index implements \JsonSerializable {
}
+ /**
+ *
+ */
public function __destruct() {
unset($this->providerId);
unset($this->documentId);
+ unset($this->source);
unset($this->ownerId);
unset($this->status);
unset($this->options);
unset($this->err);
- unset($this->message);
+ unset($this->errors);
unset($this->lastIndex);
}
-} \ 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..e5fdd25 100644
--- a/lib/Model/IndexOptions.php
+++ b/lib/Model/IndexOptions.php
@@ -1,4 +1,7 @@
<?php
+declare(strict_types=1);
+
+
/**
* FullTextSearch - Full text search framework for Nextcloud
*
@@ -24,10 +27,25 @@
*
*/
+
namespace OCA\FullTextSearch\Model;
-class IndexOptions implements \JsonSerializable {
+use daita\MySmallPhpTools\Traits\TArrayTools;
+use JsonSerializable;
+use OCP\FullTextSearch\Model\IIndexOptions;
+
+
+/**
+ * Class IndexOptions
+ *
+ * @package OCA\FullTextSearch\Model
+ */
+class IndexOptions implements IIndexOptions, JsonSerializable {
+
+
+ use TArrayTools;
+
/**
* @var array
@@ -35,79 +53,89 @@ class IndexOptions implements \JsonSerializable {
private $options = [];
+ /**
+ * IndexOptions constructor.
+ *
+ * @param array $options
+ */
public function __construct($options = []) {
$this->options = $options;
}
+
/**
* @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];
- }
-
- return $default;
+ public function getOption(string $option, string $default = ''): string {
+ return $this->get($option, $this->options, $default);
}
-
/**
* @param string $option
* @param array $default
*
* @return array
*/
- public function getOptionArray($option, $default = []) {
- if (array_key_exists($option, $this->options)) {
- $options = $this->options[$option];
- if (is_array($options)) {
- return $this->options[$option];
- }
- }
-
- return $default;
+ public function getOptionArray(string $option, array $default = []): array {
+ return $this->getArray($option, $this->options, $default);
}
@@ -117,27 +145,16 @@ class IndexOptions implements \JsonSerializable {
*
* @return bool
*/
- public function getOptionBool($option, $default) {
- if (array_key_exists($option, $this->options)) {
- $options = $this->options[$option];
- if (is_bool($options)) {
- return $this->options[$option];
- }
- }
-
- return $default;
+ public function getOptionBool(string $option, bool $default): bool {
+ return $this->getBool($option, $this->options, $default);
}
/**
- * 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() {
+ public function jsonSerialize(): array {
return $this->options;
}
-} \ No newline at end of file
+}
+
diff --git a/lib/Model/PlatformWrapper.php b/lib/Model/PlatformWrapper.php
index 2bcccbb..6f9f84c 100644
--- a/lib/Model/PlatformWrapper.php
+++ b/lib/Model/PlatformWrapper.php
@@ -1,4 +1,7 @@
<?php
+declare(strict_types=1);
+
+
/**
* FullTextSearch - Full text search framework for Nextcloud
*
@@ -28,7 +31,7 @@
namespace OCA\FullTextSearch\Model;
-use OCA\FullTextSearch\IFullTextSearchPlatform;
+use OCP\FullTextSearch\IFullTextSearchPlatform;
/**
@@ -56,9 +59,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 +69,7 @@ class PlatformWrapper {
/**
* @return string
*/
- public function getAppId() {
+ public function getAppId(): string {
return $this->appId;
}
@@ -75,7 +78,7 @@ class PlatformWrapper {
*
* @return PlatformWrapper
*/
- public function setAppId($appId) {
+ public function setAppId(string $appId): PlatformWrapper {
$this->appId = $appId;
return $this;
@@ -85,7 +88,7 @@ class PlatformWrapper {
/**
* @return string
*/
- public function getClass() {
+ public function getClass(): string {
return $this->class;
}
@@ -94,7 +97,7 @@ class PlatformWrapper {
*
* @return PlatformWrapper
*/
- public function setClass($class) {
+ public function setClass(string $class): PlatformWrapper {
$this->class = $class;
return $this;
@@ -104,7 +107,7 @@ class PlatformWrapper {
/**
* @return IFullTextSearchPlatform
*/
- public function getPlatform() {
+ public function getPlatform(): IFullTextSearchPlatform {
return $this->platform;
}
@@ -113,7 +116,7 @@ class PlatformWrapper {
*
* @return PlatformWrapper
*/
- public function setPlatform($platform) {
+ public function setPlatform(IFullTextSearchPlatform $platform): PlatformWrapper {
$this->platform = $platform;
return $this;
@@ -123,7 +126,7 @@ class PlatformWrapper {
/**
* @return string
*/
- public function getVersion() {
+ public function getVersion(): string {
return $this->version;
}
@@ -132,7 +135,7 @@ class PlatformWrapper {
*
* @return PlatformWrapper
*/
- public function setVersion($version) {
+ public function setVersion(string $version): PlatformWrapper {
$this->version = $version;
return $this;
diff --git a/lib/Model/ProviderIndexes.php b/lib/Model/ProviderIndexes.php
index 2915181..1475631 100644
--- a/lib/Model/ProviderIndexes.php
+++ b/lib/Model/ProviderIndexes.php
@@ -1,4 +1,7 @@
<?php
+declare(strict_types=1);
+
+
/**
* FullTextSearch - Full text search framework for Nextcloud
*
@@ -27,21 +30,32 @@
namespace OCA\FullTextSearch\Model;
+
+use OCA\FullTextSearch\Exceptions\IndexDoesNotExistException;
+use OCP\FullTextSearch\Model\IIndex;
+
+
+/**
+ * Class ProviderIndexes
+ *
+ * @package OCA\FullTextSearch\Model
+ */
class ProviderIndexes {
- /** @var Index[] */
+
+ /** @var IIndex[] */
private $indexes;
- public function __construct($indexes) {
+ public function __construct(array $indexes) {
$this->indexes = $indexes;
}
/**
- * @return Index[]
+ * @return IIndex[]
*/
- public function getIndexes() {
+ public function getIndexes(): array {
return $this->indexes;
}
@@ -49,17 +63,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..05ed653 100644
--- a/lib/Model/ProviderWrapper.php
+++ b/lib/Model/ProviderWrapper.php
@@ -1,4 +1,7 @@
<?php
+declare(strict_types=1);
+
+
/**
* FullTextSearch - Full text search framework for Nextcloud
*
@@ -28,7 +31,7 @@
namespace OCA\FullTextSearch\Model;
-use OCA\FullTextSearch\IFullTextSearchProvider;
+use OCP\FullTextSearch\IFullTextSearchProvider;
/**
@@ -55,7 +58,7 @@ class ProviderWrapper {
* @param string $appId
* @param IFullTextSearchProvider $provider
*/
- public function __construct($appId, $provider) {
+ public function __construct(string $appId, IFullTextSearchProvider $provider) {
$this->appId = $appId;
$this->provider = $provider;
}
@@ -63,7 +66,7 @@ class ProviderWrapper {
/**
* @return string
*/
- public function getAppId() {
+ public function getAppId(): string {
return $this->appId;
}
@@ -72,7 +75,7 @@ class ProviderWrapper {
*
* @return ProviderWrapper
*/
- public function setAppId($appId) {
+ public function setAppId(string $appId): ProviderWrapper {
$this->appId = $appId;
return $this;
@@ -82,7 +85,7 @@ class ProviderWrapper {
/**
* @return IFullTextSearchProvider
*/
- public function getProvider() {
+ public function getProvider(): IFullTextSearchProvider {
return $this->provider;
}
@@ -91,7 +94,7 @@ class ProviderWrapper {
*
* @return ProviderWrapper
*/
- public function setProvider($provider) {
+ public function setProvider(IFullTextSearchProvider $provider): ProviderWrapper {
$this->provider = $provider;
return $this;
@@ -101,7 +104,7 @@ class ProviderWrapper {
/**
* @return string
*/
- public function getVersion() {
+ public function getVersion(): string {
return $this->version;
}
@@ -110,7 +113,7 @@ class ProviderWrapper {
*
* @return ProviderWrapper
*/
- public function setVersion($version) {
+ public function setVersion(string $version): ProviderWrapper {
$this->version = $version;
return $this;
@@ -118,3 +121,4 @@ class ProviderWrapper {
}
+
diff --git a/lib/Model/Runner.php b/lib/Model/Runner.php
index a2187aa..7f17b7f 100644
--- a/lib/Model/Runner.php
+++ b/lib/Model/Runner.php
@@ -1,4 +1,7 @@
<?php
+declare(strict_types=1);
+
+
/**
* FullTextSearch - Full text search framework for Nextcloud
*
@@ -27,15 +30,28 @@
namespace OCA\FullTextSearch\Model;
+
+use daita\MySmallPhpTools\Traits\TArrayTools;
+use OCA\FullTextSearch\ACommandBase;
use OCA\FullTextSearch\Exceptions\RunnerAlreadyUpException;
use OCA\FullTextSearch\Exceptions\TickDoesNotExistException;
use OCA\FullTextSearch\Exceptions\TickIsNotAliveException;
-use OCA\FullTextSearch\Service\MiscService;
use OCA\FullTextSearch\Service\RunningService;
+use OCP\FullTextSearch\Model\IIndex;
+use OCP\FullTextSearch\Model\IRunner;
use Symfony\Component\Console\Output\OutputInterface;
-class Runner {
+/**
+ * Class Runner
+ *
+ * @package OCA\FullTextSearch\Model
+ */
+class Runner implements IRunner {
+
+
+ use TArrayTools;
+
const TICK_TTL = 1800;
@@ -43,24 +59,17 @@ 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;
/** @var string */
private $source;
-// /** @var bool */
-// private $strict = false;
-
/** @var int */
- private $tickId;
+ private $tickId = 0;
- /** @var ExtendedBase */
- private $commandBase = null;
+ /** @var ACommandBase */
+ private $base = null;
/** @var OutputInterface */
private $outputInterface = null;
@@ -109,7 +118,7 @@ class Runner {
* @param string $source
* @param array $keys
*/
- public function __construct(RunningService $runningService, $source, $keys = []) {
+ public function __construct(RunningService $runningService, string $source, array $keys = []) {
$this->runningService = $runningService;
$this->source = $source;
@@ -123,7 +132,6 @@ class Runner {
* @throws RunnerAlreadyUpException
*/
public function start() {
-// $this->strict = $strict;
$this->tickId = $this->runningService->start($this->source);
}
@@ -135,7 +143,12 @@ class Runner {
* @return string
* @throws \Exception
*/
- public function updateAction($action = '', $force = false) {
+ public function updateAction(string $action = '', bool $force = false): string {
+
+ if ($this->base !== null) {
+ $this->base->abort();
+ }
+
$n = '';
if (sizeof($this->methodOnKeyPress) > 0) {
$n = fread(STDIN, 9999);
@@ -150,13 +163,6 @@ class Runner {
}
$tick = time();
-// try {
-// $this->hasBeenInterrupted();
-// } catch (InterruptException $e) {
-// $this->stop();
-// throw $e;
-// }
-
if ($this->oldAction !== $action || $force) {
while (true) {
if (!$this->isPaused()) {
@@ -168,7 +174,11 @@ class Runner {
if ($pressed === $this->keys['nextStep']) {
break;
}
+
usleep(300000);
+ if ($this->base !== null) {
+ $this->base->abort();
+ }
}
$this->pauseRunning(false);
@@ -195,7 +205,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,9 +214,8 @@ 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) {
$this->info[$k] = $data[$k];
}
@@ -219,7 +228,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 +237,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;
}
@@ -244,39 +253,37 @@ class Runner {
if ($color !== '') {
$this->info[$info . 'Colored'] = '<' . $color . '>' . $value . '</' . $color . '>';
}
-
-
}
/**
* @return array
*/
- public function getInfoAll() {
+ public function getInfoAll(): array {
return $this->info;
}
/**
- * @param string $k
+ * @param string $info
*
* @return string
*/
- public function getInfo($k) {
- return MiscService::get($k, $this->info, '');
+ public function getInfo(string $info): string {
+ return $this->get($info, $this->info, '');
}
/**
* @param array $method
*/
- public function onKeyPress($method) {
+ public function onKeyPress(array $method) {
$this->methodOnKeyPress[] = $method;
}
/**
- * @param $key
+ * @param string $key
*/
- public function keyPressed($key) {
+ public function keyPressed(string $key) {
foreach ($this->methodOnKeyPress as $method) {
call_user_func($method, $key);
}
@@ -286,11 +293,14 @@ class Runner {
/**
* @param array $method
*/
- public function onInfoUpdate($method) {
+ public function onInfoUpdate(array $method) {
$this->methodOnInfoUpdate[] = $method;
}
+ /**
+ *
+ */
public function infoUpdated() {
foreach ($this->methodOnInfoUpdate as $method) {
call_user_func($method, $this->info);
@@ -301,17 +311,18 @@ class Runner {
/**
* @param array $method
*/
- public function onNewIndexError($method) {
+ public function onNewIndexError(array $method) {
$this->methodOnIndexError[] = $method;
}
/**
- * @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,
@@ -328,18 +339,18 @@ class Runner {
/**
* @param array $method
*/
- public function onNewIndexResult($method) {
+ public function onNewIndexResult(array $method) {
$this->methodOnIndexResult[] = $method;
}
/**
- * @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,24 +364,13 @@ class Runner {
}
-// /**
-// * @throws InterruptException
-// */
-// private function hasBeenInterrupted() {
-// if ($this->commandBase === null) {
-// return;
-// }
-// $this->commandBase->hasBeenInterrupted();
-// }
-
-
/**
* @param int $tick
* @param string $action
*
* @throws TickDoesNotExistException
*/
- private function updateTick($tick, $action) {
+ private function updateTick(int $tick, string $action) {
if ($this->oldAction === $action && ($this->tickUpdate + self::TICK_UPDATE > $tick)) {
return;
}
@@ -387,9 +387,9 @@ class Runner {
/**
- * @param $tick
+ * @param int $tick
*/
- private function updateRamInfo($tick) {
+ private function updateRamInfo(int $tick) {
if (($this->ramUpdate + self::MEMORY_UPDATE) > $tick) {
return;
}
@@ -402,10 +402,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,19 +423,19 @@ class Runner {
/**
- * @param ExtendedBase $base
+ * @param ACommandBase $base
* @param OutputInterface $output
*/
- public function sourceIsCommandLine(ExtendedBase $base, OutputInterface $output) {
+ public function sourceIsCommandLine(ACommandBase $base, OutputInterface $output) {
+ $this->base = $base;
$this->outputInterface = $output;
- $this->commandBase = $base;
}
/**
* @param bool $pause
*/
- public function pause($pause) {
+ public function pause(bool $pause) {
$this->paused = $pause;
$this->infoUpdated();
}
@@ -443,7 +443,7 @@ class Runner {
/**
* @return bool
*/
- public function isPaused() {
+ public function isPaused(): bool {
return $this->paused;
}
@@ -451,28 +451,23 @@ class Runner {
/**
* @param bool $running
*/
- public function pauseRunning($running) {
+ public function pauseRunning(bool $running) {
$this->pauseRunning = $running;
$this->infoUpdated();
}
-
- public function isPauseRunning() {
+ /**
+ * @return bool
+ */
+ public function isPauseRunning(): bool {
return $this->pauseRunning;
}
-// /**
-// * @return bool
-// */
-// public function isStrict() {
-// return $this->strict;
-// }
-
/**
* @param string $line
*/
- public function output($line) {
+ public function output(string $line) {
if ($this->outputInterface === null) {
return;
}
diff --git a/lib/Model/SearchRequest.php b/lib/Model/SearchRequest.php
index 0fce57a..bc98d05 100644
--- a/lib/Model/SearchRequest.php
+++ b/lib/Model/SearchRequest.php
@@ -1,4 +1,7 @@
<?php
+declare(strict_types=1);
+
+
/**
* FullTextSearch - Full text search framework for Nextcloud
*
@@ -24,11 +27,25 @@
*
*/
+
namespace OCA\FullTextSearch\Model;
-use OCA\FullTextSearch\Service\MiscService;
-class SearchRequest implements \JsonSerializable {
+use daita\MySmallPhpTools\Traits\TArrayTools;
+use JsonSerializable;
+use OCP\FullTextSearch\Model\ISearchRequest;
+
+
+/**
+ * Class SearchRequest
+ *
+ * @package OCA\FullTextSearch\Model
+ */
+class SearchRequest implements ISearchRequest, JsonSerializable {
+
+
+ use TArrayTools;
+
/** @var array */
private $providers;
@@ -89,52 +106,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 +177,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 +215,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,12 +330,8 @@ class SearchRequest implements \JsonSerializable {
*
* @return string
*/
- public function getOption($option, $default = '') {
- if (array_key_exists($option, $this->options)) {
- return $this->options[$option];
- }
-
- return $default;
+ public function getOption(string $option, string $default = ''): string {
+ return $this->get($option, $this->options, $default);
}
@@ -302,25 +341,18 @@ class SearchRequest implements \JsonSerializable {
*
* @return array
*/
- public function getOptionArray($option, $default = []) {
- if (array_key_exists($option, $this->options)) {
- $options = $this->options[$option];
- if (is_array($options)) {
- return $this->options[$option];
- }
- }
-
- return $default;
+ public function getOptionArray(string $option, array $default = []): array {
+ return $this->getArray($option, $this->options, $default);
}
/**
- * @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 +360,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 +399,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 +412,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 +431,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 +473,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 +492,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 +505,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 +526,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 +542,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 +554,7 @@ class SearchRequest implements \JsonSerializable {
/**
* @return array
*/
- public function getWildcardFields() {
+ public function getWildcardFields(): array {
return $this->wildcardFields;
}
@@ -508,7 +562,7 @@ class SearchRequest implements \JsonSerializable {
// /**
// * @param array $query
// *
-// * @return $this
+// * @return ISearchRequest
// */
// public function addWildcardQuery($query) {
// $this->addWildcardQueries([$query]);
@@ -519,7 +573,7 @@ class SearchRequest implements \JsonSerializable {
// /**
// * @param array $query
// *
-// * @return $this
+// * @return ISearchRequest
// */
// public function addWildcardQueries($query) {
// array_push($this->wildcardQueries, $query);
@@ -538,9 +592,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 +603,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 +614,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 +633,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 +644,7 @@ class SearchRequest implements \JsonSerializable {
/**
* @return array
*/
- public function getRegexFilters() {
+ public function getRegexFilters(): array {
return $this->regexFilters;
}
@@ -598,7 +652,7 @@ class SearchRequest implements \JsonSerializable {
/**
* @return array
*/
- public function jsonSerialize() {
+ public function jsonSerialize(): array {
return [
'providers' => $this->getProviders(),
'author' => $this->getAuthor(),
@@ -615,39 +669,41 @@ class SearchRequest implements \JsonSerializable {
/**
- * @param string $json
- *
- * @return SearchRequest
- */
- public static function fromJSON($json) {
- return self::fromArray(json_decode($json, true));
- }
-
- /**
* @param array $arr
*
* @return SearchRequest
*/
- public static function fromArray($arr) {
+ public function importFromArray($arr): SearchRequest {
$providers = $arr['providers'];
if (!is_array($providers)) {
$providers = [$providers];
}
- $request = new SearchRequest();
- $request->setProviders($providers);
- $request->setAuthor(MiscService::get('author', $arr, ''));
- $request->setSearch(MiscService::get('search', $arr, ''));
- $request->setPage(MiscService::get('page', $arr, 0));
- $request->setParts(MiscService::get('parts', $arr, []));
- $request->setSize(MiscService::get('size', $arr, 10));
- $request->setOptions(MiscService::get('options', $arr, []));
- $request->setMetaTags(MiscService::get('metatags', $arr, []));
- $request->setSubTags(MiscService::get('subtags', $arr, []));
- $request->setTags(MiscService::get('tags', $arr, []));
+ $this->setProviders($providers);
+ $this->setAuthor($this->get('author', $arr, ''));
+ $this->setSearch($this->get('search', $arr, ''));
+ $this->setPage($this->getInt('page', $arr, 0));
+ $this->setParts($this->getArray('parts', $arr, []));
+ $this->setSize($this->getInt('size', $arr, 10));
+ $this->setOptions($this->getArray('options', $arr, []));
+ $this->setMetaTags($this->getArray('metatags', $arr, []));
+ $this->setSubTags($this->getArray('subtags', $arr, []));
+ $this->setTags($this->getArray('tags', $arr, []));
- return $request;
+ return $this;
}
-} \ No newline at end of file
+ /**
+ * @param string $json
+ *
+ * @return SearchRequest
+ */
+ public static function fromJSON(string $json): SearchRequest {
+ $searchRequest = new SearchRequest();
+ $searchRequest->importFromArray(json_decode($json, true));
+
+ return $searchRequest;
+ }
+
+}
diff --git a/lib/Model/SearchResult.php b/lib/Model/SearchResult.php
index e985fc3..4d77445 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,24 @@
*
*/
+
namespace OCA\FullTextSearch\Model;
-use OCA\FullTextSearch\IFullTextSearchPlatform;
-use OCA\FullTextSearch\IFullTextSearchProvider;
-class SearchResult implements \JsonSerializable {
+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
+ *
+ * @package OCA\FullTextSearch\Model
+ */
+class SearchResult implements ISearchResult, JsonSerializable {
/** @var IndexDocument[] */
private $documents = [];
@@ -55,11 +70,16 @@ class SearchResult implements \JsonSerializable {
/** @var boolean */
private $timedOut;
- /** @var SearchRequest */
+ /** @var ISearchRequest */
private $request;
- public function __construct(SearchRequest $searchRequest = null) {
+ /**
+ * SearchResult constructor.
+ *
+ * @param SearchRequest $searchRequest
+ */
+ public function __construct(SearchRequest $searchRequest) {
$this->request = $searchRequest;
}
@@ -67,9 +87,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 +98,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 +116,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 +162,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(IFullTextSearchPlatform $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,68 +206,113 @@ 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;
+ }
+
+
+ /**
+ * @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 [];
}
/**
- * @return array<string,array<string,string>|IndexDocument[]|integer>
+ * @return array
*/
- public function jsonSerialize() {
+ public function jsonSerialize(): array {
$providerObj = $this->getProvider();
$provider = [];
if ($providerObj !== null) {
$provider = [
- 'id' => $providerObj->getId(),
- 'name' => $providerObj->getName()
+ 'id' => $providerObj->getId(),
+ 'name' => $providerObj->getName()
];
}
@@ -239,8 +320,8 @@ class SearchResult implements \JsonSerializable {
$platform = [];
if ($platformObj !== null) {
$platform = [
- 'id' => $platformObj->getId(),
- 'name' => $platformObj->getName()
+ 'id' => $platformObj->getId(),
+ 'name' => $platformObj->getName()
];
}
@@ -258,4 +339,6 @@ class SearchResult implements \JsonSerializable {
]
];
}
+
}
+
diff --git a/lib/Model/Tick.php b/lib/Model/Tick.php
index 865bb86..3a9efc2 100644
--- a/lib/Model/Tick.php
+++ b/lib/Model/Tick.php
@@ -1,4 +1,7 @@
<?php
+declare(strict_types=1);
+
+
/**
* FullTextSearch - Full text search framework for Nextcloud
*
@@ -28,8 +31,19 @@
namespace OCA\FullTextSearch\Model;
+use daita\MySmallPhpTools\Traits\TArrayTools;
+
+/**
+ * Class Tick
+ *
+ * @package OCA\FullTextSearch\Model
+ */
class Tick {
+
+ use TArrayTools;
+
+
/** @var int */
private $id;
@@ -49,10 +63,16 @@ class Tick {
private $status;
/** @var string */
- private $action;
+ private $action = '';
- public function __construct($source, $id = 0) {
+ /**
+ * Tick constructor.
+ *
+ * @param string $source
+ * @param int $id
+ */
+ public function __construct(string $source, int $id = 0) {
$this->source = $source;
$this->id = $id;
}
@@ -61,7 +81,7 @@ class Tick {
/**
* @return int
*/
- public function getId() {
+ public function getId(): int {
return $this->id;
}
@@ -70,7 +90,7 @@ class Tick {
*
* @return $this
*/
- public function setId($id) {
+ public function setId(int $id): Tick {
$this->id = $id;
return $this;
@@ -80,7 +100,7 @@ class Tick {
/**
* @return string
*/
- public function getSource() {
+ public function getSource(): string {
return $this->source;
}
@@ -88,7 +108,7 @@ class Tick {
/**
* @return array
*/
- public function getData() {
+ public function getData(): array {
return $this->data;
}
@@ -97,7 +117,7 @@ class Tick {
*
* @return $this
*/
- public function setData($data) {
+ public function setData(array $data): Tick {
$this->data = $data;
return $this;
@@ -107,7 +127,7 @@ class Tick {
/**
* @return int
*/
- public function getTick() {
+ public function getTick(): int {
return $this->tick;
}
@@ -116,7 +136,7 @@ class Tick {
*
* @return $this
*/
- public function setTick($tick = 0) {
+ public function setTick(int $tick = 0): Tick {
if ($tick === 0) {
$tick = time();
}
@@ -130,7 +150,7 @@ class Tick {
/**
* @return int
*/
- public function getFirstTick() {
+ public function getFirstTick(): int {
return $this->firstTick;
}
@@ -139,7 +159,7 @@ class Tick {
*
* @return $this
*/
- public function setFirstTick($tick = 0) {
+ public function setFirstTick(int $tick = 0): Tick {
if ($tick === 0) {
$tick = time();
}
@@ -153,7 +173,7 @@ class Tick {
/**
* @return string
*/
- public function getStatus() {
+ public function getStatus(): string {
return $this->status;
}
@@ -162,7 +182,7 @@ class Tick {
*
* @return $this
*/
- public function setStatus($status) {
+ public function setStatus(string $status): Tick {
$this->status = $status;
return $this;
@@ -172,7 +192,7 @@ class Tick {
/**
* @return string
*/
- public function getAction() {
+ public function getAction(): string {
return $this->action;
}
@@ -181,10 +201,86 @@ class Tick {
*
* @return $this
*/
- public function setAction($action) {
+ public function setAction(string $action): Tick {
$this->action = $action;
return $this;
}
-} \ No newline at end of file
+
+ /**
+ * @param string $info
+ * @param string $value
+ *
+ * @return $this
+ */
+ public function setInfo(string $info, string $value): Tick {
+ $this->data[$info] = $value;
+
+ return $this;
+ }
+
+ /**
+ * @param string $info
+ * @param int $value
+ *
+ * @return $this
+ */
+ public function setInfoInt(string $info, int $value): Tick {
+ $this->data[$info] = $value;
+
+ return $this;
+ }
+
+ /**
+ * @param string $info
+ * @param float $value
+ *
+ * @return $this
+ */
+ public function setInfoFloat(string $info, float $value): Tick {
+ $this->data[$info] = $value;
+
+ return $this;
+ }
+
+ /**
+ * @param string $info
+ */
+ public function unsetInfo(string $info) {
+ unset($this->data[$info]);
+ }
+
+ /**
+ * @param string $info
+ * @param string $default
+ *
+ * @return string
+ */
+ public function getInfo(string $info, string $default = ''): string {
+ return $this->get($info, $this->data, $default);
+ }
+
+
+ /**
+ * @param string $info
+ * @param int $default
+ *
+ * @return int
+ */
+ public function getInfoInt(string $info, int $default = 0): int {
+ return $this->getInt($info, $this->data, $default);
+ }
+
+ /**
+ * @param string $info
+ * @param float $default
+ *
+ * @return float
+ */
+ public function getInfoFloat(string $info, float $default = 0): float {
+ return $this->getFloat($info, $this->data, $default);
+ }
+
+}
+
diff --git a/lib/Provider/TestProvider.php b/lib/Provider/TestProvider.php
index 1deeb11..360c12b 100644
--- a/lib/Provider/TestProvider.php
+++ b/lib/Provider/TestProvider.php
@@ -1,4 +1,7 @@
<?php
+declare(strict_types=1);
+
+
/**
* FullTextSearch - Full text search framework for Nextcloud
*
@@ -27,19 +30,28 @@
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
+ *
+ * @package OCA\FullTextSearch\Provider
+ */
class TestProvider implements IFullTextSearchProvider {
@@ -74,15 +86,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 +100,7 @@ class TestProvider implements IFullTextSearchProvider {
/**
* return name of the provider
*/
- public function getName() {
+ public function getName(): string {
return 'Test Provider';
}
@@ -98,29 +108,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,34 +153,18 @@ class TestProvider implements IFullTextSearchProvider {
*
* @return IndexDocument[]
*/
- public function generateIndexableDocuments($userId) {
+ public function generateIndexableDocuments(string $userId): array {
$result = [];
$result[] = $this->testService->generateIndexDocumentContentLicense($this->indexOptions);
$result[] = $this->testService->generateIndexDocumentSimple($this->indexOptions);
-// $result[] = $this->testService->generateIndexDocuments(TestService::DOCUMENT_TEST_INDEX3);
-
return $result;
}
/**
* 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 +177,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 +216,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..1b8b734 100644
--- a/lib/Service/CliService.php
+++ b/lib/Service/CliService.php
@@ -1,4 +1,7 @@
<?php
+declare(strict_types=1);
+
+
/**
* FullTextSearch - Full text search framework for Nextcloud
*
@@ -24,12 +27,20 @@
*
*/
+
namespace OCA\FullTextSearch\Service;
+
use OCA\FullTextSearch\Model\Runner;
use Symfony\Component\Console\Helper\ProgressBar;
use Symfony\Component\Console\Output\OutputInterface;
+
+/**
+ * Class CliService
+ *
+ * @package OCA\FullTextSearch\Service
+ */
class CliService {
@@ -51,8 +62,9 @@ class CliService {
/** @var OutputInterface */
private $output = null;
+
/**
- * TestService constructor.
+ * CliService constructor.
*
* @param MiscService $miscService
*/
@@ -75,7 +87,7 @@ class CliService {
* @param string $panelId
* @param array $lines
*/
- public function createPanel($panelId, $lines) {
+ public function createPanel(string $panelId, array $lines) {
if (!is_array($lines)) {
$lines = [$lines];
}
@@ -96,7 +108,7 @@ class CliService {
* @param string $panelSlot
* @param string $panelId
*/
- public function displayPanel($panelSlot, $panelId) {
+ public function displayPanel(string $panelSlot, string $panelId) {
$this->displayedPanel[] = [
'slot' => $panelSlot,
'id' => $panelId
@@ -109,7 +121,7 @@ class CliService {
*
* @return string
*/
- public function currentPanel($panelSlot) {
+ public function currentPanel(string $panelSlot): string {
foreach ($this->displayedPanel as $panel) {
if ($panel['slot'] === $panelSlot) {
return $panel['id'];
@@ -124,7 +136,7 @@ class CliService {
* @param string $panelSlot
* @param string $panelId
*/
- public function switchPanel($panelSlot, $panelId) {
+ public function switchPanel(string $panelSlot, string $panelId) {
$this->displayedPanel = array_map(
function($item) use ($panelId, $panelSlot) {
if ($item['slot'] === $panelSlot) {
@@ -140,9 +152,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('');
@@ -168,6 +179,9 @@ class CliService {
}
+ /**
+ *
+ */
public function refreshDisplay() {
if ($this->display === null) {
@@ -188,6 +202,9 @@ class CliService {
}
+ /**
+ *
+ */
public function refreshInfo() {
if ($this->runner->isPauseRunning()) {
$this->display->setMessage('(paused)', '_paused');
@@ -201,7 +218,7 @@ class CliService {
/**
* @param array $info
*/
- public function onInfoUpdated($info) {
+ public function onInfoUpdated(array $info) {
if ($this->display === null) {
return;
}
@@ -216,3 +233,4 @@ class CliService {
}
}
+
diff --git a/lib/Service/ConfigService.php b/lib/Service/ConfigService.php
index 8462831..00ccbd0 100644
--- a/lib/Service/ConfigService.php
+++ b/lib/Service/ConfigService.php
@@ -1,4 +1,7 @@
<?php
+declare(strict_types=1);
+
+
/**
* FullTextSearch - Full text search framework for Nextcloud
*
@@ -24,21 +27,31 @@
*
*/
+
namespace OCA\FullTextSearch\Service;
+
use OCA\FullTextSearch\AppInfo\Application;
use OCA\FullTextSearch\Exceptions\ProviderOptionsDoesNotExistException;
use OCP\IConfig;
use OCP\PreConditionNotMetException;
use OCP\Util;
+
+/**
+ * Class ConfigService
+ *
+ * @package OCA\FullTextSearch\Service
+ */
class ConfigService {
+
const APP_NAVIGATION = 'app_navigation';
const SEARCH_PLATFORM = 'search_platform';
const PROVIDER_INDEXED = 'provider_indexed';
const CRON_LAST_ERR_RESET = 'cron_err_reset';
+
/** @var array */
public $defaults = [
self::SEARCH_PLATFORM => '',
@@ -47,6 +60,7 @@ class ConfigService {
self::CRON_LAST_ERR_RESET => '0'
];
+
/** @var IConfig */
private $config;
@@ -64,9 +78,7 @@ class ConfigService {
* @param string $userId
* @param MiscService $miscService
*/
- public function __construct(
- IConfig $config, $userId, MiscService $miscService
- ) {
+ public function __construct(IConfig $config, $userId, MiscService $miscService) {
$this->config = $config;
$this->userId = $userId;
$this->miscService = $miscService;
@@ -76,7 +88,7 @@ class ConfigService {
/**
* @return array
*/
- public function getConfig() {
+ public function getConfig(): array {
$keys = array_keys($this->defaults);
$data = [];
@@ -91,7 +103,7 @@ class ConfigService {
/**
* @param array $save
*/
- public function setConfig($save) {
+ public function setConfig(array $save) {
$keys = array_keys($this->defaults);
foreach ($keys as $k) {
@@ -105,11 +117,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', '');
}
@@ -121,7 +133,7 @@ class ConfigService {
*
* @return string
*/
- public function getAppValue($key) {
+ public function getAppValue(string $key): string {
$defaultValue = null;
if (array_key_exists($key, $this->defaults)) {
$defaultValue = $this->defaults[$key];
@@ -135,10 +147,8 @@ class ConfigService {
*
* @param string $key
* @param string $value
- *
- * @return void
*/
- public function setAppValue($key, $value) {
+ public function setAppValue(string $key, string $value) {
$this->config->setAppValue(Application::APP_NAME, $key, $value);
}
@@ -146,11 +156,9 @@ class ConfigService {
* remove a key
*
* @param string $key
- *
- * @return string
*/
- public function deleteAppValue($key) {
- return $this->config->deleteAppValue(Application::APP_NAME, $key);
+ public function deleteAppValue(string $key) {
+ $this->config->deleteAppValue(Application::APP_NAME, $key);
}
/**
@@ -160,7 +168,7 @@ class ConfigService {
*
* @return string
*/
- public function getUserValue($key) {
+ public function getUserValue(string $key): string {
$defaultValue = null;
if (array_key_exists($key, $this->defaults)) {
$defaultValue = $this->defaults[$key];
@@ -177,11 +185,10 @@ class ConfigService {
* @param string $key
* @param string $value
*
- * @return string
* @throws PreConditionNotMetException
*/
- public function setUserValue($key, $value) {
- return $this->config->setUserValue($this->userId, Application::APP_NAME, $key, $value);
+ public function setUserValue(string $key, string $value) {
+ $this->config->setUserValue($this->userId, Application::APP_NAME, $key, $value);
}
/**
@@ -192,7 +199,7 @@ class ConfigService {
*
* @return string
*/
- public function getValueForUser($userId, $key) {
+ public function getValueForUser(string $userId, string $key) {
return $this->config->getUserValue($userId, Application::APP_NAME, $key);
}
@@ -203,11 +210,10 @@ class ConfigService {
* @param string $key
* @param string $value
*
- * @return string
* @throws PreConditionNotMetException
*/
- public function setValueForUser($userId, $key, $value) {
- return $this->config->setUserValue($userId, Application::APP_NAME, $key, $value);
+ public function setValueForUser(string $userId, string $key, string $value) {
+ $this->config->setUserValue($userId, Application::APP_NAME, $key, $value);
}
@@ -216,7 +222,7 @@ class ConfigService {
* @param string $options
* @param string $value
*/
- public function setProviderOptions($providerId, $options, $value) {
+ public function setProviderOptions(string $providerId, string $options, string $value) {
$arr = json_decode($this->getAppValue($options), true);
if ($arr === null) {
$arr = [];
@@ -231,7 +237,7 @@ class ConfigService {
/**
* @param string $options
*/
- public function resetProviderOptions($options) {
+ public function resetProviderOptions(string $options) {
$this->setAppValue($options, '');
}
@@ -243,7 +249,7 @@ class ConfigService {
* @return string
* @throws ProviderOptionsDoesNotExistException
*/
- public function getProviderOptions($providerId, $options) {
+ public function getProviderOptions(string $providerId, string $options): string {
$arr = json_decode($this->getAppValue($options), true);
if ($arr === null) {
$arr = [];
@@ -259,19 +265,12 @@ class ConfigService {
/**
* return the cloud version.
- * if $complete is true, return a string x.y.z
- *
- * @param boolean $complete
*
- * @return string|integer
+ * @return int
*/
- public function getCloudVersion($complete = false) {
+ public function getCloudVersion(): int {
$ver = Util::getVersion();
- if ($complete) {
- return implode('.', $ver);
- }
-
return $ver[0];
}
}
diff --git a/lib/Service/IndexService.php b/lib/Service/IndexService.php
index 85564cb..fd37629 100644
--- a/lib/Service/IndexService.php
+++ b/lib/Service/IndexService.php
@@ -1,4 +1,7 @@
<?php
+declare(strict_types=1);
+
+
/**
* FullTextSearch - Full text search framework for Nextcloud
*
@@ -24,25 +27,35 @@
*
*/
+
namespace OCA\FullTextSearch\Service;
+
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
+ *
+ * @package OCA\FullTextSearch\Service
+ */
+class IndexService implements IIndexService {
-class IndexService {
/** @var IndexesRequest */
private $indexesRequest;
@@ -105,7 +118,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 +129,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 +144,7 @@ class IndexService {
/**
* @param array $data
*/
- private function updateRunnerInfoArray($data) {
+ private function updateRunnerInfoArray(array $data) {
if ($this->runner === null) {
return;
}
@@ -144,19 +159,20 @@ class IndexService {
* @param string $userId
* @param IndexOptions $options
*
- * @throws InterruptException
- * @throws TickDoesNotExistException
* @throws Exception
*/
public function indexProviderContentFromUser(
- IFullTextSearchPlatform $platform, IFullTextSearchProvider $provider, $userId, $options
+ IFullTextSearchPlatform $platform, IFullTextSearchProvider $provider, string $userId,
+ IndexOptions $options
) {
$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,28 +196,28 @@ 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
- ) {
-
- $currIndex = $this->getProviderIndexFromProvider($provider);
+ IFullTextSearchProvider $provider, array $documents, IIndexOptions $options
+ ): array {
+ $currIndex = $this->getProviderIndexFromProvider($provider->getId());
$result = [];
$count = 0;
foreach ($documents as $document) {
if ($count % 1000 === 0) {
$this->updateRunnerAction('compareWithCurrentIndex', true);
- $this->updateRunnerInfo('documentCurrent', $count);
+ $this->updateRunnerInfo('documentCurrent', (string)$count);
}
$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();
@@ -211,13 +227,13 @@ class IndexService {
continue;
}
- if ($options->getOption('force', false) === true) {
+ if ($options->getOptionBool('force', false) === true) {
$index->setStatus(Index::INDEX_FULL);
}
$index->resetErrors();
$document->setIndex($index);
- if ($options->getOption('force', false) === true
+ if ($options->getOptionBool('force', false) === true
|| !$this->isDocumentUpToDate($provider, $document)) {
$result[] = $document;
}
@@ -234,7 +250,7 @@ class IndexService {
* @return bool
*/
private function isDocumentUpToDate(IFullTextSearchProvider $provider, IndexDocument $document
- ) {
+ ): bool {
$index = $document->getIndex();
if (!$index->isStatus(Index::INDEX_OK)) {
@@ -250,12 +266,12 @@ class IndexService {
/**
- * @param IFullTextSearchProvider $provider
+ * @param string $providerId
*
* @return ProviderIndexes
*/
- private function getProviderIndexFromProvider(IFullTextSearchProvider $provider) {
- $indexes = $this->indexesRequest->getIndexesFromProvider($provider);
+ private function getProviderIndexFromProvider(string $providerId): ProviderIndexes {
+ $indexes = $this->indexesRequest->getIndexesFromProvider($providerId);
return new ProviderIndexes($indexes);
}
@@ -270,7 +286,7 @@ class IndexService {
* @throws Exception
*/
private function indexDocuments(
- IFullTextSearchPlatform $platform, IFullTextSearchProvider $provider, $documents,
+ IFullTextSearchPlatform $platform, IFullTextSearchProvider $provider, array $documents,
IndexOptions $options
) {
while ($document = array_shift($documents)) {
@@ -302,15 +318,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 +351,13 @@ 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, IndexDocument $document
+ ): IIndex {
$this->updateRunnerAction('indexDocument', true);
$this->updateRunnerInfoArray(
[
@@ -356,13 +367,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;
}
@@ -371,7 +383,6 @@ class IndexService {
* @param IFullTextSearchProvider $provider
* @param Index $index
*
- * @internal param int|string $documentId
* @throws Exception
*/
public function updateDocument(
@@ -411,7 +422,7 @@ class IndexService {
$document->getIndex()
->resetErrors();
- $index = $platform->indexDocument($provider, $document);
+ $index = $platform->indexDocument($document);
$this->updateIndex($index);
}
@@ -421,7 +432,7 @@ class IndexService {
*
* @throws DatabaseException
*/
- public function updateIndexes($indexes) {
+ public function updateIndexes(array $indexes) {
try {
foreach ($indexes as $index) {
$this->updateIndex($index);
@@ -434,16 +445,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 +466,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,8 +476,39 @@ class IndexService {
}
- private function updateIndexError(Index $index) {
+ /**
+ * @param IIndex $index
+ */
+ private function updateIndexError(IIndex $index) {
+
+ }
+
+
+ /**
+ * @param string $providerId
+ * @param string $documentId
+ * @param int $status
+ * @param bool $reset
+ *
+ * @throws Exception
+ */
+ public function updateIndexStatus(
+ string $providerId, string $documentId, int $status, bool $reset = false
+ ) {
+ if ($reset === true) {
+ $this->indexesRequest->updateStatus($providerId, $documentId, $status);
+
+ return;
+ }
+ try {
+ $curr = $this->getIndex($providerId, $documentId);
+ } catch (IndexDoesNotExistException $e) {
+ return;
+ }
+
+ $curr->setStatus($status);
+ $this->updateIndex($curr);
}
@@ -477,9 +520,11 @@ 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);
+ $this->indexesRequest->updateStatuses($providerId, $documentIds, $status);
return;
}
@@ -494,7 +539,6 @@ class IndexService {
$curr->setStatus($status);
$this->updateIndexes([$curr]);
}
-
}
@@ -526,9 +570,9 @@ class IndexService {
/**
- * @return ExtendedIndex[]
+ * @return Index[]
*/
- public function getErrorIndexes() {
+ public function getErrorIndexes(): array {
return $this->indexesRequest->getErrorIndexes();
}
@@ -537,7 +581,7 @@ class IndexService {
* @param string $providerId
* @param array $documentId
*
- * @return ExtendedIndex[]
+ * @return Index[]
* @throws IndexDoesNotExistException
*/
public function getIndexes($providerId, $documentId) {
@@ -550,7 +594,7 @@ class IndexService {
*
* @return Index[]
*/
- public function getQueuedIndexes($all = false) {
+ public function getQueuedIndexes(bool $all = false): array {
return $this->indexesRequest->getQueuedIndexes($all);
}
@@ -560,7 +604,7 @@ class IndexService {
*
* @throws Exception
*/
- public function resetIndex($providerId = '') {
+ public function resetIndex(string $providerId = '') {
$wrapper = $this->platformService->getPlatform();
$platform = $wrapper->getPlatform();
@@ -587,4 +631,16 @@ 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);
+ }
+
+
}
diff --git a/lib/Service/MiscService.php b/lib/Service/MiscService.php
index c5b0d34..8927fc8 100644
--- a/lib/Service/MiscService.php
+++ b/lib/Service/MiscService.php
@@ -1,4 +1,7 @@
<?php
+declare(strict_types=1);
+
+
/**
* FullTextSearch - Full text search framework for Nextcloud
*
@@ -24,82 +27,47 @@
*
*/
+
namespace OCA\FullTextSearch\Service;
+
use OCA\FullTextSearch\AppInfo\Application;
use OCP\ILogger;
-use OCP\Util;
+
+/**
+ * Class MiscService
+ *
+ * @package OCA\FullTextSearch\Service
+ */
class MiscService {
/** @var ILogger */
private $logger;
- public function __construct(ILogger $logger) {
- $this->logger = $logger;
- }
-
- public function log($message, $level = 2) {
- $data = array(
- 'app' => Application::APP_NAME,
- 'level' => $level
- );
-
- $this->logger->log($level, $message, $data);
- }
/**
- * @param $arr
- * @param $k
+ * MiscService constructor.
*
- * @param string $default
- *
- * @return array|string|integer
+ * @param ILogger $logger
*/
- public static function get($k, $arr, $default = '') {
- if ($arr === null) {
- return $default;
- }
-
- if (!key_exists($k, $arr)) {
- return $default;
- }
-
- return $arr[$k];
- }
-
-
- public static function noEndSlash($path) {
- if (substr($path, -1) === '/') {
- $path = substr($path, 0, -1);
- }
-
- return $path;
+ public function __construct(ILogger $logger) {
+ $this->logger = $logger;
}
/**
- * @param string $time
- *
- * @return float
+ * @param string $message
+ * @param int $level
*/
- public static function getMicroTime($time) {
- list($usec, $sec) = explode(' ', $time);
-
- return ((float)$usec + (float)$sec);
- }
-
+ public function log(string $message, int $level = 2) {
+ $data = array(
+ 'app' => Application::APP_NAME,
+ 'level' => $level
+ );
- public function addJavascript() {
- Util::addStyle(Application::APP_NAME, 'fulltextsearch');
- Util::addScript(Application::APP_NAME, 'fulltextsearch.v1.api');
- Util::addScript(Application::APP_NAME, 'fulltextsearch.v1.settings');
- Util::addScript(Application::APP_NAME, 'fulltextsearch.v1.searchbox');
- Util::addScript(Application::APP_NAME, 'fulltextsearch.v1.result');
- Util::addScript(Application::APP_NAME, 'fulltextsearch.v1.navigation');
- Util::addScript(Application::APP_NAME, 'fulltextsearch.v1');
+ $this->logger->log($level, $message, $data);
}
-
}
diff --git a/lib/Service/PlatformService.php b/lib/Service/PlatformService.php
index 3962681..4738f80 100644
--- a/lib/Service/PlatformService.php
+++ b/lib/Service/PlatformService.php
@@ -1,4 +1,7 @@
<?php
+declare(strict_types=1);
+
+
/**
* FullTextSearch - Full text search framework for Nextcloud
*
@@ -24,19 +27,28 @@
*
*/
+
namespace OCA\FullTextSearch\Service;
+
use Exception;
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
+ *
+ * @package OCA\FullTextSearch\Service
+ */
class PlatformService {
+
/** @var AppManager */
private $appManager;
@@ -62,7 +74,6 @@ class PlatformService {
* @param AppManager $appManager
* @param ConfigService $configService
* @param MiscService $miscService
- *
*/
public function __construct(
AppManager $appManager, ConfigService $configService, MiscService $miscService
@@ -80,7 +91,7 @@ class PlatformService {
* @return PlatformWrapper
* @throws Exception
*/
- public function getPlatform($silent = false) {
+ public function getPlatform(bool $silent = false): PlatformWrapper {
try {
$this->loadPlatform();
} catch (Exception $e) {
@@ -98,7 +109,7 @@ class PlatformService {
* @return PlatformWrapper[]
* @throws Exception
*/
- public function getPlatforms() {
+ public function getPlatforms(): array {
$this->loadPlatforms();
$platforms = [];
@@ -161,7 +172,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 +188,7 @@ class PlatformService {
* @throws PlatformDoesNotExistException
* @throws PlatformNotSelectedException
*/
- private function getSelectedPlatform() {
+ private function getSelectedPlatform(): PlatformWrapper {
$selected = $this->configService->getAppValue(ConfigService::SEARCH_PLATFORM);
if ($selected === '') {
@@ -201,7 +212,7 @@ class PlatformService {
/**
* @param string $appId
*/
- private function loadPlatformsFromApp($appId) {
+ private function loadPlatformsFromApp(string $appId) {
$appInfo = $this->appManager->getAppInfo($appId);
if (!is_array($appInfo) || !key_exists('fulltextsearch', $appInfo)
|| !key_exists('platform', $appInfo['fulltextsearch'])) {
diff --git a/lib/Service/ProviderService.php b/lib/Service/ProviderService.php
index 692e0bb..6cb5608 100644
--- a/lib/Service/ProviderService.php
+++ b/lib/Service/ProviderService.php
@@ -1,4 +1,7 @@
<?php
+declare(strict_types=1);
+
+
/**
* FullTextSearch - Full text search framework for Nextcloud
*
@@ -24,19 +27,31 @@
*
*/
+
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
+ *
+ * @package OCA\FullTextSearch\Service
+ */
+class ProviderService implements IProviderService {
-class ProviderService {
/** @var AppManager */
private $appManager;
@@ -60,7 +75,6 @@ class ProviderService {
* @param AppManager $appManager
* @param ConfigService $configService
* @param MiscService $miscService
- *
*/
public function __construct(
AppManager $appManager, ConfigService $configService, MiscService $miscService
@@ -102,7 +116,7 @@ class ProviderService {
* @throws ProviderIsNotUniqueException
* @throws QueryException
*/
- public function loadProvider($appId, $providerId) {
+ public function loadProvider(string $appId, string $providerId) {
$provider = \OC::$server->query((string)$providerId);
if (!($provider instanceof IFullTextSearchProvider)) {
@@ -127,7 +141,7 @@ class ProviderService {
* @return ProviderWrapper[]
* @throws Exception
*/
- public function getProviders() {
+ public function getProviders(): array {
$this->loadProviders();
return $this->providers;
@@ -137,7 +151,7 @@ class ProviderService {
* @return IFullTextSearchProvider[]
* @throws Exception
*/
- public function getConfiguredProviders() {
+ public function getConfiguredProviders(): array {
$this->loadProviders();
$providers = [];
@@ -159,7 +173,7 @@ class ProviderService {
* @throws Exception
* @throws ProviderDoesNotExistException
*/
- public function getFilteredProviders($providerList) {
+ public function getFilteredProviders(array $providerList): array {
$this->loadProviders();
$providers = $this->getConfiguredProviders();
@@ -186,7 +200,7 @@ class ProviderService {
* @throws Exception
* @throws ProviderDoesNotExistException
*/
- public function getProvider($providerId) {
+ public function getProvider(string $providerId): ProviderWrapper {
$providers = $this->getProviders();
foreach ($providers as $providerWrapper) {
@@ -205,7 +219,7 @@ class ProviderService {
*
* @return bool
*/
- public function isProviderIndexed($providerId) {
+ public function isProviderIndexed(string $providerId): bool {
try {
$indexed = $this->configService->getProviderOptions(
$providerId, ConfigService::PROVIDER_INDEXED
@@ -223,13 +237,20 @@ class ProviderService {
}
- public function setProviderAsIndexed(IFullTextSearchProvider $provider, $boolean) {
+ /**
+ * @param IFullTextSearchProvider $provider
+ * @param bool $boolean
+ */
+ public function setProviderAsIndexed(IFullTextSearchProvider $provider, bool $boolean) {
$this->configService->setProviderOptions(
$provider->getId(), ConfigService::PROVIDER_INDEXED, (($boolean) ? '1' : '0')
);
}
+ /**
+ *
+ */
public function setProvidersAsNotIndexed() {
$this->configService->resetProviderOptions(ConfigService::PROVIDER_INDEXED);
}
@@ -242,7 +263,7 @@ class ProviderService {
* @throws ProviderIsNotUniqueException
* @throws QueryException
*/
- private function loadProvidersFromApp($appId) {
+ private function loadProvidersFromApp(string $appId) {
$appInfo = $this->appManager->getAppInfo($appId);
if (!is_array($appInfo) || !key_exists('fulltextsearch', $appInfo)
|| !key_exists('provider', $appInfo['fulltextsearch'])) {
@@ -250,19 +271,23 @@ class ProviderService {
}
$providers = $appInfo['fulltextsearch']['provider'];
+ if (!is_array($providers)) {
+ $providers = [$providers];
+ }
+
$this->loadProvidersFromList($appId, $providers);
}
/**
* @param string $appId
- * @param string|array $providers
+ * @param array $providers
*
* @throws ProviderIsNotCompatibleException
* @throws ProviderIsNotUniqueException
* @throws QueryException
*/
- private function loadProvidersFromList($appId, $providers) {
+ private function loadProvidersFromList(string $appId, array $providers) {
if (!is_array($providers)) {
$providers = [$providers];
}
@@ -296,7 +321,7 @@ class ProviderService {
*
* @return array
*/
- public function serialize($providers) {
+ public function serialize(array $providers): array {
$arr = [];
foreach ($providers as $provider) {
$arr[] = [
@@ -308,4 +333,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..a182f0b 100644
--- a/lib/Service/RunningService.php
+++ b/lib/Service/RunningService.php
@@ -1,4 +1,7 @@
<?php
+declare(strict_types=1);
+
+
/**
* FullTextSearch - Full text search framework for Nextcloud
*
@@ -24,17 +27,26 @@
*
*/
+
namespace OCA\FullTextSearch\Service;
+
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
+ *
+ * @package OCA\FullTextSearch\Service
+ */
class RunningService {
+
/** @var TickRequest */
private $tickRequest;
@@ -62,23 +74,23 @@ class RunningService {
/**
- * @param $source
+ * @param string $source
*
* @return int
* @throws RunnerAlreadyUpException
* @throws \Exception
*/
- public function start($source) {
+ public function start(string $source): int {
if ($this->isAlreadyRunning()) {
throw new RunnerAlreadyUpException('Index is already running');
}
- $tick = new ExtendedTick($source);
+ $tick = new Tick($source);
$tick->setStatus('run')
->setTick()
->setFirstTick()
- ->setInfo('runStart ', time());
+ ->setInfoInt('runStart ', time());
return $this->tickRequest->create($tick);
}
@@ -91,7 +103,7 @@ class RunningService {
* @throws TickDoesNotExistException
* @throws TickIsNotAliveException
*/
- public function update($runId, $action = '') {
+ public function update(int $runId, string $action = '') {
$tick = $this->tickRequest->getTickById($runId);
$this->isStillAlive($tick, true);
@@ -107,11 +119,12 @@ class RunningService {
/**
* @deprecated - verifier l'interet !
+ *
* @param int $runId
* @param string $reason
* @param bool $stop
*/
- public function exception($runId, $reason, $stop = false) {
+ public function exception(int $runId, string $reason, bool $stop = false) {
if ($stop) {
try {
$this->stop($runId, $reason);
@@ -129,12 +142,12 @@ class RunningService {
*
* @throws TickDoesNotExistException
*/
- public function stop($runId, $reason = '') {
+ public function stop(int $runId, string $reason = '') {
$tick = $this->tickRequest->getTickById($runId);
$tick->setStatus('stop')
->setTick()
- ->setInfo('runStop', time())
- ->setInfo('totalDocuments', 42);
+ ->setInfoInt('runStop', time())
+ ->setInfoInt('totalDocuments', 42);
if ($reason !== '') {
$tick->setStatus('exception');
@@ -146,12 +159,12 @@ class RunningService {
/**
- * @param $runId
+ * @param int $runId
*
* @return bool
* @throws TickIsNotAliveException
*/
- public function isAlive($runId) {
+ public function isAlive(int $runId): bool {
$tick = null;
try {
$tick = $this->tickRequest->getTickById($runId);
@@ -164,13 +177,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, bool $exception = false): bool {
if ($tick->getStatus() !== 'run') {
if ($exception) {
throw new TickIsNotAliveException();
@@ -186,8 +199,8 @@ class RunningService {
/**
* @return bool
*/
- public function isAlreadyRunning() {
- $ticks = $this->tickRequest->getTickByStatus('run');
+ public function isAlreadyRunning(): bool {
+ $ticks = $this->tickRequest->getTicksByStatus('run');
$isAlreadyRunning = false;
foreach ($ticks as $tick) {
@@ -207,7 +220,7 @@ class RunningService {
*
*/
public function forceStop() {
- $ticks = $this->tickRequest->getTickByStatus('run');
+ $ticks = $this->tickRequest->getTicksByStatus('run');
foreach ($ticks as $tick) {
$tick->setStatus('forceStop');
@@ -217,27 +230,27 @@ class RunningService {
/**
- * @param ExtendedTick $tick
+ * @param Tick $tick
* @param string $action
*/
- private function assignActionToTick(ExtendedTick &$tick, $action) {
+ private function assignActionToTick(Tick &$tick, string $action) {
$now = microtime(true);
$preAction = $tick->getAction();
if ($preAction !== '') {
- $preActionTotal = $tick->getInfo($preAction . 'Total', 0);
- $preActionStart = $tick->getInfo($preAction . 'Init', 0);
+ $preActionTotal = $tick->getInfoFloat($preAction . 'Total', 0);
+ $preActionStart = $tick->getInfoFloat($preAction . 'Init', 0);
if ($preActionStart > 0) {
$preActionTotal += ($now - $preActionStart);
- $tick->setInfo($preAction . 'Total', $preActionTotal);
+ $tick->setInfoFloat($preAction . 'Total', $preActionTotal);
$tick->unsetInfo($preAction . 'Init');
}
}
$tick->setAction($action)
- ->setInfo($action . 'Init', $now);
+ ->setInfoFloat($action . 'Init', $now);
}
-} \ No newline at end of file
+}
diff --git a/lib/Service/SearchService.php b/lib/Service/SearchService.php
index 5552b5c..2761f01 100644
--- a/lib/Service/SearchService.php
+++ b/lib/Service/SearchService.php
@@ -1,4 +1,7 @@
<?php
+declare(strict_types=1);
+
+
/**
* FullTextSearch - Full text search framework for Nextcloud
*
@@ -24,25 +27,36 @@
*
*/
+
namespace OCA\FullTextSearch\Service;
+
use Exception;
use OC\App\AppManager;
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
+ *
+ * @package OCA\FullTextSearch\Service
+ */
+class SearchService implements ISearchService {
+
/** @var string */
private $userId;
@@ -70,7 +84,7 @@ class SearchService {
/**
- * IndexService constructor.
+ * SearchService constructor.
*
* @param string $userId
* @param AppManager $appManager
@@ -82,7 +96,8 @@ class SearchService {
* @param MiscService $miscService
*/
public function __construct(
- $userId, AppManager $appManager, IUserManager $userManager, IGroupManager $groupManager,
+ $userId, AppManager $appManager, IUserManager $userManager,
+ IGroupManager $groupManager,
ConfigService $configService, ProviderService $providerService,
PlatformService $platformService,
MiscService $miscService
@@ -99,18 +114,32 @@ class SearchService {
/**
+ * @param array $request
+ *
+ * @return ISearchRequest
+ */
+ public function generateSearchRequest(array $request): ISearchRequest {
+ $searchRequest = new SearchRequest();
+ $searchRequest->importFromArray($request);
+
+ return $searchRequest;
+ }
+
+
+ /**
* @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 +148,7 @@ class SearchService {
throw new NoUserException('User does not exist');
}
+ /** @var $request SearchRequest */
$request->setAuthor($user->getUID());
$request->cleanSearch();
@@ -139,11 +169,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,12 +186,12 @@ class SearchService {
* @param IFullTextSearchProvider[] $providers
* @param SearchRequest $request
*
- * @return SearchResult[]
+ * @return ISearchResult[]
*/
private function searchFromProviders(
- IFullTextSearchPlatform $platform, $providers, DocumentAccess $access,
+ IFullTextSearchPlatform $platform, array $providers, DocumentAccess $access,
SearchRequest $request
- ) {
+ ): array {
$result = [];
foreach ($providers AS $provider) {
$provider->improveSearchRequest($request);
@@ -185,7 +215,7 @@ class SearchService {
*
* @return DocumentAccess
*/
- private function getDocumentAccessFromUser(IUser $user) {
+ private function getDocumentAccessFromUser(IUser $user): DocumentAccess {
$rights = new DocumentAccess();
$rights->setViewerId($user->getUID());
diff --git a/lib/Service/SettingsService.php b/lib/Service/SettingsService.php
index 939db0f..e6b7353 100644
--- a/lib/Service/SettingsService.php
+++ b/lib/Service/SettingsService.php
@@ -1,4 +1,7 @@
<?php
+declare(strict_types=1);
+
+
/**
* FullTextSearch - Full text search framework for Nextcloud
*
@@ -24,12 +27,21 @@
*
*/
+
namespace OCA\FullTextSearch\Service;
+
use Exception;
+
+/**
+ * Class SettingsService
+ *
+ * @package OCA\FullTextSearch\Service
+ */
class SettingsService {
+
/** @var PlatformService */
private $platformService;
@@ -39,6 +51,7 @@ class SettingsService {
/** @var MiscService */
private $miscService;
+
/**
* SettingsService constructor.
*
@@ -57,11 +70,11 @@ class SettingsService {
/**
- * @param $data
+ * @param array $data
*
* @return bool
*/
- public function checkConfig($data) {
+ public function checkConfig(array $data): bool {
return true;
}
@@ -71,7 +84,7 @@ class SettingsService {
*
* @throws Exception
*/
- public function completeSettings(&$data) {
+ public function completeSettings(array &$data) {
$data = array_merge(
$data, [
'platforms_all' => $this->completeSettingsPlatforms(),
@@ -86,7 +99,7 @@ class SettingsService {
* @return array
* @throws Exception
*/
- private function completeSettingsPlatforms() {
+ private function completeSettingsPlatforms(): array {
$list = [];
$platforms = $this->platformService->getPlatforms();
foreach ($platforms as $wrapper) {
@@ -105,7 +118,7 @@ class SettingsService {
* @return array
* @throws Exception
*/
- private function completeSettingsProviders() {
+ private function completeSettingsProviders(): array {
$list = [];
$providers = $this->providerService->getProviders();
foreach ($providers as $providerWrapper) {
diff --git a/lib/Service/TestService.php b/lib/Service/TestService.php
index 2954a99..469933a 100644
--- a/lib/Service/TestService.php
+++ b/lib/Service/TestService.php
@@ -1,4 +1,7 @@
<?php
+declare(strict_types=1);
+
+
/**
* FullTextSearch - Full text search framework for Nextcloud
*
@@ -24,13 +27,21 @@
*
*/
+
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
+ *
+ * @package OCA\FullTextSearch\Service
+ */
class TestService {
const DOCUMENT_USER1 = 'user1';
@@ -65,11 +76,11 @@ class TestService {
/**
- * @param IndexOptions $options
+ * @param IIndexOptions $options
*
* @return IndexDocument
*/
- public function generateIndexDocumentContentLicense(IndexOptions $options = null) {
+ public function generateIndexDocumentContentLicense(IIndexOptions $options): IndexDocument {
$indexDocument = $this->generateIndexDocument(self::DOCUMENT_TYPE_LICENSE);
$content = file_get_contents(__DIR__ . '/../../LICENSE');
@@ -92,11 +103,11 @@ class TestService {
/**
- * @param IndexOptions $options
+ * @param IIndexOptions $options
*
* @return IndexDocument
*/
- public function generateIndexDocumentSimple(IndexOptions $options) {
+ public function generateIndexDocumentSimple(IIndexOptions $options): IndexDocument {
$indexDocument = $this->generateIndexDocument(self::DOCUMENT_TYPE_SIMPLE);
$indexDocument->setContent('document is a simple test');
@@ -141,7 +152,7 @@ class TestService {
*
* @return IndexDocument
*/
- private function generateIndexDocument($documentType) {
+ private function generateIndexDocument(string $documentType): IndexDocument {
$indexDocument = new IndexDocument(TestProvider::TEST_PROVIDER_ID, $documentType);
$access = new DocumentAccess(self::DOCUMENT_USER1);
diff --git a/lib/Settings/Admin.php b/lib/Settings/Admin.php
index 3ab45dc..23c9b47 100644
--- a/lib/Settings/Admin.php
+++ b/lib/Settings/Admin.php
@@ -1,4 +1,7 @@
<?php
+declare(strict_types=1);
+
+
/**
* FullTextSearch - Full text search framework for Nextcloud
*
@@ -24,8 +27,10 @@
*
*/
+
namespace OCA\FullTextSearch\Settings;
+
use Exception;
use OCA\FullTextSearch\AppInfo\Application;
use OCA\FullTextSearch\Service\ConfigService;
@@ -35,6 +40,12 @@ use OCP\IL10N;
use OCP\IURLGenerator;
use OCP\Settings\ISettings;
+
+/**
+ * Class Admin
+ *
+ * @package OCA\FullTextSearch\Settings
+ */
class Admin implements ISettings {
/** @var IL10N */
@@ -57,7 +68,8 @@ class Admin implements ISettings {
* @param MiscService $miscService
*/
public function __construct(
- IL10N $l10n, IURLGenerator $urlGenerator, ConfigService $configService, MiscService $miscService
+ IL10N $l10n, IURLGenerator $urlGenerator, ConfigService $configService,
+ MiscService $miscService
) {
$this->l10n = $l10n;
$this->urlGenerator = $urlGenerator;
@@ -70,7 +82,7 @@ class Admin implements ISettings {
* @return TemplateResponse
* @throws Exception
*/
- public function getForm() {
+ public function getForm(): TemplateResponse {
return new TemplateResponse(Application::APP_NAME, 'settings.admin', []);
}
@@ -78,7 +90,7 @@ class Admin implements ISettings {
/**
* @return string the section ID, e.g. 'sharing'
*/
- public function getSection() {
+ public function getSection(): string {
return Application::APP_NAME;
}
@@ -90,7 +102,7 @@ class Admin implements ISettings {
*
* keep the server setting at the top, right after "server settings"
*/
- public function getPriority() {
+ public function getPriority(): int {
return 0;
}
diff --git a/lib/Settings/AdminSection.php b/lib/Settings/AdminSection.php
index 9365477..ed8d487 100644
--- a/lib/Settings/AdminSection.php
+++ b/lib/Settings/AdminSection.php
@@ -1,4 +1,7 @@
<?php
+declare(strict_types=1);
+
+
/**
* FullTextSearch - Full text search framework for Nextcloud
*
@@ -21,24 +24,34 @@
*
* 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\Settings;
+
use OCA\FullTextSearch\AppInfo\Application;
use OCP\IL10N;
use OCP\IURLGenerator;
use OCP\Settings\IIconSection;
+
+/**
+ * Class AdminSection
+ *
+ * @package OCA\FullTextSearch\Settings
+ */
class AdminSection implements IIconSection {
+
/** @var IL10N */
private $l10n;
/** @var IURLGenerator */
private $urlGenerator;
+
/**
* @param IL10N $l10n
* @param IURLGenerator $urlGenerator
@@ -51,28 +64,28 @@ class AdminSection implements IIconSection {
/**
* {@inheritdoc}
*/
- public function getID() {
+ public function getID(): string {
return Application::APP_NAME;
}
/**
* {@inheritdoc}
*/
- public function getName() {
+ public function getName(): string {
return $this->l10n->t('Full text search');
}
/**
* {@inheritdoc}
*/
- public function getPriority() {
+ public function getPriority(): int {
return 55;
}
/**
* {@inheritdoc}
*/
- public function getIcon() {
+ public function getIcon(): string {
return $this->urlGenerator->imagePath(Application::APP_NAME, 'fulltextsearch_black.svg');
}
}