1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* FullTextSearch - Full text search framework for Nextcloud |
4
|
|
|
* |
5
|
|
|
* This file is licensed under the Affero General Public License version 3 or |
6
|
|
|
* later. See the COPYING file. |
7
|
|
|
* |
8
|
|
|
* @author Maxence Lange <[email protected]> |
9
|
|
|
* @copyright 2018 |
10
|
|
|
* @license GNU AGPL version 3 or any later version |
11
|
|
|
* |
12
|
|
|
* This program is free software: you can redistribute it and/or modify |
13
|
|
|
* it under the terms of the GNU Affero General Public License as |
14
|
|
|
* published by the Free Software Foundation, either version 3 of the |
15
|
|
|
* License, or (at your option) any later version. |
16
|
|
|
* |
17
|
|
|
* This program is distributed in the hope that it will be useful, |
18
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
19
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
20
|
|
|
* GNU Affero General Public License for more details. |
21
|
|
|
* |
22
|
|
|
* You should have received a copy of the GNU Affero General Public License |
23
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
24
|
|
|
* |
25
|
|
|
*/ |
26
|
|
|
|
27
|
|
|
namespace OCA\FullTextSearch\Command; |
28
|
|
|
|
29
|
|
|
use Exception; |
30
|
|
|
use OCA\FullTextSearch\Model\ExtendedBase; |
31
|
|
|
use OCA\FullTextSearch\Service\ConfigService; |
32
|
|
|
use OCA\FullTextSearch\Service\MiscService; |
33
|
|
|
use OCA\FullTextSearch\Service\PlatformService; |
34
|
|
|
use OCA\FullTextSearch\Service\ProviderService; |
35
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
36
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
37
|
|
|
|
38
|
|
|
|
39
|
|
|
class Check extends ExtendedBase { |
40
|
|
|
|
41
|
|
|
const CYCLE_DELAY = 10; |
42
|
|
|
|
43
|
|
|
|
44
|
|
|
/** @var ConfigService */ |
45
|
|
|
private $configService; |
46
|
|
|
|
47
|
|
|
/** @var PlatformService */ |
48
|
|
|
private $platformService; |
49
|
|
|
|
50
|
|
|
/** @var ProviderService */ |
51
|
|
|
private $providerService; |
52
|
|
|
|
53
|
|
|
/** @var MiscService */ |
54
|
|
|
private $miscService; |
55
|
|
|
|
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* Index constructor. |
59
|
|
|
* |
60
|
|
|
* @param ConfigService $configService |
61
|
|
|
* @param PlatformService $platformService |
62
|
|
|
* @param ProviderService $providerService |
63
|
|
|
* @param MiscService $miscService |
64
|
|
|
*/ |
65
|
|
View Code Duplication |
public function __construct( |
|
|
|
|
66
|
|
|
ConfigService $configService, PlatformService $platformService, |
67
|
|
|
ProviderService $providerService, MiscService $miscService |
68
|
|
|
) { |
69
|
|
|
parent::__construct(); |
70
|
|
|
|
71
|
|
|
$this->configService = $configService; |
72
|
|
|
$this->platformService = $platformService; |
73
|
|
|
$this->providerService = $providerService; |
74
|
|
|
$this->miscService = $miscService; |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* |
80
|
|
|
*/ |
81
|
|
|
protected function configure() { |
82
|
|
|
parent::configure(); |
83
|
|
|
$this->setName('fulltextsearch:check') |
84
|
|
|
->setDescription('Check the installation'); |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* @param InputInterface $input |
90
|
|
|
* @param OutputInterface $output |
91
|
|
|
* |
92
|
|
|
* @return int|null|void |
93
|
|
|
* @throws Exception |
94
|
|
|
*/ |
95
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) { |
96
|
|
|
|
97
|
|
|
$output->writeln( |
98
|
|
|
'Full text search ' . $this->configService->getAppValue('installed_version') |
99
|
|
|
); |
100
|
|
|
$output->writeln(' '); |
101
|
|
|
|
102
|
|
|
$this->displayPlatform($output); |
103
|
|
|
$this->displayProviders($output); |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
|
107
|
|
|
/** |
108
|
|
|
* @param OutputInterface $output |
109
|
|
|
* |
110
|
|
|
* @throws Exception |
111
|
|
|
*/ |
112
|
|
|
private function displayPlatform(OutputInterface $output) { |
113
|
|
|
try { |
114
|
|
|
$platform = $this->platformService->getPlatform(); |
115
|
|
|
} catch (Exception $e) { |
116
|
|
|
$output->writeln('No search platform available'); |
117
|
|
|
|
118
|
|
|
return; |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
$output->writeln('- Search Platform:'); |
122
|
|
|
|
123
|
|
|
$output->writeln($platform->getName() . ' ' . $platform->getVersion()); |
124
|
|
|
echo json_encode($platform->getConfiguration(), JSON_PRETTY_PRINT); |
125
|
|
|
|
126
|
|
|
$output->writeln(' '); |
127
|
|
|
$output->writeln(' '); |
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
|
131
|
|
|
/** |
132
|
|
|
* @param OutputInterface $output |
133
|
|
|
* |
134
|
|
|
* @throws Exception |
135
|
|
|
*/ |
136
|
|
|
private function displayProviders(OutputInterface $output) { |
137
|
|
|
$providers = $this->providerService->getProviders(); |
138
|
|
|
|
139
|
|
|
if (sizeof($providers) === 0) { |
140
|
|
|
$output->writeln('No Content Provider available'); |
141
|
|
|
|
142
|
|
|
return; |
143
|
|
|
} |
144
|
|
|
|
145
|
|
|
$output->writeln('- Content Providers:'); |
146
|
|
|
|
147
|
|
|
foreach ($providers as $provider) { |
148
|
|
|
$output->writeln($provider->getName() . ' ' . $provider->getVersion()); |
149
|
|
|
echo json_encode($provider->getConfiguration(), JSON_PRETTY_PRINT); |
150
|
|
|
$output->writeln(''); |
151
|
|
|
} |
152
|
|
|
|
153
|
|
|
|
154
|
|
|
} |
155
|
|
|
|
156
|
|
|
|
157
|
|
|
} |
158
|
|
|
|
159
|
|
|
|
160
|
|
|
|
161
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.