-
Notifications
You must be signed in to change notification settings - Fork 26
Expand file tree
/
Copy pathConfigController.php
More file actions
45 lines (37 loc) · 1.22 KB
/
Copy pathConfigController.php
File metadata and controls
45 lines (37 loc) · 1.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
<?php
declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2023 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCA\AppAPI\Controller;
use OCA\AppAPI\AppInfo\Application;
use OCP\AppFramework\Controller;
use OCP\AppFramework\Http\Attribute\NoCSRFRequired;
use OCP\AppFramework\Http\DataResponse;
use OCP\IAppConfig;
use OCP\IRequest;
class ConfigController extends Controller {
public function __construct(
string $appName,
IRequest $request,
private readonly IAppConfig $appConfig,
) {
parent::__construct($appName, $request);
}
#[NoCSRFRequired]
public function setAdminConfig(array $values): DataResponse {
foreach ($values as $key => $value) {
// Preserve native types so bool/int settings (e.g. image cleanup) round-trip
// correctly through getValueBool/getValueInt on the read side.
if (is_bool($value)) {
$this->appConfig->setValueBool(Application::APP_ID, $key, $value, lazy: true);
} elseif (is_int($value)) {
$this->appConfig->setValueInt(Application::APP_ID, $key, $value, lazy: true);
} else {
$this->appConfig->setValueString(Application::APP_ID, $key, (string)$value, lazy: true);
}
}
return new DataResponse(1);
}
}