From 01d81ec6b42d30db83a1a12bbd2e5bc08944b0e2 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Thu, 29 Jan 2009 02:57:29 +0000 Subject: Update the level when moving items --- core/libraries/ORM_MPTT.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'core') diff --git a/core/libraries/ORM_MPTT.php b/core/libraries/ORM_MPTT.php index e67478a7..36065a69 100644 --- a/core/libraries/ORM_MPTT.php +++ b/core/libraries/ORM_MPTT.php @@ -222,9 +222,17 @@ class ORM_MPTT_Core extends ORM { $original_left = $this->left; $original_right = $this->right; $target_right = $target->right; + $level_delta = $target->level - $this->level; $this->lock(); try { + if ($level_delta) { + // Update the levels for the to-be-moved items + $this->db->query( + "UPDATE `{$this->table_name}` SET `level` = `level` + $level_delta" . + " WHERE `left` >= $original_left AND `right` <= $original_right"); + } + // Make a hole in the target for the move $target->db->query( "UPDATE `{$this->table_name}` SET `left` = `left` + $size_of_hole" . @@ -261,7 +269,6 @@ class ORM_MPTT_Core extends ORM { $this->db->query( "UPDATE `{$this->table_name}` SET `right` = `right` - $size_of_hole" . " WHERE `right` > $right"); - } catch (Exception $e) { $this->unlock(); throw $e; -- cgit v1.2.3