IcingaObject: implement supportsAssignRules

This commit is contained in:
Thomas Gelf 2016-09-09 09:06:31 +00:00
parent b6d97171e1
commit 217fb38517
6 changed files with 28 additions and 11 deletions

View File

@ -25,7 +25,7 @@ class AssignListSubForm extends QuickSubForm
{
$idx = -1;
if ($this->object && $this->object->isApplyRule()) {
if ($this->object && $this->object->supportsAssignments()) {
// $this->setElementValue('assignlist', $object->assignments()->getFormValues());
foreach ($this->object->assignments()->getFormValues() as $values) {
$idx++;

View File

@ -17,8 +17,8 @@ class IcingaHostGroupForm extends DirectorObjectForm
));
$this->addGroupDisplayNameElement()
->addAssignmentElements()
->setButtons();
$this->addAssignmentElements();
}
public function addAssignmentElements()

View File

@ -6,6 +6,8 @@ class IcingaHostGroup extends IcingaObjectGroup
{
protected $table = 'icinga_hostgroup';
// TODO: move to IcingaObjectGroup when supported for ServiceGroup
protected $supportsApplyRules = true;
public function supportsAssignments()
{
return true;
}
}

View File

@ -257,11 +257,26 @@ abstract class IcingaObject extends DbObject implements IcingaConfigRenderer
return $this->supportsFields;
}
/**
* Whether this object can be rendered as 'apply Object'
*
* @return bool
*/
public function supportsApplyRules()
{
return $this->supportsApplyRules;
}
/**
* Whether this object supports 'assign' properties
*
* @return bool
*/
public function supportsAssignments()
{
return $this->isApplyRule();
}
public function resolveUnresolvedRelatedProperties()
{
foreach ($this->unresolvedRelatedProperties as $name => $p) {
@ -309,7 +324,7 @@ abstract class IcingaObject extends DbObject implements IcingaConfigRenderer
return true;
}
if ($this->isApplyRule() && $this->assignments !== null && $this->assignments()->hasBeenModified()) {
if ($this->supportsAssignments() && $this->assignments !== null && $this->assignments()->hasBeenModified()) {
return true;
}
@ -1081,7 +1096,7 @@ abstract class IcingaObject extends DbObject implements IcingaConfigRenderer
protected function storeAssignments()
{
if ($this->isApplyRule()) {
if ($this->supportsAssignments()) {
$this->assignments !== null && $this->assignments()->store();
}
@ -1576,7 +1591,7 @@ abstract class IcingaObject extends DbObject implements IcingaConfigRenderer
protected function renderAssignments()
{
if ($this->isApplyRule()) {
if ($this->supportsAssignments()) {
return $this->assignments()->toConfigString();
} else {
return '';
@ -1908,7 +1923,7 @@ abstract class IcingaObject extends DbObject implements IcingaConfigRenderer
);
}
if ($this->isApplyRule()) {
if ($this->supportsAssignments()) {
$props['assignments'] = $this->assignments()->getPlain();
}
@ -2087,7 +2102,7 @@ abstract class IcingaObject extends DbObject implements IcingaConfigRenderer
}
}
if ($this->isApplyRule()) {
if ($this->supportsAssignments()) {
$props['assignments'] = $this->assignments()->getUnmodifiedPlain();
}

View File

@ -17,7 +17,7 @@ class IcingaObjectAssignments
public function __construct(IcingaObject $object)
{
if (! $object->isApplyRule()) {
if (! $object->supportsAssignments()) {
throw new ProgrammingError(
'I can only assign for applied objects, got %s',
$object->object_type

View File

@ -832,7 +832,7 @@ abstract class DirectorObjectForm extends QuickForm
}
if ($object instanceof IcingaObject) {
if ($object->isApplyRule()) {
if ($object->supportsAssignments()) {
$this->setElementValue('assignlist', $object->assignments()->getFormValues());
}