l3pp4rd/DoctrineExtensions — pull request #429 by butt (2012-08-10 14:30:25+00:00)
Title: updateNode (update node["parent"])

Hello.

I need to update whole tree in db (from admin area build on SonataAdminBundle)
I have an array of arrays (hierarchy).

I use this code in Repository which extends NestedTreeRepository

public function updateChilds($childrens,$parent)
{
foreach($childrens as $position=>$child)
{
$node = $this->find($child->id);
$meta = $this->getClassMetadata();

if(($parent != null) && ($node->getParent()->getId() != $parent->getId())){
if($position > 0){
$siblingNode = $this->find($childrens[$position-1]->id);
$this->listener->getStrategy($this->_em, $meta->name)->updateNode($this->_em,$node,$siblingNode,Nested::NEXT_SIBLING);
}else{
$node->setParent($parent);
$this->listener->getStrategy($this->_em, $meta->name)->updateNode($this->_em,$node,$parent,Nested::LAST_CHILD);
}
}else{
$this->listener->getStrategy($this->_em, $meta->name)->updateNode($this->_em,$node,$parent,Nested::LAST_CHILD);
}
if(isset($child->children)){
$this->updateChilds($child->children,$node);
}
}
return true;
}

But current library do not change parent of the node when updateNode is called. Also, I cant do it from my repository code.

I have added patch for this issue, not sure if its correct approach though.

Could you please offer another solution for this task or merge this PR.

Thanks