Details
-
Type:
Bug
-
Status:
Open
-
Priority:
Major
-
Resolution: Unresolved
-
Affects Version/s: 1.2.3
-
Fix Version/s: None
-
Component/s: Nested Set
-
Labels:None
-
Environment:Ubuntu 10.04 x64
PHP 5.3.2
Description
The best way I can explain the issue is with code. Please see the below:
<?php
$root = new Test();
$root->name = '1';
$root->save();
// Create root node
$tree = Doctrine::getTable('Test')->getTree();
$tree->createRoot($root);
// Create child node
$child1 = new Test();
$child1->name = '2';
$child1->save();
// Add child
$child1->getNode()->moveAsLastChildOf($root);
// Create child node
$child2 = new Test();
$child2->name = '3';
$child2->save();
// Add child2 as node of child1
$child2->getNode()->moveAsLastChildOf($child1);
// Create child node
$child3 = new Test();
$child3->name = '4';
$child3->save();
// Add child3 as node of child2
$child3->getNode()->moveAsLastChildOf($child2);
// Add another root just to be nice
$root2 = new Test();
$root2->name = '5';
$root2->save();
// Create root node
$tree->createRoot($root2);
/**
* Now we have the following tree (Each '-' indicates 1 level):
* 1
* - 2
* - - 3
* - - - 4
* 5
*/
/**
* Lets say I want to move node '3' to be a root.
* With this I assume that all of the current nodes
* children will be moved with it:
*/
$tree->createRoot(child2);
/**
* Now the (implied) tree should look like this:
* 1
* - 2
* 3
* - 4
* 5
*
* Instead, the tree actually looks like this:
* 1
* - 2
* - - - 4
* 3
* 5
*/
/**
* I will now demostrate incorrect moving back of child nodes.
*/
$child2->getNode()->moveAsLastChildOf($child1);
/**
* Now the tree should go back to looking like this:
* 1
* - 2
* - - 3
* - - - 4
* 5
*
* But the tree now looks like this:
* 1
* - 2
* - - - 4
* - - 3
* 5
*/
Fixing code spacing