Skip to content

Commit

Permalink
Allow override of forced plugin settings
Browse files Browse the repository at this point in the history
  • Loading branch information
bwalkerl committed Jan 14, 2025
1 parent 58e5c92 commit 1f0f4b7
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -349,27 +349,35 @@ function tool_abconfig_execute_command_array($commandsencoded, $shortname, $js =
if ($command == 'CFG') {
$commandarray = explode(',', $commandstring, 3);

// Allow override if set in config.php already:
// Allow override if set in config.php already.
$allow = isset($CFG->{$commandarray[1] . '_allow_abconfig'});

// Ensure that command hasn't already been set in config.php.
if ($allow || !array_key_exists($commandarray[1], $CFG->config_php_settings)) {
$CFG->{$commandarray[1]} = $commandarray[2];
$CFG->config_php_settings[$commandarray[1]] = $commandarray[2];
} else {
// Debugging shouldn't be used before sessions are loaded.
// @codingStandardsIgnoreLine
error_log("abconfig: Can't override \$CFG->{$commandarray[1]} because already set in config.php!");
}
}
if ($command == 'forced_plugin_setting') {
// Check for plugin commands.
$commandarray = explode(',', $commandstring, 4);

// Ensure that command hasnt already been forced in config.php.
// If plugin settings array doesnt exist, or the actualy config key doesnt exist.
// Ensure that command hasnt already been forced in config.php or that overriding is allowed.
// If plugin settings array doesnt exist, or the actual config key doesnt exist.
if (!array_key_exists($commandarray[1], $CFG->forced_plugin_settings) ||
!array_key_exists($commandarray[2], $CFG->forced_plugin_settings[$commandarray[1]])) {
!array_key_exists($commandarray[2], $CFG->forced_plugin_settings[$commandarray[1]]) ||
array_key_exists($commandarray[2] . '_allow_abconfig', $CFG->forced_plugin_settings[$commandarray[1]])) {

$CFG->forced_plugin_settings[$commandarray[1]][$commandarray[2]] = $commandarray[3];
} else {
// Debugging shouldn't be used before sessions are loaded.
// @codingStandardsIgnoreLine
error_log("abconfig: Can't override \$CFG->forced_plugin_settings['$commandarray[1]']['$commandarray[2]'] " .
"because already set in config.php!");
}
}
if ($command == 'http_header') {
Expand Down

0 comments on commit 1f0f4b7

Please sign in to comment.