IcingaTemplateRepository: fetch parents, not...
...ancestors per default fixes #1114
This commit is contained in:
parent
8f15fe3c0e
commit
1a08b90c7a
|
@ -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)) {
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue