88 |
88 |
def move_to(new_project, new_tracker = nil, options = {})
|
89 |
89 |
options ||= {}
|
90 |
90 |
issue = options[:copy] ? self.clone : self
|
91 |
|
transaction do
|
92 |
|
if new_project && issue.project_id != new_project.id
|
93 |
|
# delete issue relations
|
94 |
|
unless Setting.cross_project_issue_relations?
|
95 |
|
issue.relations_from.clear
|
96 |
|
issue.relations_to.clear
|
|
91 |
begin
|
|
92 |
transaction do
|
|
93 |
if new_project && issue.project_id != new_project.id
|
|
94 |
# delete issue relations
|
|
95 |
unless Setting.cross_project_issue_relations?
|
|
96 |
issue.relations_from.clear
|
|
97 |
issue.relations_to.clear
|
|
98 |
end
|
|
99 |
# issue is moved to another project
|
|
100 |
# reassign to the category with same name if any
|
|
101 |
new_category = issue.category.nil? ? nil : new_project.issue_categories.find_by_name(issue.category.name)
|
|
102 |
issue.category = new_category
|
|
103 |
issue.fixed_version = nil
|
|
104 |
issue.project = new_project
|
97 |
105 |
end
|
98 |
|
# issue is moved to another project
|
99 |
|
# reassign to the category with same name if any
|
100 |
|
new_category = issue.category.nil? ? nil : new_project.issue_categories.find_by_name(issue.category.name)
|
101 |
|
issue.category = new_category
|
102 |
|
issue.fixed_version = nil
|
103 |
|
issue.project = new_project
|
104 |
|
end
|
105 |
|
if new_tracker
|
106 |
|
issue.tracker = new_tracker
|
107 |
|
end
|
108 |
|
if options[:copy]
|
109 |
|
issue.custom_field_values = self.custom_field_values.inject({}) {|h,v| h[v.custom_field_id] = v.value; h}
|
110 |
|
issue.status = self.status
|
111 |
|
end
|
112 |
|
if issue.save
|
|
106 |
if new_tracker
|
|
107 |
issue.tracker = new_tracker
|
|
108 |
end
|
|
109 |
if options[:copy]
|
|
110 |
issue.custom_field_values = self.custom_field_values.inject({}) {|h,v| h[v.custom_field_id] = v.value; h}
|
|
111 |
issue.status = self.status
|
|
112 |
end
|
|
113 |
issue.save!
|
113 |
114 |
unless options[:copy]
|
114 |
115 |
# Manually update project_id on related time entries
|
115 |
116 |
TimeEntry.update_all("project_id = #{new_project.id}", {:issue_id => id})
|
116 |
117 |
end
|
117 |
|
else
|
118 |
|
Issue.connection.rollback_db_transaction
|
119 |
|
return false
|
120 |
118 |
end
|
|
119 |
rescue ActiveRecord::RecordInvalid
|
|
120 |
# #Issue.connection.rollback_db_transaction
|
|
121 |
return false
|
121 |
122 |
end
|
122 |
123 |
return issue
|
123 |
124 |
end
|
... | ... | |
143 |
144 |
if start_date && soonest_start && start_date < soonest_start
|
144 |
145 |
errors.add :start_date, :invalid
|
145 |
146 |
end
|
146 |
|
end
|
147 |
|
|
148 |
|
def validate_on_create
|
|
147 |
|
149 |
148 |
errors.add :tracker_id, :invalid unless project.trackers.include?(tracker)
|
150 |
149 |
end
|
151 |
150 |
|