##// END OF EJS Templates
SQLServer: rule is a reserved keyword (#12713)....
Jean-Philippe Lang -
r10869:dd7d54b3a1d7
parent child
Show More
@@ -1,73 +1,73
1 # Redmine - project management software
1 # Redmine - project management software
2 # Copyright (C) 2006-2012 Jean-Philippe Lang
2 # Copyright (C) 2006-2012 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.
17
17
18 class WorkflowRule < ActiveRecord::Base
18 class WorkflowRule < ActiveRecord::Base
19 self.table_name = "#{table_name_prefix}workflows#{table_name_suffix}"
19 self.table_name = "#{table_name_prefix}workflows#{table_name_suffix}"
20
20
21 belongs_to :role
21 belongs_to :role
22 belongs_to :tracker
22 belongs_to :tracker
23 belongs_to :old_status, :class_name => 'IssueStatus', :foreign_key => 'old_status_id'
23 belongs_to :old_status, :class_name => 'IssueStatus', :foreign_key => 'old_status_id'
24 belongs_to :new_status, :class_name => 'IssueStatus', :foreign_key => 'new_status_id'
24 belongs_to :new_status, :class_name => 'IssueStatus', :foreign_key => 'new_status_id'
25
25
26 validates_presence_of :role, :tracker, :old_status
26 validates_presence_of :role, :tracker, :old_status
27
27
28 # Copies workflows from source to targets
28 # Copies workflows from source to targets
29 def self.copy(source_tracker, source_role, target_trackers, target_roles)
29 def self.copy(source_tracker, source_role, target_trackers, target_roles)
30 unless source_tracker.is_a?(Tracker) || source_role.is_a?(Role)
30 unless source_tracker.is_a?(Tracker) || source_role.is_a?(Role)
31 raise ArgumentError.new("source_tracker or source_role must be specified")
31 raise ArgumentError.new("source_tracker or source_role must be specified")
32 end
32 end
33
33
34 target_trackers = [target_trackers].flatten.compact
34 target_trackers = [target_trackers].flatten.compact
35 target_roles = [target_roles].flatten.compact
35 target_roles = [target_roles].flatten.compact
36
36
37 target_trackers = Tracker.sorted.all if target_trackers.empty?
37 target_trackers = Tracker.sorted.all if target_trackers.empty?
38 target_roles = Role.all if target_roles.empty?
38 target_roles = Role.all if target_roles.empty?
39
39
40 target_trackers.each do |target_tracker|
40 target_trackers.each do |target_tracker|
41 target_roles.each do |target_role|
41 target_roles.each do |target_role|
42 copy_one(source_tracker || target_tracker,
42 copy_one(source_tracker || target_tracker,
43 source_role || target_role,
43 source_role || target_role,
44 target_tracker,
44 target_tracker,
45 target_role)
45 target_role)
46 end
46 end
47 end
47 end
48 end
48 end
49
49
50 # Copies a single set of workflows from source to target
50 # Copies a single set of workflows from source to target
51 def self.copy_one(source_tracker, source_role, target_tracker, target_role)
51 def self.copy_one(source_tracker, source_role, target_tracker, target_role)
52 unless source_tracker.is_a?(Tracker) && !source_tracker.new_record? &&
52 unless source_tracker.is_a?(Tracker) && !source_tracker.new_record? &&
53 source_role.is_a?(Role) && !source_role.new_record? &&
53 source_role.is_a?(Role) && !source_role.new_record? &&
54 target_tracker.is_a?(Tracker) && !target_tracker.new_record? &&
54 target_tracker.is_a?(Tracker) && !target_tracker.new_record? &&
55 target_role.is_a?(Role) && !target_role.new_record?
55 target_role.is_a?(Role) && !target_role.new_record?
56
56
57 raise ArgumentError.new("arguments can not be nil or unsaved objects")
57 raise ArgumentError.new("arguments can not be nil or unsaved objects")
58 end
58 end
59
59
60 if source_tracker == target_tracker && source_role == target_role
60 if source_tracker == target_tracker && source_role == target_role
61 false
61 false
62 else
62 else
63 transaction do
63 transaction do
64 delete_all :tracker_id => target_tracker.id, :role_id => target_role.id
64 delete_all :tracker_id => target_tracker.id, :role_id => target_role.id
65 connection.insert "INSERT INTO #{WorkflowRule.table_name} (tracker_id, role_id, old_status_id, new_status_id, author, assignee, field_name, rule, type)" +
65 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)" +
66 " SELECT #{target_tracker.id}, #{target_role.id}, old_status_id, new_status_id, author, assignee, field_name, rule, type" +
66 " SELECT #{target_tracker.id}, #{target_role.id}, old_status_id, new_status_id, author, assignee, field_name, #{connection.quote_column_name 'rule'}, type" +
67 " FROM #{WorkflowRule.table_name}" +
67 " FROM #{WorkflowRule.table_name}" +
68 " WHERE tracker_id = #{source_tracker.id} AND role_id = #{source_role.id}"
68 " WHERE tracker_id = #{source_tracker.id} AND role_id = #{source_role.id}"
69 end
69 end
70 true
70 true
71 end
71 end
72 end
72 end
73 end
73 end
General Comments 0
You need to be logged in to leave comments. Login now