Code snippets for symfony 1.x


Refine Tags

Snippets tagged "rebuild"

Tree Rebuild for sfPropelActAsNestedSetBehaviorPlugin plugin

Tree managed by sfPropelActAsNestedSetBehaviorPlugin plugin can be corrupted. In this case, the left & right value are not well numbered (there is hole in numbering) then some method like retrieveFirstChild() or hasChildren() can return incorrect results.

This is a method that scan all the tree and correct left & right numbering. It modify the left & right number only if necessary. It make at maximum one Select SQL request and one update SQL request by node.

It can work for any subtree of the given node or for entire tree if you give the root node as parameter. Second parameter indicate from which number, the numbering start.

  public static function rebuildSubTree($base_node,$number=1)
    if (is_array($children))
      foreach ($children as $child)
    if($base_node->getLeftValue()!=$left || $base_node->getRightValue()!=$right)
    return $number+1;
by Sylvain PAPET on 2008-02-13, tagged plugin  rebuild  sfpropelactasnestedsetbehaviorplugin  tree