@@ -1,16 +1,16 | |||||
1 |
# |
|
1 | # Redmine - project management software | |
2 | # Copyright (C) 2006 Jean-Philippe Lang |
|
2 | # Copyright (C) 2006-2011 Jean-Philippe Lang | |
3 | # |
|
3 | # | |
4 | # This program is free software; you can redistribute it and/or |
|
4 | # This program is free software; you can redistribute it and/or | |
5 | # modify it under the terms of the GNU General Public License |
|
5 | # modify it under the terms of the GNU General Public License | |
6 | # as published by the Free Software Foundation; either version 2 |
|
6 | # as published by the Free Software Foundation; either version 2 | |
7 | # of the License, or (at your option) any later version. |
|
7 | # of the License, or (at your option) any later version. | |
8 |
# |
|
8 | # | |
9 | # This program is distributed in the hope that it will be useful, |
|
9 | # This program is distributed in the hope that it will be useful, | |
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 | # GNU General Public License for more details. |
|
12 | # GNU General Public License for more details. | |
13 |
# |
|
13 | # | |
14 | # You should have received a copy of the GNU General Public License |
|
14 | # You should have received a copy of the GNU General Public License | |
15 | # along with this program; if not, write to the Free Software |
|
15 | # along with this program; if not, write to the Free Software | |
16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |
@@ -21,13 +21,13 class Workflow < ActiveRecord::Base | |||||
21 | belongs_to :new_status, :class_name => 'IssueStatus', :foreign_key => 'new_status_id' |
|
21 | belongs_to :new_status, :class_name => 'IssueStatus', :foreign_key => 'new_status_id' | |
22 |
|
22 | |||
23 | validates_presence_of :role, :old_status, :new_status |
|
23 | validates_presence_of :role, :old_status, :new_status | |
24 |
|
24 | |||
25 | # Returns workflow transitions count by tracker and role |
|
25 | # Returns workflow transitions count by tracker and role | |
26 | def self.count_by_tracker_and_role |
|
26 | def self.count_by_tracker_and_role | |
27 | counts = connection.select_all("SELECT role_id, tracker_id, count(id) AS c FROM #{Workflow.table_name} GROUP BY role_id, tracker_id") |
|
27 | counts = connection.select_all("SELECT role_id, tracker_id, count(id) AS c FROM #{Workflow.table_name} GROUP BY role_id, tracker_id") | |
28 | roles = Role.find(:all, :order => 'builtin, position') |
|
28 | roles = Role.find(:all, :order => 'builtin, position') | |
29 | trackers = Tracker.find(:all, :order => 'position') |
|
29 | trackers = Tracker.find(:all, :order => 'position') | |
30 |
|
30 | |||
31 | result = [] |
|
31 | result = [] | |
32 | trackers.each do |tracker| |
|
32 | trackers.each do |tracker| | |
33 | t = [] |
|
33 | t = [] | |
@@ -37,7 +37,7 class Workflow < ActiveRecord::Base | |||||
37 | end |
|
37 | end | |
38 | result << [tracker, t] |
|
38 | result << [tracker, t] | |
39 | end |
|
39 | end | |
40 |
|
40 | |||
41 | result |
|
41 | result | |
42 | end |
|
42 | end | |
43 |
|
43 | |||
@@ -51,19 +51,19 class Workflow < ActiveRecord::Base | |||||
51 | uniq. |
|
51 | uniq. | |
52 | sort |
|
52 | sort | |
53 | end |
|
53 | end | |
54 |
|
54 | |||
55 | # Copies workflows from source to targets |
|
55 | # Copies workflows from source to targets | |
56 | def self.copy(source_tracker, source_role, target_trackers, target_roles) |
|
56 | def self.copy(source_tracker, source_role, target_trackers, target_roles) | |
57 | unless source_tracker.is_a?(Tracker) || source_role.is_a?(Role) |
|
57 | unless source_tracker.is_a?(Tracker) || source_role.is_a?(Role) | |
58 | raise ArgumentError.new("source_tracker or source_role must be specified") |
|
58 | raise ArgumentError.new("source_tracker or source_role must be specified") | |
59 | end |
|
59 | end | |
60 |
|
60 | |||
61 | target_trackers = [target_trackers].flatten.compact |
|
61 | target_trackers = [target_trackers].flatten.compact | |
62 | target_roles = [target_roles].flatten.compact |
|
62 | target_roles = [target_roles].flatten.compact | |
63 |
|
63 | |||
64 | target_trackers = Tracker.all if target_trackers.empty? |
|
64 | target_trackers = Tracker.all if target_trackers.empty? | |
65 | target_roles = Role.all if target_roles.empty? |
|
65 | target_roles = Role.all if target_roles.empty? | |
66 |
|
66 | |||
67 | target_trackers.each do |target_tracker| |
|
67 | target_trackers.each do |target_tracker| | |
68 | target_roles.each do |target_role| |
|
68 | target_roles.each do |target_role| | |
69 | copy_one(source_tracker || target_tracker, |
|
69 | copy_one(source_tracker || target_tracker, | |
@@ -73,17 +73,17 class Workflow < ActiveRecord::Base | |||||
73 | end |
|
73 | end | |
74 | end |
|
74 | end | |
75 | end |
|
75 | end | |
76 |
|
76 | |||
77 | # Copies a single set of workflows from source to target |
|
77 | # Copies a single set of workflows from source to target | |
78 | def self.copy_one(source_tracker, source_role, target_tracker, target_role) |
|
78 | def self.copy_one(source_tracker, source_role, target_tracker, target_role) | |
79 | unless source_tracker.is_a?(Tracker) && !source_tracker.new_record? && |
|
79 | unless source_tracker.is_a?(Tracker) && !source_tracker.new_record? && | |
80 | source_role.is_a?(Role) && !source_role.new_record? && |
|
80 | source_role.is_a?(Role) && !source_role.new_record? && | |
81 | target_tracker.is_a?(Tracker) && !target_tracker.new_record? && |
|
81 | target_tracker.is_a?(Tracker) && !target_tracker.new_record? && | |
82 | target_role.is_a?(Role) && !target_role.new_record? |
|
82 | target_role.is_a?(Role) && !target_role.new_record? | |
83 |
|
83 | |||
84 | raise ArgumentError.new("arguments can not be nil or unsaved objects") |
|
84 | raise ArgumentError.new("arguments can not be nil or unsaved objects") | |
85 | end |
|
85 | end | |
86 |
|
86 | |||
87 | if source_tracker == target_tracker && source_role == target_role |
|
87 | if source_tracker == target_tracker && source_role == target_role | |
88 | false |
|
88 | false | |
89 | else |
|
89 | else |
General Comments 0
You need to be logged in to leave comments.
Login now