[icinga-checkins] icinga.org: icingaweb2-module-director/master: IcingaArguments: fix argment removal for forms

git at icinga.org git at icinga.org
Mon Aug 1 13:07:40 CEST 2016


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

Author: Thomas Gelf <thomas at gelf.net>
Date:   Mon Aug  1 11:06:52 2016 +0000

IcingaArguments: fix argment removal for forms

fixes #11536

---

 application/forms/IcingaCommandArgumentForm.php |   19 +++++++++++++++++++
 library/Director/Objects/IcingaArguments.php    |   10 +++++-----
 2 files changed, 24 insertions(+), 5 deletions(-)

diff --git a/application/forms/IcingaCommandArgumentForm.php b/application/forms/IcingaCommandArgumentForm.php
index f7b0503..59214a8 100644
--- a/application/forms/IcingaCommandArgumentForm.php
+++ b/application/forms/IcingaCommandArgumentForm.php
@@ -102,6 +102,25 @@ class IcingaCommandArgumentForm extends DirectorObjectForm
         $this->setButtons();
     }
 
+    protected function deleteObject($object)
+    {
+        $cmd = $this->commandObject;
+
+        $msg = sprintf(
+            '%s argument "%s" has been removed',
+            $this->translate($this->getObjectName()),
+            $object->argument_name
+        );
+
+        $url = $this->getSuccessUrl()->without('argument_id');
+
+        $cmd->arguments()->remove($object->argument_name);
+        if ($cmd->store()) {
+            $this->setSuccessUrl($url);
+        }
+
+        $this->redirectOnSuccess($msg);
+    }
 
     public function onSuccess()
     {
diff --git a/library/Director/Objects/IcingaArguments.php b/library/Director/Objects/IcingaArguments.php
index 8f15800..9a5ed77 100644
--- a/library/Director/Objects/IcingaArguments.php
+++ b/library/Director/Objects/IcingaArguments.php
@@ -228,11 +228,12 @@ class IcingaArguments implements Iterator, Countable, IcingaConfigRenderer
     public function remove($argument)
     {
         if (array_key_exists($argument, $this->arguments)) {
-            unset($this->arguments[$argument]);
+            $this->arguments[$argument]->markForRemoval();
+            $this->modified = true;
+            $this->refreshIndex();
         }
 
-        $this->modified = true;
-        $this->refreshIndex();
+        return $this;
     }
 
     protected function refreshIndex()
@@ -340,8 +341,6 @@ class IcingaArguments implements Iterator, Countable, IcingaConfigRenderer
         $deleted = array();
         foreach ($this->arguments as $key => $argument) {
             if ($argument->shouldBeRemoved()) {
-                $argument->delete();
-                unset($this->arguments[$key]);
                 $deleted[] = $key;
             } else {
                 $argument->command_id = $this->object->id;
@@ -350,6 +349,7 @@ class IcingaArguments implements Iterator, Countable, IcingaConfigRenderer
         }
 
         foreach ($deleted as $key) {
+            $this->arguments[$key]->delete();
             unset($this->arguments[$key]);
         }
 



More information about the icinga-checkins mailing list