mirror of
https://github.com/Icinga/icingaweb2-module-director.git
synced 2025-08-15 23:08:11 +02:00
IcingaServiceForm: prepare support for...
...host-generated services
This commit is contained in:
parent
4f7647c258
commit
c7c1bfe998
@ -12,8 +12,20 @@ class IcingaServiceForm extends DirectorObjectForm
|
||||
|
||||
private $apply;
|
||||
|
||||
private $hostGenerated = false;
|
||||
|
||||
public function setHostGenerated($hostGenerated = true)
|
||||
{
|
||||
$this->hostGenerated = $hostGenerated;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function setup()
|
||||
{
|
||||
if ($this->hostGenerated) {
|
||||
return $this->setupHostGenerated();
|
||||
}
|
||||
|
||||
if (!$this->isNew() && $this->host === null) {
|
||||
$this->host = $this->object->getResolvedRelated('host');
|
||||
}
|
||||
@ -57,6 +69,22 @@ class IcingaServiceForm extends DirectorObjectForm
|
||||
->setButtons();
|
||||
}
|
||||
|
||||
protected function setupHostGenerated()
|
||||
{
|
||||
$this->addNameElement()
|
||||
->addImportsElement()
|
||||
->addDisabledElement();
|
||||
|
||||
$this->setSubmitLabel(
|
||||
$this->translate('Override vars')
|
||||
);
|
||||
|
||||
foreach (array('object_name', 'imports') as $name) {
|
||||
$this->getElement($name)->setAttrib('disabled', 'disabled');
|
||||
$this->getElement($name)->setRequired(false);
|
||||
}
|
||||
}
|
||||
|
||||
protected function addAssignmentElements()
|
||||
{
|
||||
if (!$this->object || !$this->object->isApplyRule()) {
|
||||
@ -211,4 +239,27 @@ class IcingaServiceForm extends DirectorObjectForm
|
||||
|
||||
return $db->fetchPairs($select);
|
||||
}
|
||||
|
||||
public function onSuccess()
|
||||
{
|
||||
if (! $this->hostGenerated) {
|
||||
return parent::onSuccess();
|
||||
}
|
||||
|
||||
$modified =array();
|
||||
foreach ($this->object->vars() as $key => $var) {
|
||||
$modified[$key] = $var->getValue();
|
||||
}
|
||||
|
||||
$host = $this->host;
|
||||
if (empty($modified)) {
|
||||
unset($host->vars()->_director_apply_override);
|
||||
} else {
|
||||
$host->vars()->_director_apply_override = $modified;
|
||||
}
|
||||
|
||||
if ($host->hasBeenModified()) {
|
||||
$host->store();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user