diff options
author | Maxence Lange <maxence@artificial-owl.com> | 2018-10-03 16:04:50 +0300 |
---|---|---|
committer | Maxence Lange <maxence@artificial-owl.com> | 2018-10-03 16:04:50 +0300 |
commit | f677307eaedbd2e87610fa5655429a8690c269c0 (patch) | |
tree | c82275a511017a330c7cf9f757135623ecdc7b73 | |
parent | da3b449169bc0ce0c6c2e2bb06f1d971234e536d (diff) |
using a ProviderWrapper to manage Provider around
Signed-off-by: Maxence Lange <maxence@artificial-owl.com>
-rw-r--r-- | lib/Command/Check.php | 10 | ||||
-rw-r--r-- | lib/Command/DocumentProvider.php | 5 | ||||
-rw-r--r-- | lib/Command/Index.php | 3 | ||||
-rw-r--r-- | lib/Command/Live.php | 4 | ||||
-rw-r--r-- | lib/Command/Test.php | 7 | ||||
-rw-r--r-- | lib/Controller/TemplatesController.php | 14 | ||||
-rw-r--r-- | lib/IFullTextSearchProvider.php | 18 | ||||
-rw-r--r-- | lib/Model/ProviderWrapper.php | 120 | ||||
-rw-r--r-- | lib/Model/SearchResult.php | 8 | ||||
-rw-r--r-- | lib/Provider/TestProvider.php | 18 | ||||
-rw-r--r-- | lib/Service/ConfigService.php | 12 | ||||
-rw-r--r-- | lib/Service/IndexService.php | 5 |
12 files changed, 168 insertions, 56 deletions
diff --git a/lib/Command/Check.php b/lib/Command/Check.php index e016ed9..9097bc6 100644 --- a/lib/Command/Check.php +++ b/lib/Command/Check.php @@ -133,9 +133,10 @@ class Check extends ExtendedBase { $resultProviders = []; try { $providers = $this->providerService->getProviders(); - foreach ($providers as $provider) { + foreach ($providers as $providerWrapper) { + $provider = $providerWrapper->getProvider(); $resultProviders[$provider->getId()] = [ - 'version' => $provider->getVersion(), + 'version' => $providerWrapper->getVersion(), 'config' => $provider->getConfiguration() ]; } @@ -196,8 +197,9 @@ class Check extends ExtendedBase { $output->writeln('- Content Providers:'); - foreach ($providers as $provider) { - $output->writeln($provider->getName() . ' ' . $provider->getVersion()); + foreach ($providers as $providerWrapper) { + $provider = $providerWrapper->getProvider(); + $output->writeln($provider->getName() . ' ' . $providerWrapper->getVersion()); echo json_encode($provider->getConfiguration(), JSON_PRETTY_PRINT); $output->writeln(''); } diff --git a/lib/Command/DocumentProvider.php b/lib/Command/DocumentProvider.php index c672f81..583efc1 100644 --- a/lib/Command/DocumentProvider.php +++ b/lib/Command/DocumentProvider.php @@ -89,7 +89,8 @@ class DocumentProvider extends ExtendedBase { $documentId = $input->getArgument('documentId'); $userId = $input->getArgument('userId'); - $provider = $this->providerService->getProvider($providerId); + $providerWrapper = $this->providerService->getProvider($providerId); + $provider = $providerWrapper->getProvider(); $index = new Index($providerId, $documentId); $index->setOwnerId($userId); @@ -99,7 +100,7 @@ class DocumentProvider extends ExtendedBase { ->isStatus(Index::INDEX_REMOVE)) { throw new Exception('Unknown document'); } - + $output->writeln('Document: '); $output->writeln(json_encode($indexDocument, JSON_PRETTY_PRINT)); diff --git a/lib/Command/Index.php b/lib/Command/Index.php index 40e6c6c..ac7952b 100644 --- a/lib/Command/Index.php +++ b/lib/Command/Index.php @@ -237,7 +237,8 @@ class Index extends ExtendedBase { $this->displayResult(); $providers = $this->providerService->getProviders(); - foreach ($providers as $provider) { + foreach ($providers as $providerWrapper) { + $provider = $providerWrapper->getProvider(); if (!$this->isIncludedProvider($options, $provider->getId())) { continue; diff --git a/lib/Command/Live.php b/lib/Command/Live.php index 513b656..5c5aac9 100644 --- a/lib/Command/Live.php +++ b/lib/Command/Live.php @@ -254,7 +254,9 @@ class Live extends ExtendedBase { $this->runner->updateAction('indexing'); try { - $provider = $this->providerService->getProvider($index->getProviderId()); + $providerWrapper = $this->providerService->getProvider($index->getProviderId()); + $provider = $providerWrapper->getProvider(); + $provider->setRunner($this->runner); $this->indexService->updateDocument($platform, $provider, $index); } catch (Exception $e) { diff --git a/lib/Command/Test.php b/lib/Command/Test.php index c227b99..7bf375b 100644 --- a/lib/Command/Test.php +++ b/lib/Command/Test.php @@ -187,9 +187,12 @@ class Test extends ExtendedBase { * @throws ProviderIsNotUniqueException */ private function generateMockProvider() { - $this->providerService->loadProvider('OCA\FullTextSearch\Provider\TestProvider'); + $this->providerService->loadProvider( + 'fulltextsearch', 'OCA\FullTextSearch\Provider\TestProvider' + ); + $providerWrapper = $this->providerService->getProvider(TestProvider::TEST_PROVIDER_ID); - return $this->providerService->getProvider(TestProvider::TEST_PROVIDER_ID); + return $providerWrapper->getProvider(); } diff --git a/lib/Controller/TemplatesController.php b/lib/Controller/TemplatesController.php index 9cec6d8..9aea5c7 100644 --- a/lib/Controller/TemplatesController.php +++ b/lib/Controller/TemplatesController.php @@ -30,6 +30,7 @@ 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; @@ -86,7 +87,8 @@ class TemplatesController extends Controller { * @throws ProviderDoesNotExistException */ public function getOptionsPanel($providerId) { - $provider = $this->providerService->getProvider($providerId); + $providerWrapper = $this->providerService->getProvider($providerId); + $provider = $providerWrapper->getProvider(); $panel = []; $options = $provider->getOptionsTemplate(); @@ -95,7 +97,8 @@ class TemplatesController extends Controller { } if (array_key_exists('template', $panel)) { - $tmpl = new TemplateResponse($provider->getAppId(), $panel['template'], [], 'blank'); + $tmpl = + new TemplateResponse($providerWrapper->getAppId(), $panel['template'], [], 'blank'); $panel['template'] = $tmpl->render(); } @@ -116,8 +119,9 @@ class TemplatesController extends Controller { $providers = $this->providerService->getProviders(); $ret = []; - foreach ($providers as $provider) { - $providerAppId = $provider->getAppId(); + foreach ($providers as $providerWrapper) { + $provider = $providerWrapper->getProvider(); + $providerAppId = $providerWrapper->getAppId(); $options = $provider->getOptionsTemplate(); $nav = []; @@ -137,4 +141,4 @@ class TemplatesController extends Controller { } -}
\ No newline at end of file +} diff --git a/lib/IFullTextSearchProvider.php b/lib/IFullTextSearchProvider.php index 7d73229..91c4c42 100644 --- a/lib/IFullTextSearchProvider.php +++ b/lib/IFullTextSearchProvider.php @@ -46,14 +46,6 @@ interface IFullTextSearchProvider { /** - * return a appId of the Provider - * - * @return string - */ - public function getAppId(); - - - /** * return a display name of the Provider * * @return string @@ -62,14 +54,6 @@ interface IFullTextSearchProvider { /** - * return a display version of the Provider - * - * @return string - */ - public function getVersion(); - - - /** * @return array */ public function getConfiguration(); @@ -180,4 +164,4 @@ interface IFullTextSearchProvider { */ public function unloadProvider(); -}
\ No newline at end of file +} diff --git a/lib/Model/ProviderWrapper.php b/lib/Model/ProviderWrapper.php new file mode 100644 index 0000000..866c58c --- /dev/null +++ b/lib/Model/ProviderWrapper.php @@ -0,0 +1,120 @@ +<?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\IFullTextSearchProvider; + + +/** + * Class ProviderWrapper + * + * @package OCA\FullTextSearch\Model + */ +class ProviderWrapper { + + + /** @var string */ + private $appId; + + /** @var IFullTextSearchProvider */ + private $provider; + + /** @var string */ + private $version; + + + /** + * Provider constructor. + * + * @param string $appId + * @param IFullTextSearchProvider $provider + */ + public function __construct($appId, $provider) { + $this->appId = $appId; + $this->provider = $provider; + } + + /** + * @return string + */ + public function getAppId() { + return $this->appId; + } + + /** + * @param string $appId + * + * @return ProviderWrapper + */ + public function setAppId($appId) { + $this->appId = $appId; + + return $this; + } + + + /** + * @return IFullTextSearchProvider + */ + public function getProvider() { + return $this->provider; + } + + /** + * @param IFullTextSearchProvider $provider + * + * @return ProviderWrapper + */ + public function setProvider($provider) { + $this->provider = $provider; + + return $this; + } + + + /** + * @return string + */ + public function getVersion() { + return $this->version; + } + + /** + * @param string $version + * + * @return ProviderWrapper + */ + public function setVersion($version) { + $this->version = $version; + + return $this; + } + + +} diff --git a/lib/Model/SearchResult.php b/lib/Model/SearchResult.php index 9b33a17..e985fc3 100644 --- a/lib/Model/SearchResult.php +++ b/lib/Model/SearchResult.php @@ -231,8 +231,7 @@ class SearchResult implements \JsonSerializable { if ($providerObj !== null) { $provider = [ 'id' => $providerObj->getId(), - 'name' => $providerObj->getName(), - 'version' => $providerObj->getVersion() + 'name' => $providerObj->getName() ]; } @@ -241,8 +240,7 @@ class SearchResult implements \JsonSerializable { if ($platformObj !== null) { $platform = [ 'id' => $platformObj->getId(), - 'name' => $platformObj->getName(), - 'version' => $platformObj->getVersion() + 'name' => $platformObj->getName() ]; } @@ -260,4 +258,4 @@ class SearchResult implements \JsonSerializable { ] ]; } -}
\ No newline at end of file +} diff --git a/lib/Provider/TestProvider.php b/lib/Provider/TestProvider.php index 3880893..1deeb11 100644 --- a/lib/Provider/TestProvider.php +++ b/lib/Provider/TestProvider.php @@ -96,14 +96,6 @@ class TestProvider implements IFullTextSearchProvider { /** - * @return string - */ - public function getVersion() { - return $this->configService->getAppValue('installed_version'); - } - - - /** * @return array */ public function getConfiguration() { @@ -111,14 +103,6 @@ class TestProvider implements IFullTextSearchProvider { } - /** - * @return string - */ - public function getAppId() { - return Application::APP_NAME; - } - - public function setRunner(Runner $runner) { $this->runner = $runner; } @@ -253,4 +237,4 @@ class TestProvider implements IFullTextSearchProvider { } -}
\ No newline at end of file +} diff --git a/lib/Service/ConfigService.php b/lib/Service/ConfigService.php index cac5dd3..d0aab26 100644 --- a/lib/Service/ConfigService.php +++ b/lib/Service/ConfigService.php @@ -103,6 +103,18 @@ class ConfigService { /** + * Get a version of an app + * + * @param string $key + * + * @return string + */ + public function getAppVersion($appId) { + return $this->config->getAppValue($appId, 'installed_version', ''); + } + + + /** * Get a value by key * * @param string $key diff --git a/lib/Service/IndexService.php b/lib/Service/IndexService.php index a0b7db5..eb00109 100644 --- a/lib/Service/IndexService.php +++ b/lib/Service/IndexService.php @@ -567,7 +567,8 @@ class IndexService { return; } else { - $providers = [$this->providerService->getProvider($providerId)]; + $providerWrapper = $this->providerService->getProvider($providerId); + $providers = [$providerWrapper->getProvider()]; } foreach ($providers AS $provider) { @@ -582,4 +583,4 @@ class IndexService { } -}
\ No newline at end of file +} |