1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Nextcloud - OCR |
5
|
|
|
* This file is licensed under the Affero General Public License version 3 or |
6
|
|
|
* later. |
7
|
|
|
* See the COPYING file. |
8
|
|
|
* |
9
|
|
|
* @author Janis Koehr <[email protected]> |
10
|
|
|
* @copyright Janis Koehr 2017 |
11
|
|
|
*/ |
12
|
|
|
namespace OCA\Ocr\Controller; |
13
|
|
|
|
14
|
|
|
use OCP\AppFramework\Controller; |
15
|
|
|
use OCP\IRequest; |
16
|
|
|
use OCP\IL10N; |
17
|
|
|
use OCA\Ocr\Config\AppConfig; |
18
|
|
|
use OCP\AppFramework\Http\DataResponse; |
19
|
|
|
use OCA\Ocr\Service\AppConfigService; |
20
|
|
|
use OCA\Ocr\Service\NotFoundException; |
21
|
|
|
use OCA\Ocr\Constants\OcrConstants; |
22
|
|
|
|
23
|
|
|
|
24
|
|
|
class AdminSettingsController extends Controller { |
25
|
|
|
|
26
|
|
|
/** @var IL10N */ |
27
|
|
|
private $l10n; |
28
|
|
|
|
29
|
|
|
/** @var AppConfigService */ |
30
|
|
|
private $appConfig; |
31
|
|
|
use Errors; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* Constructor |
35
|
|
|
* |
36
|
|
|
* @param string $appName |
37
|
|
|
* @param IRequest $request |
38
|
|
|
* @param IL10N $l10n |
39
|
|
|
* @param AppConfigService $appConfig |
40
|
|
|
* @param string $userId |
41
|
|
|
*/ |
42
|
4 |
|
public function __construct($appName, IRequest $request, IL10N $l10n, AppConfigService $appConfig, $userId) { |
43
|
4 |
|
parent::__construct($appName, $request); |
44
|
4 |
|
$this->l10n = $l10n; |
45
|
4 |
|
$this->appConfig = $appConfig; |
46
|
4 |
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* @NoAdminRequired |
50
|
|
|
* |
51
|
|
|
* @return DataResponse |
52
|
|
|
*/ |
53
|
1 |
|
public function getLanguages() { |
54
|
1 |
|
return $this->handleNotFound( |
55
|
1 |
|
function () { |
56
|
|
|
return [ |
57
|
1 |
|
'languages' => $this->appConfig->getAppValue(OcrConstants::LANGUAGES_CONFIG_KEY) |
58
|
|
|
]; |
59
|
1 |
|
}); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* @NoAdminRequired |
64
|
|
|
* |
65
|
|
|
* @return DataResponse |
66
|
|
|
*/ |
67
|
1 |
|
public function evaluateRedisSettings() { |
68
|
1 |
|
return $this->handleNotFound( |
69
|
1 |
|
function () { |
70
|
|
|
return [ |
71
|
1 |
|
'set' => $this->appConfig->evaluateRedisSettings() |
72
|
|
|
]; |
73
|
1 |
|
}); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* Sets the languages that are supported by the docker worker instance. |
78
|
|
|
* |
79
|
|
|
* @param string $languages |
80
|
|
|
* @return DataResponse |
81
|
|
|
*/ |
82
|
1 |
|
public function setLanguages($languages) { |
83
|
1 |
|
return $this->handleNotFound( |
84
|
1 |
|
function () use ($languages) { |
85
|
1 |
|
$this->appConfig->setAppValue(OcrConstants::LANGUAGES_CONFIG_KEY, $languages); |
86
|
1 |
|
return $this->l10n->t('Saved'); |
87
|
1 |
|
}); |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* Sets the Redis settings. |
92
|
|
|
* |
93
|
|
|
* @param string $redisHost |
94
|
|
|
* @param string $redisPort |
95
|
|
|
* @param string $redisDb |
96
|
|
|
* @param string $redisPassword |
97
|
|
|
* @return DataResponse |
98
|
|
|
*/ |
99
|
1 |
|
public function setRedis($redisHost, $redisPort, $redisDb, $redisPassword) { |
100
|
1 |
|
return $this->handleNotFound( |
101
|
1 |
|
function () use ($redisHost, $redisPort, $redisDb, $redisPassword) { |
102
|
1 |
|
$this->appConfig->setAppValue(OcrConstants::REDIS_CONFIG_KEY_HOST, $redisHost); |
103
|
1 |
|
$this->appConfig->setAppValue(OcrConstants::REDIS_CONFIG_KEY_PORT, $redisPort); |
104
|
1 |
|
$this->appConfig->setAppValue(OcrConstants::REDIS_CONFIG_KEY_DB, $redisDb); |
105
|
1 |
|
$this->appConfig->setAppValue(OcrConstants::REDIS_CONFIG_KEY_PASSWORD, $redisPassword); |
106
|
1 |
|
return $this->l10n->t('Saved'); |
107
|
1 |
|
}); |
108
|
|
|
} |
109
|
|
|
} |