NodeRemoveAction: rework to fit current reality

This commit is contained in:
Thomas Gelf 2016-12-16 19:32:36 +01:00
parent 0d696216e2
commit 9e30be79c6
2 changed files with 38 additions and 4 deletions

View file

@ -13,12 +13,39 @@ use Icinga\Module\Businessprocess\BusinessProcess;
*/
class NodeRemoveAction extends NodeAction
{
protected $preserveProperties = array('path');
protected $path;
/**
* @param array $path
* @return $this
*/
public function setPath(array $path)
{
$this->path = $path;
return $this;
}
/**
* @return mixed
*/
public function getPath()
{
return $this->path;
}
/**
* @inheritdoc
*/
public function appliesTo(BusinessProcess $bp)
{
return $bp->hasNode($this->getNodeName());
$path = $this->getPath();
if ($path === null) {
return $bp->hasNodeByPath($this->getNodeName(), $this->getPath());
} else {
return $bp->hasNode($this->getNodeName());
}
}
/**
@ -26,6 +53,11 @@ class NodeRemoveAction extends NodeAction
*/
public function applyTo(BusinessProcess $bp)
{
$bp->removeNode($this->getNodeName());
$path = $this->getPath();
if ($path === null) {
$bp->removeNode($this->getNodeName());
} else {
$bp->removeNodeByPath($this->getNodeName(), $this->getPath());
}
}
}

View file

@ -99,9 +99,11 @@ class ProcessChanges
*
* @return $this
*/
public function deleteNode(Node $node)
public function deleteNode(Node $node, array $path)
{
return $this->push(new NodeRemoveAction($node));
$action = new NodeRemoveAction($node);
$action->setProperties('path', $path);
return $this->push($action);
}
/**