@@ -1,74 +1,74 | |||
|
1 | 1 | # Redmine - project management software |
|
2 | 2 | # Copyright (C) 2006-2016 Jean-Philippe Lang |
|
3 | 3 | # |
|
4 | 4 | # This program is free software; you can redistribute it and/or |
|
5 | 5 | # modify it under the terms of the GNU General Public License |
|
6 | 6 | # as published by the Free Software Foundation; either version 2 |
|
7 | 7 | # of the License, or (at your option) any later version. |
|
8 | 8 | # |
|
9 | 9 | # This program is distributed in the hope that it will be useful, |
|
10 | 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 | 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 | 12 | # GNU General Public License for more details. |
|
13 | 13 | # |
|
14 | 14 | # You should have received a copy of the GNU General Public License |
|
15 | 15 | # along with this program; if not, write to the Free Software |
|
16 | 16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
17 | 17 | |
|
18 | 18 | class WorkflowRule < ActiveRecord::Base |
|
19 | 19 | self.table_name = "#{table_name_prefix}workflows#{table_name_suffix}" |
|
20 | 20 | |
|
21 | 21 | belongs_to :role |
|
22 | 22 | belongs_to :tracker |
|
23 | 23 | belongs_to :old_status, :class_name => 'IssueStatus' |
|
24 | 24 | belongs_to :new_status, :class_name => 'IssueStatus' |
|
25 | 25 | |
|
26 | 26 | validates_presence_of :role, :tracker |
|
27 | 27 | attr_protected :id |
|
28 | 28 | |
|
29 | 29 | # Copies workflows from source to targets |
|
30 | 30 | def self.copy(source_tracker, source_role, target_trackers, target_roles) |
|
31 | 31 | unless source_tracker.is_a?(Tracker) || source_role.is_a?(Role) |
|
32 | 32 | raise ArgumentError.new("source_tracker or source_role must be specified") |
|
33 | 33 | end |
|
34 | 34 | |
|
35 | 35 | target_trackers = [target_trackers].flatten.compact |
|
36 | 36 | target_roles = [target_roles].flatten.compact |
|
37 | 37 | |
|
38 | 38 | target_trackers = Tracker.sorted.to_a if target_trackers.empty? |
|
39 | 39 | target_roles = Role.all.select(&:consider_workflow?) if target_roles.empty? |
|
40 | 40 | |
|
41 | 41 | target_trackers.each do |target_tracker| |
|
42 | 42 | target_roles.each do |target_role| |
|
43 | 43 | copy_one(source_tracker || target_tracker, |
|
44 | 44 | source_role || target_role, |
|
45 | 45 | target_tracker, |
|
46 | 46 | target_role) |
|
47 | 47 | end |
|
48 | 48 | end |
|
49 | 49 | end |
|
50 | 50 | |
|
51 | 51 | # Copies a single set of workflows from source to target |
|
52 | 52 | def self.copy_one(source_tracker, source_role, target_tracker, target_role) |
|
53 | 53 | unless source_tracker.is_a?(Tracker) && !source_tracker.new_record? && |
|
54 | 54 | source_role.is_a?(Role) && !source_role.new_record? && |
|
55 | 55 | target_tracker.is_a?(Tracker) && !target_tracker.new_record? && |
|
56 | 56 | target_role.is_a?(Role) && !target_role.new_record? |
|
57 | 57 | |
|
58 | 58 | raise ArgumentError.new("arguments can not be nil or unsaved objects") |
|
59 | 59 | end |
|
60 | 60 | |
|
61 | 61 | if source_tracker == target_tracker && source_role == target_role |
|
62 | 62 | false |
|
63 | 63 | else |
|
64 | 64 | transaction do |
|
65 |
|
|
|
65 | where(:tracker_id => target_tracker.id, :role_id => target_role.id).delete_all | |
|
66 | 66 | connection.insert "INSERT INTO #{WorkflowRule.table_name} (tracker_id, role_id, old_status_id, new_status_id, author, assignee, field_name, #{connection.quote_column_name 'rule'}, type)" + |
|
67 | 67 | " SELECT #{target_tracker.id}, #{target_role.id}, old_status_id, new_status_id, author, assignee, field_name, #{connection.quote_column_name 'rule'}, type" + |
|
68 | 68 | " FROM #{WorkflowRule.table_name}" + |
|
69 | 69 | " WHERE tracker_id = #{source_tracker.id} AND role_id = #{source_role.id}" |
|
70 | 70 | end |
|
71 | 71 | true |
|
72 | 72 | end |
|
73 | 73 | end |
|
74 | 74 | end |
General Comments 0
You need to be logged in to leave comments.
Login now