diff options
author | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2016-12-21 10:35:36 +0000 |
---|---|---|
committer | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2016-12-21 10:35:36 +0000 |
commit | b58cf253838bab9ef558b111b5094aae21890b45 (patch) | |
tree | 6fbd0e726f0af3de86cc8fab7a6259f81bc1f4d5 /lib/redmine | |
parent | 5a0884c90f71a43dbb1c1b10508050cbe2707a4a (diff) | |
download | redmine-b58cf253838bab9ef558b111b5094aae21890b45.tar.gz redmine-b58cf253838bab9ef558b111b5094aae21890b45.zip |
Adds .rebuild_single_tree! to rebuild a single tree (#24167).
git-svn-id: http://svn.redmine.org/redmine/trunk@16111 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'lib/redmine')
-rw-r--r-- | lib/redmine/nested_set/issue_nested_set.rb | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/lib/redmine/nested_set/issue_nested_set.rb b/lib/redmine/nested_set/issue_nested_set.rb index afbe6b995..8753f25de 100644 --- a/lib/redmine/nested_set/issue_nested_set.rb +++ b/lib/redmine/nested_set/issue_nested_set.rb @@ -183,6 +183,16 @@ module Redmine end end + def rebuild_single_tree!(root_id) + root = Issue.where(:parent_id => nil).find(root_id) + transaction do + where(root_id: root_id).reorder(:id).lock.ids + where(root_id: root_id).update_all(:lft => nil, :rgt => nil) + where(root_id: root_id, parent_id: nil).update_all(["lft = ?, rgt = ?", 1, 2]) + rebuild_nodes(root_id) + end + end + private def rebuild_nodes(parent_id = nil) |