Fields: fix inheriting fields from commands

refs #712
refs #731
This commit is contained in:
Thomas Gelf 2017-01-19 13:50:50 +01:00
parent 334bd9f58d
commit 164b5bd93d
2 changed files with 45 additions and 6 deletions

View File

@ -109,11 +109,47 @@ class DirectorDatafield extends DbObjectWithSettings
$varname = $this->get('varname');
$form->setInheritedValue(
$el,
$object->getInheritedVar($varname),
$object->getOriginForVar($varname)
);
$inherited = $object->getInheritedVar($varname);
if (null !== $inherited) {
$form->setInheritedValue(
$el,
$inherited,
$object->getOriginForVar($varname)
);
} elseif ($object->hasRelation('check_command')) {
// TODO: Move all of this elsewhere and test it
try {
/** @var IcingaCommand $command */
$command = $object->getResolvedRelated('check_command');
$inherited = $command->vars()->get($varname);
$inheritedFrom = null;
if ($inherited !== null) {
$inherited = $inherited->getValue();
}
if ($inherited === null) {
$inherited = $command->getResolvedVar($varname);
if ($inherited === null) {
$inheritedFrom = $command->getOriginForVar($varname);
}
} else {
$inheritedFrom = $command->getObjectName();
}
$inherited = $command->getResolvedVar($varname);
if (null !== $inherited) {
$form->setInheritedValue(
$el,
$inherited,
$inheritedFrom
);
}
} catch (\Exception $e) {
// Ignore failures
}
}
}
}
}

View File

@ -6,6 +6,7 @@ use Exception;
use Icinga\Data\Filter\Filter;
use Icinga\Data\Filter\FilterExpression;
use Icinga\Exception\IcingaException;
use Icinga\Module\Director\Objects\IcingaCommand;
use Icinga\Module\Director\Objects\IcingaHost;
use Icinga\Module\Director\Objects\IcingaObject;
use Icinga\Module\Director\Objects\DirectorDatafield;
@ -376,6 +377,7 @@ class IcingaObjectFieldLoader
$fields = $this->loadResolvedFieldsForObject($object);
if ($object->hasRelation('check_command')) {
try {
/** @var IcingaCommand $command */
$command = $object->getResolvedRelated('check_command');
} catch (Exception $e) {
// Ignore failures
@ -383,7 +385,8 @@ class IcingaObjectFieldLoader
}
if ($command) {
$cmdFields = $this->loadResolvedFieldsForObject($command);
$cmdLoader = new static($command);
$cmdFields = $cmdLoader->getFields($command);
foreach ($cmdFields as $varname => $field) {
if (! array_key_exists($varname, $fields)) {
$fields[$varname] = $field;