2016-11-29 09:06:38 -05:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace Icinga\Module\Businessprocess\Modification;
|
|
|
|
|
|
2017-01-11 08:04:45 -05:00
|
|
|
use Icinga\Module\Businessprocess\BpConfig;
|
2017-01-11 11:36:32 -05:00
|
|
|
use Icinga\Module\Businessprocess\BpNode;
|
2016-11-29 09:06:38 -05:00
|
|
|
|
|
|
|
|
class NodeAddChildrenAction extends NodeAction
|
|
|
|
|
{
|
|
|
|
|
protected $children = array();
|
|
|
|
|
|
|
|
|
|
protected $preserveProperties = array('children');
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @inheritdoc
|
|
|
|
|
*/
|
2017-01-11 11:36:32 -05:00
|
|
|
public function appliesTo(BpConfig $config)
|
2016-11-29 09:06:38 -05:00
|
|
|
{
|
|
|
|
|
$name = $this->getNodeName();
|
|
|
|
|
|
2017-01-11 11:36:32 -05:00
|
|
|
if (! $config->hasNode($name)) {
|
2016-11-29 09:06:38 -05:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2017-01-11 11:36:32 -05:00
|
|
|
return $config->getNode($name) instanceof BpNode;
|
2016-11-29 09:06:38 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @inheritdoc
|
|
|
|
|
*/
|
2017-01-11 11:36:32 -05:00
|
|
|
public function applyTo(BpConfig $config)
|
2016-11-29 09:06:38 -05:00
|
|
|
{
|
|
|
|
|
/** @var BpNode $node */
|
2017-01-03 05:37:39 -05:00
|
|
|
if (! $this->hasNode()) {
|
|
|
|
|
// TODO: We end up here when defining "top nodes", but that would probably
|
|
|
|
|
// be a different action
|
|
|
|
|
return $this;
|
|
|
|
|
}
|
2017-01-11 11:38:19 -05:00
|
|
|
|
|
|
|
|
$node = $config->getBpNode($this->getNodeName());
|
|
|
|
|
|
2016-11-29 09:06:38 -05:00
|
|
|
foreach ($this->children as $name) {
|
2017-01-11 11:38:19 -05:00
|
|
|
if (! $config->hasNode($name)) {
|
|
|
|
|
if (strpos($name, ';') !== false) {
|
|
|
|
|
list($host, $service) = preg_split('/;/', $name, 2);
|
|
|
|
|
|
|
|
|
|
if ($service === 'Hoststatus') {
|
|
|
|
|
$config->createHost($host);
|
|
|
|
|
} else {
|
|
|
|
|
$config->createService($host, $service);
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-11-29 09:06:38 -05:00
|
|
|
}
|
2017-01-11 11:38:19 -05:00
|
|
|
$node->addChild($config->getNode($name));
|
2016-11-29 09:06:38 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param array|string $children
|
|
|
|
|
* @return $this
|
|
|
|
|
*/
|
|
|
|
|
public function setChildren($children)
|
|
|
|
|
{
|
|
|
|
|
if (is_string($children)) {
|
|
|
|
|
$children = array($children);
|
|
|
|
|
}
|
|
|
|
|
$this->children = $children;
|
|
|
|
|
return $this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @return array
|
|
|
|
|
*/
|
|
|
|
|
public function getChildren()
|
|
|
|
|
{
|
|
|
|
|
return $this->children;
|
|
|
|
|
}
|
|
|
|
|
}
|