Completed
Push — master ( 81e73e...c48e81 )
by Maxence
01:56
created

Configure::configure()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 5
nc 1
nop 0
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\InputArgument;
36
use Symfony\Component\Console\Input\InputInterface;
37
use Symfony\Component\Console\Input\InputOption;
38
use Symfony\Component\Console\Output\OutputInterface;
39
40
41
class Configure extends ExtendedBase {
42
43
	const CYCLE_DELAY = 10;
44
45
46
	/** @var ConfigService */
47
	private $configService;
48
49
	/** @var PlatformService */
50
	private $platformService;
51
52
	/** @var ProviderService */
53
	private $providerService;
54
55
	/** @var MiscService */
56
	private $miscService;
57
58
59
	/**
60
	 * Index constructor.
61
	 *
62
	 * @param ConfigService $configService
63
	 * @param PlatformService $platformService
64
	 * @param ProviderService $providerService
65
	 * @param MiscService $miscService
66
	 */
67 View Code Duplication
	public function __construct(
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
68
		ConfigService $configService, PlatformService $platformService,
69
		ProviderService $providerService, MiscService $miscService
70
	) {
71
		parent::__construct();
72
73
		$this->configService = $configService;
74
		$this->platformService = $platformService;
75
		$this->providerService = $providerService;
76
		$this->miscService = $miscService;
77
	}
78
79
80
	/**
81
	 *
82
	 */
83
	protected function configure() {
84
		parent::configure();
85
		$this->setName('fulltextsearch:configure')
86
			 ->addArgument('json', InputArgument::REQUIRED, 'set config')
87
			 ->setDescription('Configure the installation');
88
	}
89
90
91
	/**
92
	 * @param InputInterface $input
93
	 * @param OutputInterface $output
94
	 *
95
	 * @return int|null|void
96
	 * @throws Exception
97
	 */
98
	protected function execute(InputInterface $input, OutputInterface $output) {
99
		$json = $input->getArgument('json');
100
101
		$config = json_decode($json, true);
102
103
		if ($config === null) {
104
			$output->writeln('Invalid JSON');
105
106
			return;
107
		}
108
109
		$ak = array_keys($config);
110
		foreach ($ak as $k) {
111
			if (array_key_exists($k, $this->configService->defaults)) {
112
				$this->configService->setAppValue($k, $config[$k]);
113
			}
114
		}
115
116
		$output->writeln(json_encode($this->configService->getConfig(), JSON_PRETTY_PRINT));
117
	}
118
119
120
}
121
122
123
124