[icinga-checkins] icinga.org: icinga-web/next: Fix default preferences not being overwritten

git at icinga.org git at icinga.org
Fri Apr 26 12:44:02 CEST 2013


Module: icinga-web
Branch: next
Commit: f89f0d54ffc063e68dde9517c0d85dfb43c40f8f
URL:    https://git.icinga.org/?p=icinga-web.git;a=commit;h=f89f0d54ffc063e68dde9517c0d85dfb43c40f8f

Author: Jannis Moßhammer <jannis.mosshammer at netways.de>
Date:   Fri Apr 26 12:43:49 2013 +0200

Fix default preferences not being overwritten

The NsmUser Model didn't recognize if a preference
is a default (i.e. configuration defined) preference or
a preference from the database and always called update.
This caused the update to not match any rows and to be
ignored.

fixes #3990

---

 app/modules/AppKit/lib/database/models/NsmUser.php |   16 +++++++++-------
 1 files changed, 9 insertions(+), 7 deletions(-)

diff --git a/app/modules/AppKit/lib/database/models/NsmUser.php b/app/modules/AppKit/lib/database/models/NsmUser.php
index e82e2e1..15de5a8 100644
--- a/app/modules/AppKit/lib/database/models/NsmUser.php
+++ b/app/modules/AppKit/lib/database/models/NsmUser.php
@@ -197,7 +197,7 @@ class NsmUser extends BaseNsmUser {
             $field = "upref_longval";
         }
         try {
-            $pref = $this->getPrefObject($key);
+            $pref = $this->getPrefObject($key, false, true);
 
             // DO NOT OVERWRITE
             if ($overwrite === false) {
@@ -234,8 +234,8 @@ class NsmUser extends BaseNsmUser {
      * @throws AppKitDoctrineException
      * @author Marius Hein
      */
-    public function getPrefObject($key,$graceful = true) {
-        $res = $this->getPreferences();
+    public function getPrefObject($key,$graceful = true, $ignoreDefaults = false) {
+        $res = $this->getPreferences(false, $ignoreDefaults);
         if(isset($res[$key]))
             return $res[$key];
         else if($graceful) {
@@ -321,7 +321,7 @@ class NsmUser extends BaseNsmUser {
         }
     }
 
-    public function getPreferences($shortenBlob = false) {
+    public function getPreferences($shortenBlob = false, $ignoreDefaults = false) {
         if(!empty(self::$cachedPreferences)) {
             return self::$cachedPreferences;
         }
@@ -342,9 +342,11 @@ class NsmUser extends BaseNsmUser {
             if($shortenBlob && $d['upref_longval'])
                 $out[$key] = "BLOB";
         // Adding defaults
-        foreach(AgaviConfig::get('modules.appkit.user_preferences_default', array()) as $k=>$v) {
-            if (!array_key_exists($k, $out)) {
-                $out[$k] = $v;
+        if(!$ignoreDefaults) {
+            foreach(AgaviConfig::get('modules.appkit.user_preferences_default', array()) as $k=>$v) {
+                if (!array_key_exists($k, $out)) {
+                    $out[$k] = $v;
+                }
             }
         }
         self::$cachedPreferences = $out;





More information about the icinga-checkins mailing list