Skip to content

Commit 84a3a2f

Browse files
Admin: Add "validation" server type to configuration settings and generalize variable processing - refs #3819
Author: @christianbeeznest
1 parent 193d447 commit 84a3a2f

File tree

3 files changed

+25
-23
lines changed

3 files changed

+25
-23
lines changed

public/main/inc/lib/api.lib.php

Lines changed: 12 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2704,59 +2704,49 @@ function api_get_setting($variable, $isArray = false, $key = null)
27042704
return '';
27052705
}
27062706
$variable = trim($variable);
2707+
// Normalize setting name: keep full name for lookup, extract short name for switch matching
2708+
$full = $variable;
2709+
$short = str_contains($variable, '.') ? substr($variable, strrpos($variable, '.') + 1) : $variable;
27072710

2708-
switch ($variable) {
2711+
switch ($short) {
27092712
case 'server_type':
2710-
$test = ['dev', 'test'];
2711-
$environment = Container::getEnvironment();
2712-
if (in_array($environment, $test)) {
2713-
return 'test';
2714-
}
2715-
2716-
return 'prod';
2717-
// deprecated settings
2718-
// no break
2713+
$settingValue = $settingsManager->getSetting($full, true);
2714+
return $settingValue ?: 'prod';
27192715
case 'openid_authentication':
27202716
case 'service_ppt2lp':
27212717
case 'formLogin_hide_unhide_label':
27222718
return false;
2723-
break;
27242719
case 'tool_visible_by_default_at_creation':
2725-
$values = $settingsManager->getSetting($variable);
2720+
$values = $settingsManager->getSetting($full);
27262721
$newResult = [];
27272722
foreach ($values as $parameter) {
27282723
$newResult[$parameter] = 'true';
27292724
}
27302725

27312726
return $newResult;
2732-
break;
2727+
27332728
default:
2734-
$settingValue = $settingsManager->getSetting($variable, true);
2735-
if (is_string($settingValue) && $isArray && !empty($settingValue)) {
2729+
$settingValue = $settingsManager->getSetting($full, true);
2730+
if (is_string($settingValue) && $isArray && $settingValue !== '') {
27362731
// Check if the value is a valid JSON string
27372732
$decodedValue = json_decode($settingValue, true);
27382733

27392734
// If it's a valid JSON string and the result is an array, return it
27402735
if (is_array($decodedValue)) {
27412736
return $decodedValue;
27422737
}
2743-
2744-
// If it's not an array, continue with the normal flow
2745-
// Optional: If you need to evaluate the value using eval
2746-
$strArrayValue = rtrim($settingValue, ';');
2747-
$value = eval("return $strArrayValue;");
2738+
$value = eval('return ' . rtrim($settingValue, ';') . ';');
27482739
if (is_array($value)) {
27492740
return $value;
27502741
}
27512742
}
27522743

27532744
// If the value is not a JSON array or wasn't returned previously, continue with the normal flow
2754-
if (!empty($key) && isset($settingValue[$variable][$key])) {
2745+
if ($key !== null && isset($settingValue[$variable][$key])) {
27552746
return $settingValue[$variable][$key];
27562747
}
27572748

27582749
return $settingValue;
2759-
break;
27602750
}
27612751
}
27622752

src/CoreBundle/DataFixtures/SettingsCurrentFixtures.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1089,7 +1089,7 @@ public static function getExistingSettings(): array
10891089
[
10901090
'name' => 'server_type',
10911091
'title' => 'Server Type',
1092-
'comment' => 'What sort of server is this? This enables or disables some specific options. On a development server there is a translation feature functional that inidcates untranslated strings',
1092+
'comment' => 'Defines the environment type: "prod" (normal production), "validation" (like production but without reporting statistics), or "test" (debug mode with developer tools such as untranslated string indicators).',
10931093
],
10941094
[
10951095
'name' => 'show_tabs',

src/CoreBundle/Settings/PlatformSettingsSchema.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,18 @@ public function buildForm(FormBuilderInterface $builder): void
166166
],
167167
]
168168
)
169+
->add(
170+
'server_type',
171+
ChoiceType::class,
172+
[
173+
'label' => 'Server Type',
174+
'choices' => [
175+
'Production' => 'prod',
176+
'Validation' => 'validation',
177+
'Test/Development' => 'test',
178+
],
179+
]
180+
)
169181
->add(
170182
'show_tabs',
171183
ChoiceType::class,

0 commit comments

Comments
 (0)