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-10-03 16:08:14 +0300
committerMaxence Lange <maxence@artificial-owl.com>2018-10-03 16:08:14 +0300
commit02ce131d336e3594744dfa3e919e39f727d6fbb3 (patch)
tree582977b5d2fa6d2da7cc687e05494c6e967bd8bb /lib
parentf677307eaedbd2e87610fa5655429a8690c269c0 (diff)
using PlatformWrapper to manage Platform around
Signed-off-by: Maxence Lange <maxence@artificial-owl.com>
Diffstat (limited to 'lib')
-rw-r--r--lib/Command/Check.php16
-rw-r--r--lib/Command/DocumentPlatform.php3
-rw-r--r--lib/Command/Index.php8
-rw-r--r--lib/Command/Live.php3
-rw-r--r--lib/Command/Test.php4
-rw-r--r--lib/Cron/Index.php4
-rw-r--r--lib/IFullTextSearchPlatform.php8
-rw-r--r--lib/Model/PlatformWrapper.php142
-rw-r--r--lib/Service/IndexService.php3
-rw-r--r--lib/Service/PlatformService.php48
-rw-r--r--lib/Service/SearchService.php5
-rw-r--r--lib/Service/SettingsService.php7
12 files changed, 207 insertions, 44 deletions
diff --git a/lib/Command/Check.php b/lib/Command/Check.php
index 9097bc6..8b3aca1 100644
--- a/lib/Command/Check.php
+++ b/lib/Command/Check.php
@@ -115,13 +115,12 @@ class Check extends ExtendedBase {
try {
$platforms = $this->platformService->getPlatforms();
- $ak = array_keys($platforms);
- foreach ($ak as $k) {
- $platform = $platforms[$k];
+ foreach ($platforms as $platformWrapper) {
+ $platform = $platformWrapper->getPlatform();
$platform->loadPlatform();
- $resultPlatform[$platform->getId()] = [
- 'class' => $k,
- 'version' => $platform->getVersion(),
+ $resultPlatform[] = [
+ 'class' => $platformWrapper->getClass(),
+ 'version' => $platformWrapper->getVersion(),
'config' => $platform->getConfiguration()
];
}
@@ -164,7 +163,8 @@ class Check extends ExtendedBase {
*/
private function displayPlatform(OutputInterface $output) {
try {
- $platform = $this->platformService->getPlatform();
+ $wrapper = $this->platformService->getPlatform();
+ $platform = $wrapper->getPlatform();
} catch (Exception $e) {
$output->writeln('No search platform available');
@@ -173,7 +173,7 @@ class Check extends ExtendedBase {
$output->writeln('- Search Platform:');
- $output->writeln($platform->getName() . ' ' . $platform->getVersion());
+ $output->writeln($platform->getName() . ' ' . $wrapper->getVersion());
echo json_encode($platform->getConfiguration(), JSON_PRETTY_PRINT);
$output->writeln(' ');
diff --git a/lib/Command/DocumentPlatform.php b/lib/Command/DocumentPlatform.php
index b64d4e8..72315e0 100644
--- a/lib/Command/DocumentPlatform.php
+++ b/lib/Command/DocumentPlatform.php
@@ -84,7 +84,8 @@ class DocumentPlatform extends ExtendedBase {
$providerId = $input->getArgument('providerId');
$documentId = $input->getArgument('documentId');
- $platform = $this->platformService->getPlatform();
+ $wrapper = $this->platformService->getPlatform();
+ $platform = $wrapper->getPlatform();
$indexDocument = $platform->getDocument($providerId, $documentId);
$result = [
diff --git a/lib/Command/Index.php b/lib/Command/Index.php
index ac7952b..2697a81 100644
--- a/lib/Command/Index.php
+++ b/lib/Command/Index.php
@@ -350,7 +350,9 @@ class Index extends ExtendedBase {
* @throws Exception
*/
private function testPlatform() {
- $platform = $this->platformService->getPlatform();
+ $wrapper = $this->platformService->getPlatform();
+ $platform = $wrapper->getPlatform();
+
if (!$platform->testPlatform()) {
throw new Exception('failed platform test.');
}
@@ -364,7 +366,9 @@ class Index extends ExtendedBase {
* @throws Exception
*/
private function indexProvider(IFullTextSearchProvider $provider, IndexOptions $options) {
- $platform = $this->platformService->getPlatform();
+ $wrapper = $this->platformService->getPlatform();
+ $platform = $wrapper->getPlatform();
+
$platform->initializeIndex();
$provider->onInitializingIndex($platform);
diff --git a/lib/Command/Live.php b/lib/Command/Live.php
index 5c5aac9..f750e18 100644
--- a/lib/Command/Live.php
+++ b/lib/Command/Live.php
@@ -243,7 +243,8 @@ class Live extends ExtendedBase {
*/
private function liveCycle() {
- $platform = $this->platformService->getPlatform();
+ $wrapper = $this->platformService->getPlatform();
+ $platform = $wrapper->getPlatform();
$platform->setRunner($this->runner);
while (true) {
diff --git a/lib/Command/Test.php b/lib/Command/Test.php
index 7bf375b..f560b25 100644
--- a/lib/Command/Test.php
+++ b/lib/Command/Test.php
@@ -270,7 +270,9 @@ class Test extends ExtendedBase {
*/
private function testLoadingPlatform($output) {
$this->output($output, 'Loading search platform.');
- $testPlatform = $this->platformService->getPlatform();
+ $wrapper = $this->platformService->getPlatform();
+ $testPlatform = $wrapper->getPlatform();
+
$this->output($output, '(' . $testPlatform->getName() . ')', false);
$this->output($output, true);
diff --git a/lib/Cron/Index.php b/lib/Cron/Index.php
index bd78d8f..c4b2965 100644
--- a/lib/Cron/Index.php
+++ b/lib/Cron/Index.php
@@ -109,7 +109,9 @@ class Index extends TimedJob {
*/
private function liveCycle() {
- $platform = $this->platformService->getPlatform(true);
+ $wrapper = $this->platformService->getPlatform(true);
+ $platform = $wrapper->getPlatform();
+
$all = $this->shouldWeGetAllIndex();
$indexes = $this->indexService->getQueuedIndexes($all);
diff --git a/lib/IFullTextSearchPlatform.php b/lib/IFullTextSearchPlatform.php
index 4bf6256..947394f 100644
--- a/lib/IFullTextSearchPlatform.php
+++ b/lib/IFullTextSearchPlatform.php
@@ -51,12 +51,6 @@ interface IFullTextSearchPlatform {
/**
- * @return string
- */
- public function getVersion();
-
-
- /**
* @return array
*/
public function getConfiguration();
@@ -154,4 +148,4 @@ interface IFullTextSearchPlatform {
// * @return IndexDocument
// */
// public function getDocument($providerId, $documentId);
-} \ No newline at end of file
+}
diff --git a/lib/Model/PlatformWrapper.php b/lib/Model/PlatformWrapper.php
new file mode 100644
index 0000000..2bcccbb
--- /dev/null
+++ b/lib/Model/PlatformWrapper.php
@@ -0,0 +1,142 @@
+<?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 OCA\FullTextSearch\IFullTextSearchPlatform;
+
+
+/**
+ * Class PlatformWrapper
+ *
+ * @package OCA\FullTextSearch\Model
+ */
+class PlatformWrapper {
+
+
+ /** @var string */
+ private $appId;
+
+ /** @var string */
+ private $class;
+
+ /** @var IFullTextSearchPlatform */
+ private $platform;
+
+ /** @var string */
+ private $version;
+
+
+ /**
+ * Provider constructor.
+ *
+ * @param string $appId
+ * @param IFullTextSearchPlatform $platform
+ */
+ public function __construct($appId, $class) {
+ $this->appId = $appId;
+ $this->class = $class;
+ }
+
+ /**
+ * @return string
+ */
+ public function getAppId() {
+ return $this->appId;
+ }
+
+ /**
+ * @param string $appId
+ *
+ * @return PlatformWrapper
+ */
+ public function setAppId($appId) {
+ $this->appId = $appId;
+
+ return $this;
+ }
+
+
+ /**
+ * @return string
+ */
+ public function getClass() {
+ return $this->class;
+ }
+
+ /**
+ * @param string $class
+ *
+ * @return PlatformWrapper
+ */
+ public function setClass($class) {
+ $this->class = $class;
+
+ return $this;
+ }
+
+
+ /**
+ * @return IFullTextSearchPlatform
+ */
+ public function getPlatform() {
+ return $this->platform;
+ }
+
+ /**
+ * @param IFullTextSearchPlatform $platform
+ *
+ * @return PlatformWrapper
+ */
+ public function setPlatform($platform) {
+ $this->platform = $platform;
+
+ return $this;
+ }
+
+
+ /**
+ * @return string
+ */
+ public function getVersion() {
+ return $this->version;
+ }
+
+ /**
+ * @param string $version
+ *
+ * @return PlatformWrapper
+ */
+ public function setVersion($version) {
+ $this->version = $version;
+
+ return $this;
+ }
+
+
+}
diff --git a/lib/Service/IndexService.php b/lib/Service/IndexService.php
index eb00109..7821a7d 100644
--- a/lib/Service/IndexService.php
+++ b/lib/Service/IndexService.php
@@ -558,7 +558,8 @@ class IndexService {
* @throws Exception
*/
public function resetIndex($providerId = '') {
- $platform = $this->platformService->getPlatform();
+ $wrapper = $this->platformService->getPlatform();
+ $platform = $wrapper->getPlatform();
if ($providerId === '') {
$platform->resetIndex('all');
diff --git a/lib/Service/PlatformService.php b/lib/Service/PlatformService.php
index 304116d..3962681 100644
--- a/lib/Service/PlatformService.php
+++ b/lib/Service/PlatformService.php
@@ -32,6 +32,7 @@ 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;
class PlatformService {
@@ -45,10 +46,10 @@ class PlatformService {
/** @var MiscService */
private $miscService;
- /** @var array */
+ /** @var PlatformWrapper[] */
private $platforms = [];
- /** @var IFullTextSearchPlatform */
+ /** @var PlatformWrapper */
private $platform;
/** @var bool */
@@ -76,7 +77,7 @@ class PlatformService {
/**
* @param bool $silent
*
- * @return IFullTextSearchPlatform
+ * @return PlatformWrapper
* @throws Exception
*/
public function getPlatform($silent = false) {
@@ -94,18 +95,20 @@ class PlatformService {
/**
- * @return IFullTextSearchPlatform[]
+ * @return PlatformWrapper[]
* @throws Exception
*/
public function getPlatforms() {
$this->loadPlatforms();
$platforms = [];
- foreach ($this->platforms as $class) {
+ foreach ($this->platforms as $wrapper) {
+ $class = $wrapper->getClass();
try {
$platform = \OC::$server->query((string)$class);
if ($platform instanceof IFullTextSearchPlatform) {
- $platforms[$class] = $platform;
+ $wrapper->setPlatform($platform);
+ $platforms[] = $wrapper;
}
} catch (QueryException $e) {
/** we cycle */
@@ -155,7 +158,7 @@ class PlatformService {
$this->loadPlatforms();
$selected = $this->getSelectedPlatform();
- $platform = \OC::$server->query((string)$selected);
+ $platform = \OC::$server->query((string)$selected->getClass());
if (!($platform instanceof IFullTextSearchPlatform)) {
throw new PlatformIsNotCompatibleException(
$selected . ' is not a compatible FullTextSearchPlatform'
@@ -163,12 +166,14 @@ class PlatformService {
}
$platform->loadPlatform();
- $this->platform = $platform;
+ $selected->setPlatform($platform);
+
+ $this->platform = $selected;
}
/**
- * @return string
+ * @return PlatformWrapper
* @throws PlatformDoesNotExistException
* @throws PlatformNotSelectedException
*/
@@ -176,16 +181,20 @@ class PlatformService {
$selected = $this->configService->getAppValue(ConfigService::SEARCH_PLATFORM);
if ($selected === '') {
- throw new PlatformNotSelectedException('Admin have not selected any IFullTextSearchPlatform');
+ throw new PlatformNotSelectedException(
+ 'Admin have not selected any IFullTextSearchPlatform'
+ );
}
- if (!in_array($selected, $this->platforms)) {
- throw new PlatformDoesNotExistException(
- 'FullTextSearchPlatform ' . $selected . ' is not available'
- );
+ foreach ($this->platforms as $wrapper) {
+ if ($wrapper->getClass() === $selected) {
+ return $wrapper;
+ }
}
- return $selected;
+ throw new PlatformDoesNotExistException(
+ 'FullTextSearchPlatform ' . $selected . ' is not available'
+ );
}
@@ -204,7 +213,14 @@ class PlatformService {
$platforms = [$platforms];
}
- $this->platforms = array_merge($this->platforms, $platforms);
+ $wrappers = [];
+ foreach ($platforms as $class) {
+ $wrapper = new PlatformWrapper($appId, $class);
+ $wrapper->setVersion($this->configService->getAppVersion($appId));
+ $wrappers[] = $wrapper;
+ }
+
+ $this->platforms = array_merge($this->platforms, $wrappers);
}
diff --git a/lib/Service/SearchService.php b/lib/Service/SearchService.php
index 3912139..5552b5c 100644
--- a/lib/Service/SearchService.php
+++ b/lib/Service/SearchService.php
@@ -123,7 +123,8 @@ class SearchService {
$request->cleanSearch();
$providers = $this->providerService->getFilteredProviders($request->getProviders());
- $platform = $this->platformService->getPlatform();
+ $wrapper = $this->platformService->getPlatform();
+ $platform = $wrapper->getPlatform();
$access = $this->getDocumentAccessFromUser($user);
$result = $this->searchFromProviders($platform, $providers, $access, $request);
@@ -202,4 +203,4 @@ class SearchService {
}
-} \ No newline at end of file
+}
diff --git a/lib/Service/SettingsService.php b/lib/Service/SettingsService.php
index 917e987..b887346 100644
--- a/lib/Service/SettingsService.php
+++ b/lib/Service/SettingsService.php
@@ -89,10 +89,9 @@ class SettingsService {
private function completeSettingsPlatforms() {
$list = [];
$platforms = $this->platformService->getPlatforms();
- $classes = array_keys($platforms);
- foreach ($classes as $class) {
- $platform = $platforms[$class];
- $list[$class] = [
+ foreach ($platforms as $wrapper) {
+ $platform = $wrapper->getPlatform();
+ $list[$wrapper->getClass()] = [
'id' => $platform->getId(),
'name' => $platform->getName()
];