IcingaTemplateRepository: fetch parents, not...

...ancestors per default

fixes #1114
This commit is contained in:
Thomas Gelf 2017-08-25 14:22:49 +02:00
parent 8f15fe3c0e
commit 1a08b90c7a
2 changed files with 25 additions and 6 deletions

View File

@ -111,7 +111,7 @@ class HostController extends ObjectController
/** @var IcingaHost[] $parents */
$parents = IcingaTemplateRepository::instanceByObject($this->object)
->getTemplatesFor($this->object);
->getTemplatesFor($this->object, true);
foreach ($parents as $parent) {
$table = IcingaHostServiceTable::load($parent)->setInheritedBy($host);
if (count($table)) {

View File

@ -29,11 +29,27 @@ class IcingaTemplateRepository
/**
* @param IcingaObject $object
* @param bool $recursive
* @return IcingaObject[]
*/
public function getTemplatesFor(IcingaObject $object)
public function getTemplatesFor(IcingaObject $object, $recursive = false)
{
if ($recursive) {
$ids = $this->tree()->listAncestorIdsFor($object);
} else {
$ids = $this->tree()->listParentIdsFor($object);
}
return $this->getTemplatesForIds($ids, $object);
}
/**
* @param array $ids
* @param IcingaObject $object
* @return IcingaObject[]
*/
public function getTemplatesForIds(array $ids, IcingaObject $object)
{
$ids = $this->tree()->listAncestorIdsFor($object);
$templates = [];
foreach ($ids as $id) {
if (! array_key_exists($id, $this->loadedById)) {
@ -52,12 +68,15 @@ class IcingaTemplateRepository
/**
* @param IcingaObject $object
* @param bool $recursive
* @return IcingaObject[]
*/
public function getTemplatesIndexedByNameFor(IcingaObject $object)
{
public function getTemplatesIndexedByNameFor(
IcingaObject $object,
$recursive = false
) {
$templates = [];
foreach ($this->getTemplatesFor($object) as $template) {
foreach ($this->getTemplatesFor($object, $recursive) as $template) {
$templates[$template->getObjectName()] = $template;
}