KEA Setup
This commit is contained in:
@@ -28,10 +28,39 @@ $defaults = $module['db_defaults'] ?? [];
|
||||
if (empty($current['db']) && is_array($defaults)) {
|
||||
$current['db'] = $defaults;
|
||||
}
|
||||
$metadataDefaults = $module['metadata_db_defaults'] ?? [];
|
||||
if (empty($current['metadata_db']) && is_array($metadataDefaults)) {
|
||||
$current['metadata_db'] = $metadataDefaults;
|
||||
}
|
||||
|
||||
$setNested = function (array &$target, string $path, mixed $value): void {
|
||||
$parts = explode('.', $path);
|
||||
$last = array_pop($parts);
|
||||
$node = &$target;
|
||||
foreach ($parts as $part) {
|
||||
if (!isset($node[$part]) || !is_array($node[$part])) {
|
||||
$node[$part] = [];
|
||||
}
|
||||
$node = &$node[$part];
|
||||
}
|
||||
if ($last !== null && $last !== '') {
|
||||
$node[$last] = $value;
|
||||
}
|
||||
};
|
||||
|
||||
$getNested = function (array $source, string $path): mixed {
|
||||
$node = $source;
|
||||
foreach (explode('.', $path) as $part) {
|
||||
if (!is_array($node) || !array_key_exists($part, $node)) {
|
||||
return null;
|
||||
}
|
||||
$node = $node[$part];
|
||||
}
|
||||
return $node;
|
||||
};
|
||||
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
$payload = [];
|
||||
$db = $current['db'] ?? [];
|
||||
|
||||
foreach ($fields as $field) {
|
||||
$name = (string)($field['name'] ?? '');
|
||||
@@ -55,19 +84,14 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (str_starts_with($name, 'db.')) {
|
||||
$key = substr($name, 3);
|
||||
$db[$key] = $value;
|
||||
if (str_contains($name, '.')) {
|
||||
$setNested($payload, $name, $value);
|
||||
continue;
|
||||
}
|
||||
|
||||
$payload[$name] = $value;
|
||||
}
|
||||
|
||||
if (!empty($db)) {
|
||||
$payload['db'] = $db;
|
||||
}
|
||||
|
||||
modules()->saveSettings($moduleName, $payload);
|
||||
modules()->saveAuth($moduleName, [
|
||||
'required' => isset($_POST['auth_required']),
|
||||
@@ -107,9 +131,8 @@ $authConfig = is_array($module['auth'] ?? null) ? $module['auth'] : ['required'
|
||||
$value = '';
|
||||
if ($name === 'kea_auto_init') {
|
||||
$value = !empty($current[$name]) ? '1' : '0';
|
||||
} elseif (str_starts_with($name, 'db.')) {
|
||||
$key = substr($name, 3);
|
||||
$value = (string)($current['db'][$key] ?? '');
|
||||
} elseif (str_contains($name, '.')) {
|
||||
$value = (string)($getNested($current, $name) ?? '');
|
||||
} else {
|
||||
$value = (string)($current[$name] ?? '');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user