DeleteNode: use parent, not path

fixes #94
This commit is contained in:
Thomas Gelf 2017-01-27 14:57:57 +01:00
parent b0e38df177
commit 0c395cc005
5 changed files with 37 additions and 13 deletions

View file

@ -135,7 +135,7 @@ class DeleteNodeForm extends QuickForm
switch ($this->getValue('confirm')) {
case 'yes':
$changes->deleteNode($this->node, $this->path);
$changes->deleteNode($this->node, $this->parentNode->getName());
break;
case 'all':
$changes->deleteNode($this->node);

View file

@ -416,6 +416,24 @@ class BpConfig
return $node;
}
public function calculateAllStates()
{
foreach ($this->getRootNodes() as $node) {
$node->getState();
}
return $this;
}
public function clearAllStates()
{
foreach ($this->getBpNodes() as $node) {
$node->clearState();
}
return $this;
}
public function listInvolvedHostNames()
{
return array_keys($this->hosts);

View file

@ -44,7 +44,7 @@ class NodeRemoveAction extends NodeAction
if ($parent === null) {
return $config->hasNode($this->getNodeName());
} else {
return $config->hasNode($this->getNodeName()) && $config->hasNode($this->getParentName()) ;
return $config->hasNode($this->getNodeName()) && $config->hasNode($this->getParentName());
}
}
@ -53,14 +53,19 @@ class NodeRemoveAction extends NodeAction
*/
public function applyTo(BpConfig $config)
{
$parent = $this->getParentName();
if ($parent === null) {
$config->removeNode($this->getNodeName());
$config->calculateAllStates();
$name = $this->getNodeName();
$parentName = $this->getParentName();
if ($parentName === null) {
$config->removeNode($name);
} else {
$node = $config->getNode($this->getNodeName());
$node->removeParent($parent);
$node = $config->getNode($name);
$parent = $config->getBpNode($parentName);
$parent->getState();
$parent->removeChild($name);
$node->removeParent($parentName);
if (! $node->hasParents()) {
$config->removeNode($this->getNodeName());
$config->removeNode($name);
}
}
}

View file

@ -96,15 +96,14 @@ class ProcessChanges
/**
* @param Node $node
* @param array $path
*
* @param string $parentName
* @return $this
*/
public function deleteNode(Node $node, array $path = null)
public function deleteNode(Node $node, $parentName = null)
{
$action = new NodeRemoveAction($node);
if ($path !== null) {
$action->setPath($path);
if ($parentName !== null) {
$action->setParentName($parentName);
}
return $this->push($action);

View file

@ -307,6 +307,8 @@ abstract class Node
return $parent->getName() !== $name;
}
);
return $this;
}
/**