Introduce new hooks boolean param called 'reload' in order to force main framework to refresh after saving preferences

This commit is contained in:
hadi 2023-03-16 16:25:48 +01:00
parent d653bde7c0
commit de9c1f5c48
3 changed files with 47 additions and 7 deletions

View File

@ -440,7 +440,8 @@ class mail_hooks
'expand' => lang('show horizontal, hide if none selected'), 'expand' => lang('show horizontal, hide if none selected'),
'hide' => lang('never show'), 'hide' => lang('never show'),
), ),
'default' => 'vertical' 'default' => 'vertical',
'reload' => true
), ),
'toggledOnActions' => array( 'toggledOnActions' => array(
'type' => 'taglist', 'type' => 'taglist',

View File

@ -184,6 +184,7 @@ class preferences_hooks
'values' => $textsize, 'values' => $textsize,
'default' => '14', 'default' => '14',
'admin' => False, 'admin' => False,
'reload' => true
), ),
'lazy-update' => array( 'lazy-update' => array(
'type' => 'select', 'type' => 'select',
@ -205,6 +206,7 @@ class preferences_hooks
'xmlrpc' => True, 'xmlrpc' => True,
'admin' => False, 'admin' => False,
'forced' => file_exists(EGW_SERVER_ROOT.'/pixelegg') ? 'pixelegg' : 'idots', 'forced' => file_exists(EGW_SERVER_ROOT.'/pixelegg') ? 'pixelegg' : 'idots',
'reload' => true
), ),
'theme' => array( 'theme' => array(
'type' => 'select', 'type' => 'select',
@ -215,6 +217,7 @@ class preferences_hooks
'xmlrpc' => True, 'xmlrpc' => True,
'admin' => False, 'admin' => False,
'forced' => file_exists(EGW_SERVER_ROOT.'/pixelegg') ? 'pixelegg' : 'idots', 'forced' => file_exists(EGW_SERVER_ROOT.'/pixelegg') ? 'pixelegg' : 'idots',
'reload' => true
), ),
'darkmode' => array( 'darkmode' => array(
'type' => 'select', 'type' => 'select',
@ -335,6 +338,7 @@ class preferences_hooks
'xmlrpc' => True, 'xmlrpc' => True,
'admin' => False, 'admin' => False,
'default'=> $lang, 'default'=> $lang,
'reload' => true
), ),
'country' => array( 'country' => array(
'type' => 'et2-select-country', 'type' => 'et2-select-country',

View File

@ -99,25 +99,25 @@ class preferences_settings
$GLOBALS['egw']->preferences->set_account_id($account_id); $GLOBALS['egw']->preferences->set_account_id($account_id);
$GLOBALS['egw']->preferences->read_repository(); $GLOBALS['egw']->preferences->read_repository();
} }
// name of common preferences which require reload of framework, if there values change
$require_reload = array('template_set', 'theme', 'lang', 'template_color', 'template_custom_color', 'textsize');
$old_values = array_intersect_key($GLOBALS['egw_info']['user']['preferences']['common'], array_flip($require_reload));
$attribute = $type == 'group' ? 'user' : $type; $attribute = $type == 'group' ? 'user' : $type;
$require_reload = self::fetchRequireToReload($appname, $type);
$old_values = array_intersect_key($GLOBALS['egw_info']['user']['preferences'][$appname], array_flip($require_reload));
if (!($msg=$this->process_array($GLOBALS['egw']->preferences->$attribute, $prefs, $content['types'], $appname, $attribute, $content))) if (!($msg=$this->process_array($GLOBALS['egw']->preferences->$attribute, $prefs, $content['types'], $appname, $attribute, $content)))
{ {
$msg_type = 'success'; $msg_type = 'success';
$msg = lang('Preferences saved.'); $msg = lang('Preferences saved.');
// do we need to reload whole framework // do we need to reload whole framework
if ($appname == 'common') if (!empty($require_reload))
{ {
if ($account_id && $GLOBALS['egw']->preferences->get_account_id() != $GLOBALS['egw_info']['user']['account_id']) if ($account_id && $GLOBALS['egw']->preferences->get_account_id() != $GLOBALS['egw_info']['user']['account_id'])
{ {
$GLOBALS['egw']->preferences->set_account_id($GLOBALS['egw_info']['user']['account_id']); $GLOBALS['egw']->preferences->set_account_id($GLOBALS['egw_info']['user']['account_id']);
} }
$GLOBALS['egw_info']['user']['preferences'] = $GLOBALS['egw']->preferences->read_repository(); $GLOBALS['egw_info']['user']['preferences'] = $GLOBALS['egw']->preferences->read_repository();
$new_values = array_intersect_key($GLOBALS['egw_info']['user']['preferences']['common'], array_flip($require_reload)); $new_values = array_intersect_key($GLOBALS['egw_info']['user']['preferences'][$appname], array_flip($require_reload));
//error_log(__METHOD__."() ".__LINE__.": old_values=".array2string($old_values).", new_values=".array2string($new_values)); //error_log(__METHOD__."() ".__LINE__.": old_values=".array2string($old_values).", new_values=".array2string($new_values));
if ($old_values != $new_values) if ($old_values != $new_values)
{ {
@ -199,6 +199,41 @@ class preferences_settings
$tpl->exec('preferences.preferences_settings.index', $data, $sel_options, $readonlys, $preserve, 2); $tpl->exec('preferences.preferences_settings.index', $data, $sel_options, $readonlys, $preserve, 2);
} }
/**
* Fetch preferences of given app where they have reload attribute set to true
* @param string $appname app name
* @param string $type 'user', 'default', 'forced'
* @return array
* @throws Api\Exception\AssertionFailed
*/
static function fetchRequireToReload($appname, $type)
{
$keys = [];
if ($appname == 'common')
{
// none app pref names here since we can't read them via hooks
$keys = ['template_color', 'template_custom_color', 'sidebox_custom_color'];
$settings = Api\Hooks::single(array(
'account_id'=>$GLOBALS['egw']->preferences->get_account_id(),
'location'=>'settings',
'type' => $type), 'preferences');
}
else
{
$settings = Api\Hooks::single(array(
'account_id'=>$GLOBALS['egw']->preferences->get_account_id(),
'location'=>'settings',
'type' => $type), $appname);
}
foreach ($settings as $key => $value)
{
if ($value['reload']) $keys[]=$key;
}
return $keys;
}
/** /**
* run admin command instance * run admin command instance
* *