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;
|
|
|
|
|
}
|
2016-11-29 09:06:38 -05:00
|
|
|
$node = $bp->getNode($this->getNodeName());
|
|
|
|
|
$existing = $node->getChildNames();
|
|
|
|
|
foreach ($this->children as $name) {
|
|
|
|
|
if (! in_array($name, $existing)) {
|
|
|
|
|
$existing[] = $name;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
$node->setChildNames($existing);
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
}
|