[icinga-checkins] icinga.org: icingaweb2-module-director/master: IcingaCommand: fix skip_key handling

git at icinga.org git at icinga.org
Fri Aug 26 09:04:33 CEST 2016


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

Author: Thomas Gelf <thomas at gelf.net>
Date:   Fri Aug 26 07:00:45 2016 +0000

IcingaCommand: fix skip_key handling

refs #11554
refs #11918

---

 application/forms/IcingaCommandArgumentForm.php    |    9 ++++++++-
 library/Director/Objects/IcingaCommand.php         |   21 ++++++++++++++++++++
 library/Director/Objects/IcingaCommandArgument.php |   14 ++++++++-----
 3 files changed, 38 insertions(+), 6 deletions(-)

diff --git a/application/forms/IcingaCommandArgumentForm.php b/application/forms/IcingaCommandArgumentForm.php
index 37f1a9b..1ba4009 100644
--- a/application/forms/IcingaCommandArgumentForm.php
+++ b/application/forms/IcingaCommandArgumentForm.php
@@ -127,10 +127,17 @@ class IcingaCommandArgumentForm extends DirectorObjectForm
     {
         $object = $this->object();
         $cmd = $this->commandObject;
+        if (! $object->hasBeenLoadedFromDb()) {
+            if ($object->argument_name === null) {
+                $object->skip_key = true;
+                $object->argument_name = $cmd->getNextSkippableKeyName();
+            }
+        }
+
         if ($object->hasBeenModified()) {
             $cmd->arguments()->set(
                 $object->argument_name,
-                IcingaCommandArgument::create($this->getValues(), $this->db)
+                $object
             );
             $msg = sprintf(
                 $this->translate('The argument %s has successfully been stored'),
diff --git a/library/Director/Objects/IcingaCommand.php b/library/Director/Objects/IcingaCommand.php
index 1b1d0cf..523cfff 100644
--- a/library/Director/Objects/IcingaCommand.php
+++ b/library/Director/Objects/IcingaCommand.php
@@ -119,6 +119,27 @@ class IcingaCommand extends IcingaObject
         return $value;
     }
 
+    public function getNextSkippableKeyName()
+    {
+        $key = $this->makeSkipKey();
+        $cnt = 1;
+        while (isset($this->arguments()->$key)) {
+            $cnt++;
+            $key = $this->makeSkipKey($cnt);
+        }
+
+        return $key;
+    }
+
+    protected function makeSkipKey($num = null)
+    {
+        if ($num === null) {
+            return '(no key)';
+        }
+
+        return sprintf('(no key.%d)', $num);
+    }
+
     protected function prefersGlobalZone()
     {
         return true;
diff --git a/library/Director/Objects/IcingaCommandArgument.php b/library/Director/Objects/IcingaCommandArgument.php
index 5de6d23..5a51dd9 100644
--- a/library/Director/Objects/IcingaCommandArgument.php
+++ b/library/Director/Objects/IcingaCommandArgument.php
@@ -48,6 +48,11 @@ class IcingaCommandArgument extends IcingaObject
         // No log right now, we have to handle "sub-objects"
     }
 
+    public function isSkippingKey()
+    {
+        return $this->skip_key === 'y' || $this->argument_name === null;
+    }
+
     // Preserve is not supported
     public function replaceWith(IcingaObject $object, $preserve = null)
     {
@@ -163,15 +168,14 @@ class IcingaCommandArgument extends IcingaObject
             $data['required'] = c::renderBoolean($this->required);
         }
 
-        if ($this->repeat_key) {
-            $data['repeat_key'] = c::renderBoolean($this->repeat_key);
+        if ($this->isSkippingKey()) {
+            $data['skip_key'] = c::renderBoolean('y');
         }
 
-/*        if ((int) $this->sort_order !== 0) {
-            $data['order'] = $this->sort_order;
+        if ($this->repeat_key) {
+            $data['repeat_key'] = c::renderBoolean($this->repeat_key);
         }
 
-*/
         if ($this->description) {
             $data['description'] = c::renderString($this->description);
         }



More information about the icinga-checkins mailing list