From 8c13d3e6cb57ccd4a3678ac8a0af3dca1d2c2b14 Mon Sep 17 00:00:00 2001 From: Ralf Becker Date: Thu, 23 Jan 2014 12:34:45 +0000 Subject: [PATCH] * API/Preferences: fixed can NOT unset last (forced) preference of an app, also fixed not working deleting of prefs when deleting a user or group --- phpgwapi/inc/class.preferences.inc.php | 33 ++++++++++++++++++-------- 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/phpgwapi/inc/class.preferences.inc.php b/phpgwapi/inc/class.preferences.inc.php index a34ec0a5f3..8021020ff9 100644 --- a/phpgwapi/inc/class.preferences.inc.php +++ b/phpgwapi/inc/class.preferences.inc.php @@ -639,7 +639,9 @@ class preferences { if ($accountid > 0) { - $this->delete($this->table,array('preference_owner' => $accountid),__LINE__,__FILE__); + $this->db->delete($this->table,array('preference_owner' => $accountid),__LINE__,__FILE__); + + egw_cache::unsetInstance(__CLASS__, $accountid); } } @@ -652,7 +654,9 @@ class preferences { if ($accountid < 0) { - $this->delete($this->table,array('preference_owner' => $accountid+self::DEFAULT_ID),__LINE__,__FILE__); + $this->db->delete($this->table,array('preference_owner' => $accountid+self::DEFAULT_ID),__LINE__,__FILE__); + + egw_cache::unsetInstance(__CLASS__, $accountid+self::DEFAULT_ID); } } @@ -768,27 +772,36 @@ class preferences if (isset($GLOBALS['egw_setup']) || !$GLOBALS['egw']->acl->check('session_only_preferences',1,'preferences') && (!($old_prefs = $this->cache_read($account_id)) || $old_prefs[$account_id] != $prefs)) { + //error_log(__METHOD__."(type=$type) saved, because old_prefs[$account_id] != prefs=".array2string($prefs)); $this->db->transaction_begin(); foreach($prefs as $app => $value) { if (!is_array($value) || !$value) { - continue; + $this->db->delete($this->table, array( + 'preference_owner' => $account_id, + 'preference_app' => $app, + ), __LINE__, __FILE__); + unset($prefs[$app]); } - $this->quote($value); // this quote-ing is for serialize, not for the db + else + { + $this->quote($value); // this quote-ing is for serialize, not for the db - $this->db->insert($this->table,array( - 'preference_value' => serialize($value), - ),array( - 'preference_owner' => $account_id, - 'preference_app' => $app, - ),__LINE__,__FILE__); + $this->db->insert($this->table,array( + 'preference_value' => serialize($value), + ),array( + 'preference_owner' => $account_id, + 'preference_app' => $app, + ),__LINE__,__FILE__); + } } $this->db->transaction_commit(); // update instance-wide cache egw_cache::setInstance(__CLASS__, $account_id, $prefs); } + //else error_log(__METHOD__."(type=$type) NOT saved because old_prefs[$account_id] == prefs=".array2string($prefs)); return $this->data; }