2015-03-16 04:08:00 -04:00
|
|
|
<?php
|
|
|
|
|
|
2016-11-23 06:27:55 -05:00
|
|
|
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
|
|
|
|
2016-11-22 15:11:26 -05:00
|
|
|
/**
|
|
|
|
|
* NodeRemoveAction
|
|
|
|
|
*
|
|
|
|
|
* Tracks removed nodes
|
|
|
|
|
*
|
|
|
|
|
* @package Icinga\Module\Businessprocess
|
|
|
|
|
*/
|
2015-03-16 04:08:00 -04:00
|
|
|
class NodeRemoveAction extends NodeAction
|
|
|
|
|
{
|
2017-01-03 05:23:05 -05:00
|
|
|
protected $preserveProperties = array('parentName');
|
2016-12-16 13:32:36 -05:00
|
|
|
|
2017-01-03 05:23:05 -05:00
|
|
|
protected $parentName;
|
2016-12-16 13:32:36 -05:00
|
|
|
|
|
|
|
|
/**
|
2017-01-03 05:23:05 -05:00
|
|
|
* @param $parentName
|
2016-12-16 13:32:36 -05:00
|
|
|
* @return $this
|
|
|
|
|
*/
|
2017-01-03 05:23:05 -05:00
|
|
|
public function setParentName($parentName = null)
|
2016-12-16 13:32:36 -05:00
|
|
|
{
|
2017-01-03 05:23:05 -05:00
|
|
|
$this->parentName = $parentName;
|
2016-12-16 13:32:36 -05:00
|
|
|
return $this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @return mixed
|
|
|
|
|
*/
|
2017-01-03 05:23:05 -05:00
|
|
|
public function getParentName()
|
2016-12-16 13:32:36 -05:00
|
|
|
{
|
2017-01-03 05:23:05 -05:00
|
|
|
return $this->parentName;
|
2016-12-16 13:32:36 -05:00
|
|
|
}
|
|
|
|
|
|
2016-11-22 15:11:26 -05:00
|
|
|
/**
|
|
|
|
|
* @inheritdoc
|
|
|
|
|
*/
|
2017-01-11 11:36:32 -05:00
|
|
|
public function appliesTo(BpConfig $config)
|
2015-03-16 04:08:00 -04:00
|
|
|
{
|
2017-01-03 05:23:05 -05:00
|
|
|
$parent = $this->getParentName();
|
|
|
|
|
if ($parent === null) {
|
2017-01-11 11:36:32 -05:00
|
|
|
return $config->hasNode($this->getNodeName());
|
2017-01-03 05:23:05 -05:00
|
|
|
} else {
|
2017-01-11 11:36:32 -05:00
|
|
|
return $config->hasNode($this->getNodeName()) && $config->hasNode($this->getParentName()) ;
|
2016-12-16 13:32:36 -05:00
|
|
|
}
|
2015-03-16 04:08:00 -04:00
|
|
|
}
|
|
|
|
|
|
2016-11-22 15:11:26 -05:00
|
|
|
/**
|
|
|
|
|
* @inheritdoc
|
|
|
|
|
*/
|
2017-01-11 11:36:32 -05:00
|
|
|
public function applyTo(BpConfig $config)
|
2015-03-16 04:08:00 -04:00
|
|
|
{
|
2017-01-03 05:23:05 -05:00
|
|
|
$parent = $this->getParentName();
|
|
|
|
|
if ($parent === null) {
|
2017-01-11 11:36:32 -05:00
|
|
|
$config->removeNode($this->getNodeName());
|
2016-12-16 13:32:36 -05:00
|
|
|
} else {
|
2017-01-11 11:36:32 -05:00
|
|
|
$node = $config->getNode($this->getNodeName());
|
2017-01-03 05:23:05 -05:00
|
|
|
$node->removeParent($parent);
|
|
|
|
|
if (! $node->hasParents()) {
|
2017-01-11 11:36:32 -05:00
|
|
|
$config->removeNode($this->getNodeName());
|
2017-01-03 05:23:05 -05:00
|
|
|
}
|
2016-12-16 13:32:36 -05:00
|
|
|
}
|
2015-03-16 04:08:00 -04:00
|
|
|
}
|
|
|
|
|
}
|