Ticket #1833 (closed defect: fixed)
Nested set: makeRoot query order is wrong
| Reported by: | weett | Owned by: | romanb |
|---|---|---|---|
| Priority: | blocker | Milestone: | 1.0.7 |
| Component: | NestedSet | Version: | 1.0.4 |
| Severity: | abc | Keywords: | |
| Cc: | Has Test: | no | |
| Status: | Pending Core Response | Has Patch: | yes |
Description
When calling makeRoot the order of things going on is wrong.
First step should be to extract all the nodes from the old tree and move them into the new tree. Then the old tree should be reordered.
Currently the steps are the other way around, which corrupts the tree if a node with subnodes is moved to the root.
I created a patch, see this diff. It only moves code around.
Index: Doctrine/Node/NestedSet.php
===================================================================
--- Doctrine/Node/NestedSet.php (revision 5358)
+++ Doctrine/Node/NestedSet.php (working copy)
@@ -803,17 +803,6 @@
try {
$conn->beginInternalTransaction();
- // Detach from old tree (close gap in old tree)
- $first = $oldRgt + 1;
- $delta = $oldLft - $oldRgt - 1;
- $this->shiftRLValues($first, $delta, $this->getRootValue());
-
- // Set new lft/rgt/root/level values for root node
- $this->setLeftValue(1);
- $this->setRightValue($oldRgt - $oldLft + 1);
- $this->setRootValue($newRootId);
- $this->record['level'] = 0;
-
// Update descendants lft/rgt/root/level values
$diff = 1 - $oldLft;
$newRoot = $newRootId;
@@ -830,6 +819,17 @@
$q = $this->_tree->returnQueryWithRootId($q, $oldRoot);
$q->execute();
+ // Detach from old tree (close gap in old tree)
+ $first = $oldRgt + 1;
+ $delta = $oldLft - $oldRgt - 1;
+ $this->shiftRLValues($first, $delta, $this->getRootValue());
+
+ // Set new lft/rgt/root/level values for root node
+ $this->setLeftValue(1);
+ $this->setRightValue($oldRgt - $oldLft + 1);
+ $this->setRootValue($newRootId);
+ $this->record['level'] = 0;
+
$conn->commit();
return true;
The version I use is the version currently included in the symfony plugin. I also checked the 1.1 branch; the error is still there.
I don't know how to make a test for this. I'll add some pictures of my test, these can be converted into a test quite easily I believe.
Attachments
Change History
Note: See
TracTickets for help on using
tickets.
