icingaweb2-module-businessp.../library/Businessprocess/Modification/NodeRemoveAction.php

73 lines
1.6 KiB
PHP
Raw Normal View History

2015-03-16 04:08:00 -04:00
<?php
namespace Icinga\Module\Businessprocess\Modification;
2017-01-11 08:04:45 -05:00
use Icinga\Module\Businessprocess\BpConfig;
2015-03-16 04:08:00 -04:00
/**
* NodeRemoveAction
*
* Tracks removed nodes
*
* @package Icinga\Module\Businessprocess
*/
2015-03-16 04:08:00 -04:00
class NodeRemoveAction extends NodeAction
{
protected $preserveProperties = array('parentName');
protected $parentName;
/**
* @param $parentName
* @return $this
*/
public function setParentName($parentName = null)
{
$this->parentName = $parentName;
return $this;
}
/**
* @return mixed
*/
public function getParentName()
{
return $this->parentName;
}
/**
* @inheritdoc
*/
2017-01-11 11:36:32 -05:00
public function appliesTo(BpConfig $config)
2015-03-16 04:08:00 -04:00
{
$parent = $this->getParentName();
if ($parent === null) {
2017-01-11 11:36:32 -05:00
return $config->hasNode($this->getNodeName());
} else {
return $config->hasNode($this->getNodeName()) && $config->hasNode($this->getParentName());
}
2015-03-16 04:08:00 -04:00
}
/**
* @inheritdoc
*/
2017-01-11 11:36:32 -05:00
public function applyTo(BpConfig $config)
2015-03-16 04:08:00 -04:00
{
$config->calculateAllStates();
$name = $this->getNodeName();
$parentName = $this->getParentName();
if ($parentName === null) {
$config->removeNode($name);
} else {
$node = $config->getNode($name);
$parent = $config->getBpNode($parentName);
$parent->getState();
$parent->removeChild($name);
$node->removeParent($parentName);
if (! $node->hasParents()) {
$config->removeNode($name);
}
}
2015-03-16 04:08:00 -04:00
}
}