1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Bookmarks_FullTextSearch - Index bookmarks |
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\Bookmarks_FullTextSearch\Command; |
28
|
|
|
|
29
|
|
|
use Exception; |
30
|
|
|
use OC\Core\Command\Base; |
31
|
|
|
use OCA\Bookmarks_FullTextSearch\Service\ConfigService; |
32
|
|
|
use OCA\Bookmarks_FullTextSearch\Service\MiscService; |
33
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
34
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
35
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
36
|
|
|
|
37
|
|
|
|
38
|
|
|
class Configure extends Base { |
39
|
|
|
|
40
|
|
|
/** @var ConfigService */ |
41
|
|
|
private $configService; |
42
|
|
|
|
43
|
|
|
/** @var MiscService */ |
44
|
|
|
private $miscService; |
45
|
|
|
|
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* Index constructor. |
49
|
|
|
* |
50
|
|
|
* @param ConfigService $configService |
51
|
|
|
* @param MiscService $miscService |
52
|
|
|
*/ |
53
|
|
|
public function __construct(ConfigService $configService, MiscService $miscService) { |
54
|
|
|
parent::__construct(); |
55
|
|
|
|
56
|
|
|
$this->configService = $configService; |
57
|
|
|
$this->miscService = $miscService; |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* |
63
|
|
|
*/ |
64
|
|
|
protected function configure() { |
65
|
|
|
parent::configure(); |
66
|
|
|
$this->setName('bookmarks_fulltextsearch:configure') |
67
|
|
|
->addArgument('json', InputArgument::REQUIRED, 'set config') |
68
|
|
|
->setDescription('Configure the installation'); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* @param InputInterface $input |
74
|
|
|
* @param OutputInterface $output |
75
|
|
|
* |
76
|
|
|
* @return int|null|void |
77
|
|
|
* @throws Exception |
78
|
|
|
*/ |
79
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) { |
80
|
|
|
$json = $input->getArgument('json'); |
81
|
|
|
|
82
|
|
|
$config = json_decode($json, true); |
83
|
|
|
|
84
|
|
|
if ($config === null) { |
85
|
|
|
$output->writeln('Invalid JSON'); |
86
|
|
|
|
87
|
|
|
return; |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
$ak = array_keys($config); |
91
|
|
|
foreach ($ak as $k) { |
92
|
|
|
if (array_key_exists($k, $this->configService->defaults)) { |
93
|
|
|
$this->configService->setAppValue($k, $config[$k]); |
94
|
|
|
} |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
$output->writeln(json_encode($this->configService->getConfig(), JSON_PRETTY_PRINT)); |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
|
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
|
104
|
|
|
|
105
|
|
|
|