mirror of
https://github.com/redmine/redmine.git
synced 2024-07-22 21:19:50 +02:00
a78c724902
Patch by Felix Schäfer. git-svn-id: http://svn.redmine.org/redmine/trunk@15737 e93f8b46-1217-0410-a6f0-8f06a7374b81
16 lines
648 B
Ruby
16 lines
648 B
Ruby
class ClearEstimatedHoursOnParentIssues < ActiveRecord::Migration
|
|
def self.up
|
|
# Clears estimated hours on parent issues
|
|
Issue.where("rgt > lft + 1 AND estimated_hours > 0").update_all :estimated_hours => nil
|
|
end
|
|
|
|
def self.down
|
|
table_name = Issue.table_name
|
|
leaves_sum_select = "SELECT SUM(leaves.estimated_hours) FROM (SELECT * FROM #{table_name}) AS leaves" +
|
|
" WHERE leaves.root_id = #{table_name}.root_id AND leaves.lft > #{table_name}.lft AND leaves.rgt < #{table_name}.rgt" +
|
|
" AND leaves.rgt = leaves.lft + 1"
|
|
|
|
Issue.where("rgt > lft + 1").update_all "estimated_hours = (#{leaves_sum_select})"
|
|
end
|
|
end
|