FieldLoader, TemplateResolver: more cleanup

A few fixes related to modified imports for unstored objects

refs #12922
This commit is contained in:
Thomas Gelf 2016-10-14 09:59:08 +00:00
parent 98acba9fb4
commit 041fd52174
3 changed files with 26 additions and 14 deletions

View File

@ -117,8 +117,17 @@ class IcingaTemplateResolver
$this->requireTemplates(); $this->requireTemplates();
if ($name === null) { if ($name === null) {
$name = $this->object->object_name;
if ($this->object->imports()->hasBeenModified()) { $object = $this->object;
if ($object->hasBeenLoadedFromDb()) {
if ($object->gotImports() && $object->imports()->hasBeenModified()) {
return $this->listUnstoredParentNames();
}
$name = $object->object_name;
} else {
return $this->listUnstoredParentNames(); return $this->listUnstoredParentNames();
} }
} }
@ -140,7 +149,7 @@ class IcingaTemplateResolver
public function listResolvedParentIds() public function listResolvedParentIds()
{ {
$this->requireTemplates(); $this->requireTemplates();
return $this->resolveParentIds($this->object->id); return $this->resolveParentIds();
} }
public function listResolvedParentNames() public function listResolvedParentNames()
@ -166,9 +175,9 @@ class IcingaTemplateResolver
protected function resolveParentNames($name, &$list = array()) protected function resolveParentNames($name, &$list = array())
{ {
foreach ($this->listParentNames($name) as $parent) { foreach ($this->listParentNames($name) as $parent) {
$this->assertNotInList($parent, $list, $id); $this->assertNotInList($parent, $list, $name);
$list[$parent] = true; $list[$parent] = true;
$this->resolveParentIds($parent, $list); $this->resolveParentNames($parent, $list);
unset($list[$parent]); unset($list[$parent]);
$list[$parent] = true; $list[$parent] = true;
} }
@ -176,10 +185,12 @@ class IcingaTemplateResolver
return array_keys($list); return array_keys($list);
} }
protected function resolveParentIds($id, &$list = array()) protected function resolveParentIds($id = null, &$list = array())
{ {
foreach ($this->listParentIds($id) as $parent) { foreach ($this->listParentIds($id) as $parent) {
$this->assertNotInList($parent, $list, $id); if ($id !== null) {
$this->assertNotInList($parent, $list, $id);
}
$list[$parent] = true; $list[$parent] = true;
$this->resolveParentIds($parent, $list); $this->resolveParentIds($parent, $list);
unset($list[$parent]); unset($list[$parent]);

View File

@ -273,7 +273,7 @@ abstract class DirectorObjectForm extends QuickForm
protected function handleCustomVars($object, & $values) protected function handleCustomVars($object, & $values)
{ {
IcingaObjectFieldLoader::addFieldsToForm($this, $values); IcingaObjectFieldLoader::addFieldsToForm($this, $object, $values);
} }
protected function isNew() protected function isNew()

View File

@ -3,6 +3,7 @@
namespace Icinga\Module\Director\Web\Form; namespace Icinga\Module\Director\Web\Form;
use Icinga\Module\Director\Exception\NestingError; use Icinga\Module\Director\Exception\NestingError;
use Icinga\Module\Director\Objects\IcingaObject;
use Icinga\Module\Director\Objects\IcingaServiceSet; use Icinga\Module\Director\Objects\IcingaServiceSet;
use Icinga\Module\Director\Objects\DirectorDatafield; use Icinga\Module\Director\Objects\DirectorDatafield;
use stdClass; use stdClass;
@ -13,19 +14,19 @@ class IcingaObjectFieldLoader
protected $object; protected $object;
protected function __construct(DirectorObjectForm $form) protected function __construct(DirectorObjectForm $form, IcingaObject $object)
{ {
$this->form = $form; $this->form = $form;
$this->object = $form->getObject(); $this->object = $object;
} }
public static function addFieldsToForm(DirectorObjectForm $form, & $values) public static function addFieldsToForm(DirectorObjectForm $form, IcingaObject $object, & $values)
{ {
if (! $form->getObject()->supportsCustomVars()) { if (! $object->supportsCustomVars()) {
return $form; return $form;
} }
$loader = new static($form); $loader = new static($form, $object);
$loader->addFields(); $loader->addFields();
if ($values !== null) { if ($values !== null) {
$loader->setValues($loader->stripKeyPrefix($values, 'var_')); $loader->setValues($loader->stripKeyPrefix($values, 'var_'));