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

68 lines
1.4 KiB
PHP
Raw Normal View History

2015-03-16 04:08:00 -04:00
<?php
namespace Icinga\Module\Businessprocess\Modification;
use Icinga\Module\Businessprocess\BusinessProcess;
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
*/
2015-03-16 04:08:00 -04:00
public function appliesTo(BusinessProcess $bp)
{
$parent = $this->getParentName();
if ($parent === null) {
return $bp->hasNode($this->getNodeName());
} else {
return $bp->hasNode($this->getNodeName()) && $bp->hasNode($this->getParentName()) ;
}
2015-03-16 04:08:00 -04:00
}
/**
* @inheritdoc
*/
2015-03-16 04:08:00 -04:00
public function applyTo(BusinessProcess $bp)
{
$parent = $this->getParentName();
if ($parent === null) {
$bp->removeNode($this->getNodeName());
} else {
$node = $bp->getNode($this->getNodeName());
$node->removeParent($parent);
if (! $node->hasParents()) {
$bp->removeNode($this->getNodeName());
}
}
2015-03-16 04:08:00 -04:00
}
}