Preserve the old values to be used in values comparison

This commit is contained in:
Hadi Nategh 2018-08-22 12:26:56 +02:00
parent 030eb89f84
commit 886bc915cf
2 changed files with 31 additions and 6 deletions

View File

@ -46,4 +46,14 @@ class admin_cmd_edit_preferences extends admin_cmd
$GLOBALS['egw']->preferences->save_repository(True, $this->type); $GLOBALS['egw']->preferences->save_repository(True, $this->type);
return lang('Preferences saved.'); return lang('Preferences saved.');
} }
/**
* Return a title / string representation for a given command, eg. to display it
*
* @return string
*/
function __tostring()
{
return lang('Preferences of user %1 changed by %2', $this->data['account'], $this->requested_email);
}
} }

View File

@ -167,6 +167,20 @@ class preferences_settings
$preserve['appname'] = $preserve['old_appname'] = $data['appname']; $preserve['appname'] = $preserve['old_appname'] = $data['appname'];
$preserve['type'] = $preserve['old_type'] = $data['type']; $preserve['type'] = $preserve['old_type'] = $data['type'];
$preserve['is_admin'] = $is_admin; $preserve['is_admin'] = $is_admin;
// preserve the old values since we need them for admin cmd data comparison
$preserve['old_values'] = array ();
foreach($data as $key => $val)
{
if (is_array($val) && strpos($key, 'tab') === 0)
{
foreach ($val as $k => $v)
{
if (!is_int($k)) $preserve['old_values'][$k] = $v;
}
}
}
if (isset($old_tab)) $data['tabs'] = $old_tab; if (isset($old_tab)) $data['tabs'] = $old_tab;
if ($msg) Framework::message($msg, $msg_type ? $msg_type : 'error'); if ($msg) Framework::message($msg, $msg_type ? $msg_type : 'error');
@ -178,14 +192,15 @@ class preferences_settings
* run admin command instance * run admin command instance
* *
* @param array $content * @param array $content
* @param array $prefs
* @param array $values * @param array $values
* @param string $account_id * @param string $account_id
*/ */
static function admin_cmd_run($content, $prefs, $values, $account_id) static function admin_cmd_run($content, $values, $account_id)
{ {
$changes = array_diff($values, $prefs); $changes = array_udiff_assoc($values, $content['old_values'], function($a, $b){
$old = array_intersect_key($prefs, $changes); return (int) $a !== $b;
});
$old = array_intersect_key($content['old_values'], $changes);
$cmd = new admin_cmd_edit_preferences(array( $cmd = new admin_cmd_edit_preferences(array(
'account' => $account_id, 'account' => $account_id,
'set' => $changes, 'set' => $changes,
@ -218,7 +233,7 @@ class preferences_settings
$prefs = &$repository[$appname]; $prefs = &$repository[$appname];
unset($prefs['']); unset($prefs['']);
$old = $prefs;
//_debug_array($values);exit; //_debug_array($values);exit;
foreach($values as $var => $value) foreach($values as $var => $value)
{ {
@ -311,7 +326,7 @@ class preferences_settings
{ {
if ($content['is_admin']) if ($content['is_admin'])
{ {
self::admin_cmd_run($content, $old, $values, $GLOBALS['egw']->preferences->get_account_id()); self::admin_cmd_run($content, $content['old_values'], $values, $GLOBALS['egw']->preferences->get_account_id());
} }
else else
{ {