Fix/avoid cyclic inheritance only for host and command (#3037)

fixes #3036
This commit is contained in:
Ravi Kumar Kempapura Srinivasa 2026-03-26 09:51:03 +01:00 committed by GitHub
commit fed11fc0e4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 21 additions and 12 deletions

View file

@ -140,18 +140,21 @@ class IcingaObjectHandler extends RequestHandler
$object->replaceWith(IcingaObject::createByType($type, $data, $db));
}
if (in_array((int) $object->get('id'), $object->listAncestorIds())) {
throw new RuntimeException(
'Import loop detected for the object '
. $object->getObjectName() . ' -> Imports: '
. implode(', ', $object->getImports())
);
}
// Avoid cyclic imports for hosts and commands
if (in_array($object->getShortTableName(), ['host', 'command'], true)) {
if (in_array((int) $object->get('id'), $object->listAncestorIds())) {
throw new RuntimeException(
'Import loop detected for the object '
. $object->getObjectName() . ' -> Imports: '
. implode(', ', $object->getImports())
);
}
if (isset($data['imports']) && in_array($object->get('object_name'), $data['imports'])) {
throw new RuntimeException(
'You can not import the same object into itself: ' . $object->getObjectName()
);
if (isset($data['imports']) && in_array($object->get('object_name'), $data['imports'])) {
throw new RuntimeException(
'You can not import the same object into itself: ' . $object->getObjectName()
);
}
}
$this->persistChanges($object);

View file

@ -1289,7 +1289,13 @@ abstract class DirectorObjectForm extends DirectorForm
'class' => 'autosubmit',
'validators' => [
new Zend_Validate_Callback(function ($value) {
$templateTree = new TemplateTree($this->object->getShortTableName(), $this->getDb());
$objectInstance = $this->object->getShortTableName();
// Avoid cyclic imports for hosts and commands
if ($objectInstance !== 'host' && $objectInstance !== 'command') {
return true;
}
$templateTree = new TemplateTree($objectInstance, $this->getDb());
$importsElement = $this->getElement('imports');
$objectName = $this->object->getObjectName();
if (in_array($objectName, $value, true)) {