IcingaArguments: fix argment removal for forms

fixes #11536
This commit is contained in:
Thomas Gelf 2016-08-01 11:06:52 +00:00
parent 52e412002f
commit 54643fe5cd
2 changed files with 24 additions and 5 deletions

View File

@ -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()
{

View File

@ -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]);
}