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

SettingsController::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 9
rs 9.9666
c 0
b 0
f 0
cc 1
nc 1
nop 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\Controller;
32
33
34
use Exception;
35
use OCA\FullTextSearch_Elasticsearch\AppInfo\Application;
36
use OCA\FullTextSearch_Elasticsearch\Service\ConfigService;
37
use OCA\FullTextSearch_Elasticsearch\Service\MiscService;
38
use OCA\FullTextSearch_Elasticsearch\Service\SettingsService;
39
use OCP\AppFramework\Controller;
40
use OCP\AppFramework\Http;
41
use OCP\AppFramework\Http\DataResponse;
42
use OCP\IRequest;
43
44
45
/**
46
 * Class SettingsController
47
 *
48
 * @package OCA\FullTextSearch_Elasticsearch\Controller
49
 */
50
class SettingsController extends Controller {
51
52
53
	/** @var ConfigService */
54
	private $configService;
55
56
	/** @var SettingsService */
57
	private $settingsService;
58
59
	/** @var MiscService */
60
	private $miscService;
61
62
63
	/**
64
	 * SettingsController constructor.
65
	 *
66
	 * @param IRequest $request
67
	 * @param ConfigService $configService
68
	 * @param SettingsService $settingsService
69
	 * @param MiscService $miscService
70
	 */
71
	public function __construct(
72
		IRequest $request, ConfigService $configService, SettingsService $settingsService,
73
		MiscService $miscService
74
	) {
75
		parent::__construct(Application::APP_NAME, $request);
76
		$this->configService = $configService;
77
		$this->settingsService = $settingsService;
78
		$this->miscService = $miscService;
79
	}
80
81
82
	/**
83
	 * @return DataResponse
84
	 * @throws Exception
85
	 */
86
	public function getSettingsAdmin(): DataResponse {
87
		$data = $this->configService->getConfig();
88
89
		return new DataResponse($data, Http::STATUS_OK);
90
	}
91
92
93
	/**
94
	 * @param array $data
95
	 *
96
	 * @return DataResponse
97
	 * @throws Exception
98
	 */
99
	public function setSettingsAdmin(array $data): DataResponse {
100
101
		if ($this->settingsService->checkConfig($data)) {
102
			$this->configService->setConfig($data);
103
		}
104
105
		return $this->getSettingsAdmin();
106
	}
107
108
109
}
110
111