IcingaObject: getAppliedGroups with id=null

This commit is contained in:
Thomas Gelf 2021-08-16 06:21:50 +02:00
parent 21dcadd143
commit 77fca39ff3

View File

@ -859,6 +859,12 @@ abstract class IcingaObject extends DbObject implements IcingaConfigRenderer
// them here on demand.
return [];
}
$id = $this->get('id');
if ($id === null) {
// Do not fail for branches. Should be handled otherwise
// TODO: throw an Exception, once we are able to deal with this
return [];
}
$type = strtolower($this->getType());
$query = $this->db->select()->from(
@ -870,11 +876,11 @@ abstract class IcingaObject extends DbObject implements IcingaConfigRenderer
[]
)->joinLeft(
['go' => "icinga_${type}group_${type}"],
"go.${type}group_id = gr.${type}group_id AND go.${type}_id = " . $this->id,
"go.${type}group_id = gr.${type}group_id AND go.${type}_id = " . (int) $id,
[]
)->where(
"gr.${type}_id = ?",
$this->id
(int) $id
)->where("go.${type}_id IS NULL")->order('g.object_name');
return $this->db->fetchCol($query);