Mercurial > hg > soundsoftware-site
diff app/models/issue_status.rb @ 1115:433d4f72a19b redmine-2.2
Update to Redmine SVN revision 11137 on 2.2-stable branch
author | Chris Cannam |
---|---|
date | Mon, 07 Jan 2013 12:01:42 +0000 |
parents | cbb26bc654de |
children | 622f24f53b42 |
line wrap: on
line diff
--- a/app/models/issue_status.rb Wed Jun 27 14:54:18 2012 +0100 +++ b/app/models/issue_status.rb Mon Jan 07 12:01:42 2013 +0000 @@ -1,5 +1,5 @@ # Redmine - project management software -# Copyright (C) 2006-2011 Jean-Philippe Lang +# Copyright (C) 2006-2012 Jean-Philippe Lang # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License @@ -17,10 +17,10 @@ class IssueStatus < ActiveRecord::Base before_destroy :check_integrity - has_many :workflows, :foreign_key => "old_status_id" + has_many :workflows, :class_name => 'WorkflowTransition', :foreign_key => "old_status_id" acts_as_list - before_destroy :delete_workflows + before_destroy :delete_workflow_rules after_save :update_default validates_presence_of :name @@ -28,23 +28,23 @@ validates_length_of :name, :maximum => 30 validates_inclusion_of :default_done_ratio, :in => 0..100, :allow_nil => true - named_scope :named, lambda {|arg| { :conditions => ["LOWER(#{table_name}.name) = LOWER(?)", arg.to_s.strip]}} + scope :sorted, order("#{table_name}.position ASC") + scope :named, lambda {|arg| where("LOWER(#{table_name}.name) = LOWER(?)", arg.to_s.strip)} def update_default - IssueStatus.update_all("is_default=#{connection.quoted_false}", ['id <> ?', id]) if self.is_default? + IssueStatus.update_all({:is_default => false}, ['id <> ?', id]) if self.is_default? end # Returns the default status for new issues def self.default - find(:first, :conditions =>["is_default=?", true]) + where(:is_default => true).first end # Update all the +Issues+ setting their done_ratio to the value of their +IssueStatus+ def self.update_issue_done_ratios if Issue.use_status_for_done_ratio? - IssueStatus.find(:all, :conditions => ["default_done_ratio >= 0"]).each do |status| - Issue.update_all(["done_ratio = ?", status.default_done_ratio], - ["status_id = ?", status.id]) + IssueStatus.where("default_done_ratio >= 0").all.each do |status| + Issue.update_all({:done_ratio => status.default_done_ratio}, {:status_id => status.id}) end end @@ -61,7 +61,7 @@ w.tracker_id == tracker.id && ((!w.author && !w.assignee) || (author && w.author) || (assignee && w.assignee)) end - transitions.collect{|w| w.new_status}.compact.sort + transitions.map(&:new_status).compact.sort else [] end @@ -75,12 +75,12 @@ conditions << " OR author = :true" if author conditions << " OR assignee = :true" if assignee - workflows.find(:all, - :include => :new_status, - :conditions => ["role_id IN (:role_ids) AND tracker_id = :tracker_id AND (#{conditions})", + workflows. + includes(:new_status). + where(["role_id IN (:role_ids) AND tracker_id = :tracker_id AND (#{conditions})", {:role_ids => roles.collect(&:id), :tracker_id => tracker.id, :true => true, :false => false} - ] - ).collect{|w| w.new_status}.compact.sort + ]).all. + map(&:new_status).compact.sort else [] end @@ -92,13 +92,14 @@ def to_s; name end -private + private + def check_integrity - raise "Can't delete status" if Issue.find(:first, :conditions => ["status_id=?", self.id]) + raise "Can't delete status" if Issue.where(:status_id => id).any? end # Deletes associated workflows - def delete_workflows - Workflow.delete_all(["old_status_id = :id OR new_status_id = :id", {:id => id}]) + def delete_workflow_rules + WorkflowRule.delete_all(["old_status_id = :id OR new_status_id = :id", {:id => id}]) end end