IcingaCommand: fix skip_key handling

refs #11554
refs #11918
This commit is contained in:
Thomas Gelf 2016-08-26 07:00:45 +00:00
parent 7323f73327
commit b6d59b9aca
3 changed files with 38 additions and 6 deletions

View File

@ -127,10 +127,17 @@ class IcingaCommandArgumentForm extends DirectorObjectForm
{ {
$object = $this->object(); $object = $this->object();
$cmd = $this->commandObject; $cmd = $this->commandObject;
if (! $object->hasBeenLoadedFromDb()) {
if ($object->argument_name === null) {
$object->skip_key = true;
$object->argument_name = $cmd->getNextSkippableKeyName();
}
}
if ($object->hasBeenModified()) { if ($object->hasBeenModified()) {
$cmd->arguments()->set( $cmd->arguments()->set(
$object->argument_name, $object->argument_name,
IcingaCommandArgument::create($this->getValues(), $this->db) $object
); );
$msg = sprintf( $msg = sprintf(
$this->translate('The argument %s has successfully been stored'), $this->translate('The argument %s has successfully been stored'),

View File

@ -119,6 +119,27 @@ class IcingaCommand extends IcingaObject
return $value; 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() protected function prefersGlobalZone()
{ {
return true; return true;

View File

@ -48,6 +48,11 @@ class IcingaCommandArgument extends IcingaObject
// No log right now, we have to handle "sub-objects" // 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 // Preserve is not supported
public function replaceWith(IcingaObject $object, $preserve = null) public function replaceWith(IcingaObject $object, $preserve = null)
{ {
@ -163,15 +168,14 @@ class IcingaCommandArgument extends IcingaObject
$data['required'] = c::renderBoolean($this->required); $data['required'] = c::renderBoolean($this->required);
} }
if ($this->isSkippingKey()) {
$data['skip_key'] = c::renderBoolean('y');
}
if ($this->repeat_key) { if ($this->repeat_key) {
$data['repeat_key'] = c::renderBoolean($this->repeat_key); $data['repeat_key'] = c::renderBoolean($this->repeat_key);
} }
/* if ((int) $this->sort_order !== 0) {
$data['order'] = $this->sort_order;
}
*/
if ($this->description) { if ($this->description) {
$data['description'] = c::renderString($this->description); $data['description'] = c::renderString($this->description);
} }