Completed
Push — master ( 2566be...2cb116 )
by Maxence
01:40 queued 10s
created

Configure   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 59
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 1
dl 0
loc 59
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A configure() 0 6 1
A execute() 0 20 4
1
<?php
2
declare(strict_types=1);
3
4
5
/**
6
 * FullTextSearch_Elasticsearch - Use Elasticsearch to index the content of your nextcloud
7
 *
8
 * This file is licensed under the Affero General Public License version 3 or
9
 * later. See the COPYING file.
10
 *
11
 * @author Maxence Lange <[email protected]>
12
 * @copyright 2018
13
 * @license GNU AGPL version 3 or any later version
14
 *
15
 * This program is free software: you can redistribute it and/or modify
16
 * it under the terms of the GNU Affero General Public License as
17
 * published by the Free Software Foundation, either version 3 of the
18
 * License, or (at your option) any later version.
19
 *
20
 * This program is distributed in the hope that it will be useful,
21
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
23
 * GNU Affero General Public License for more details.
24
 *
25
 * You should have received a copy of the GNU Affero General Public License
26
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
27
 *
28
 */
29
30
31
namespace OCA\FullTextSearch_Elasticsearch\Command;
32
33
34
use Exception;
35
use OC\Core\Command\Base;
36
use OCA\FullTextSearch_Elasticsearch\Service\ConfigService;
37
use Symfony\Component\Console\Input\InputArgument;
38
use Symfony\Component\Console\Input\InputInterface;
39
use Symfony\Component\Console\Output\OutputInterface;
40
41
42
/**
43
 * Class Configure
44
 *
45
 * @package OCA\FullTextSearch_Elasticsearch\Command
46
 */
47
class Configure extends Base {
48
49
50
	/** @var ConfigService */
51
	private $configService;
52
53
54
	/**
55
	 * Configure constructor.
56
	 *
57
	 * @param ConfigService $configService
58
	 */
59
	public function __construct(ConfigService $configService) {
60
		parent::__construct();
61
62
		$this->configService = $configService;
63
	}
64
65
66
	/**
67
	 *
68
	 */
69
	protected function configure() {
70
		parent::configure();
71
		$this->setName('fulltextsearch_elasticsearch:configure')
72
			 ->addArgument('json', InputArgument::REQUIRED, 'set config')
73
			 ->setDescription('Configure the installation');
74
	}
75
76
77
	/**
78
	 * @param InputInterface $input
79
	 * @param OutputInterface $output
80
	 *
81
	 * @throws Exception
82
	 */
83
	protected function execute(InputInterface $input, OutputInterface $output) {
84
		$json = $input->getArgument('json');
85
86
		$config = json_decode($json, true);
87
88
		if ($config === null) {
89
			$output->writeln('Invalid JSON');
90
91
			return;
92
		}
93
94
		$ak = array_keys($config);
95
		foreach ($ak as $k) {
96
			if (array_key_exists($k, $this->configService->defaults)) {
97
				$this->configService->setAppValue($k, $config[$k]);
98
			}
99
		}
100
101
		$output->writeln(json_encode($this->configService->getConfig(), JSON_PRETTY_PRINT));
102
	}
103
104
105
}
106
107