[icinga-checkins] icinga.org: icingaweb2-module-director/fiddle/mfrosch: WIP: IcingaObject: Handle vars case in-sensitive

git at icinga.org git at icinga.org
Tue Jun 7 15:59:18 CEST 2016


Module: icingaweb2-module-director
Branch: fiddle/mfrosch
Commit: a238e2b6271130e6b6806b0043e6f261290b11c8
URL:    https://git.icinga.org/?p=icingaweb2-module-director.git;a=commit;h=a238e2b6271130e6b6806b0043e6f261290b11c8

Author: Markus Frosch <lazyfrosch at icinga.org>
Date:   Tue Jun  7 15:59:02 2016 +0200

WIP: IcingaObject: Handle vars case in-sensitive

refs #11911

---

 library/Director/Objects/IcingaObject.php |   18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

diff --git a/library/Director/Objects/IcingaObject.php b/library/Director/Objects/IcingaObject.php
index 8a3fd7f..8c30ff3 100644
--- a/library/Director/Objects/IcingaObject.php
+++ b/library/Director/Objects/IcingaObject.php
@@ -382,6 +382,12 @@ abstract class IcingaObject extends DbObject implements IcingaConfigRenderer
                 if (! array_key_exists($k, $value)) {
                     $unset[] = $k;
                 }
+                // check if there is a var in a different case
+                foreach (array_keys($value) as $newKey) {
+                    if (strtolower($k) === strtolower($newKey) && $k !== $newKey) {
+                        $unset[] = $k;
+                    }
+                }
             }
             foreach ($unset as $k) {
                 unset($this->vars()->$k);
@@ -392,6 +398,12 @@ abstract class IcingaObject extends DbObject implements IcingaConfigRenderer
             return $this;
         } elseif (substr($key, 0, 5) === 'vars.') {
             //TODO: allow for deep keys
+            // check if there is a var in a different case
+            foreach ($this->vars() as $oldKey => $v) {
+                if (strtolower($oldKey) === strtolower($key) && $oldKey !== $key) {
+                    unset($this->vars()->$oldKey);
+                }
+            }
             $this->vars()->set(substr($key, 5), $value);
             return $this;
         } elseif (substr($key, 0, 10) === 'arguments.') {
@@ -1564,6 +1576,12 @@ abstract class IcingaObject extends DbObject implements IcingaConfigRenderer
         if ($object->supportsCustomVars()) {
             $myVars = $this->vars();
             foreach ($vars as $key => $var) {
+                // check if there is a var in a different case
+                foreach ($myVars as $oldKey => $v) {
+                    if (strtolower($oldKey) === strtolower($key) && $oldKey !== $key) {
+                        unset($myVars->$oldKey);
+                    }
+                }
                 $myVars->set($key, $var);
             }
         }



More information about the icinga-checkins mailing list