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')) { switch ($this->getValue('confirm')) {
case 'yes': case 'yes':
$changes->deleteNode($this->node, $this->path); $changes->deleteNode($this->node, $this->parentNode->getName());
break; break;
case 'all': case 'all':
$changes->deleteNode($this->node); $changes->deleteNode($this->node);

View file

@ -416,6 +416,24 @@ class BpConfig
return $node; 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() public function listInvolvedHostNames()
{ {
return array_keys($this->hosts); return array_keys($this->hosts);

View file

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

View file

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

View file

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