do NOT save config, if there is an error, also let config hook know if it is called initially or after an apply

This commit is contained in:
Ralf Becker 2019-07-17 11:15:32 +02:00
parent 0f8e678524
commit 8520b0ba15

View File

@ -142,7 +142,7 @@ class admin_config
$this->remove_anon_images(array_diff((array)$c->config_data['login_background_file'], $_content['newsettings']['login_background_file']));
/* Load hook file with functions to validate each config (one/none/all) */
Api\Hooks::single(array(
$errors = Api\Hooks::single(array(
'location' => 'config_validate',
)+(array)$_content['newsettings'], $appname);
@ -179,6 +179,9 @@ class admin_config
unset($GLOBALS['egw_info']['server']['found_validation_hook']);
}
// do not allow to save config, if there are errors
if (!$errors)
{
// compute real changes and their old values (null for removals)
$modifications = array_udiff_assoc($c->config_data, $old, function($a, $b)
{
@ -203,8 +206,6 @@ class admin_config
{
$msg = lang('Nothing to save.');
}
if (!$errors)
{
// allow apps to hook into configuration dialog to eg. save some stuff outside configuration
$_content['location'] = 'config_after_save';
Api\Hooks::single($_content, $_appname);
@ -224,18 +225,24 @@ class admin_config
Api\Framework::message(lang('Error') . ': ' . $errors, 'error');
unset($errors);
unset($GLOBALS['config_error']);
// keep old content on error
$config = $_content['newsettings'];
}
elseif ($_content['apply'])
else
{
if ($_content['apply'])
{
Api\Framework::message($msg, 'success');
}
$sel_options = $readonlys = array();
$config = $c->read_repository();
}
$sel_options = $readonlys = array();
// call "config" hook, allowing apps to overwrite config, eg. set default values,
// or return options in "sel_options" keys
$config['location'] = 'config';
// let config hook know, this is an inital call and not one after user hits [Apply] button
$config['initial-call'] = is_null($_content);
$ret = Api\Hooks::single($config, $appname);
if (is_array($ret))
{