@@ -75,6 +75,7 class Issue < ActiveRecord::Base | |||||
75 |
|
75 | |||
76 | before_create :default_assign |
|
76 | before_create :default_assign | |
77 | before_save :close_duplicates, :update_done_ratio_from_issue_status |
|
77 | before_save :close_duplicates, :update_done_ratio_from_issue_status | |
|
78 | after_save {|issue| issue.send :after_project_change if !issue.id_changed? && issue.project_id_changed?} | |||
78 | after_save :reschedule_following_issues, :update_nested_set_attributes, :update_parent_attributes, :create_journal |
|
79 | after_save :reschedule_following_issues, :update_nested_set_attributes, :update_parent_attributes, :create_journal | |
79 | after_destroy :update_parent_attributes |
|
80 | after_destroy :update_parent_attributes | |
80 |
|
81 | |||
@@ -153,23 +154,7 class Issue < ActiveRecord::Base | |||||
153 | end |
|
154 | end | |
154 |
|
155 | |||
155 | if new_project && issue.project_id != new_project.id |
|
156 | if new_project && issue.project_id != new_project.id | |
156 | # delete issue relations |
|
|||
157 | unless Setting.cross_project_issue_relations? |
|
|||
158 | issue.relations_from.clear |
|
|||
159 | issue.relations_to.clear |
|
|||
160 | end |
|
|||
161 | # issue is moved to another project |
|
|||
162 | # reassign to the category with same name if any |
|
|||
163 | new_category = issue.category.nil? ? nil : new_project.issue_categories.find_by_name(issue.category.name) |
|
|||
164 | issue.category = new_category |
|
|||
165 | # Keep the fixed_version if it's still valid in the new_project |
|
|||
166 | unless new_project.shared_versions.include?(issue.fixed_version) |
|
|||
167 | issue.fixed_version = nil |
|
|||
168 | end |
|
|||
169 | issue.project = new_project |
|
157 | issue.project = new_project | |
170 | if issue.parent && issue.parent.project_id != issue.project_id |
|
|||
171 | issue.parent_issue_id = nil |
|
|||
172 | end |
|
|||
173 | end |
|
158 | end | |
174 | if new_tracker |
|
159 | if new_tracker | |
175 | issue.tracker = new_tracker |
|
160 | issue.tracker = new_tracker | |
@@ -192,19 +177,7 class Issue < ActiveRecord::Base | |||||
192 | issue.init_journal(User.current, options[:notes]) |
|
177 | issue.init_journal(User.current, options[:notes]) | |
193 | issue.current_journal.notify = false |
|
178 | issue.current_journal.notify = false | |
194 | end |
|
179 | end | |
195 |
|
|
180 | unless issue.save | |
196 | unless options[:copy] |
|
|||
197 | # Manually update project_id on related time entries |
|
|||
198 | TimeEntry.update_all("project_id = #{new_project.id}", {:issue_id => id}) |
|
|||
199 |
|
||||
200 | issue.children.each do |child| |
|
|||
201 | unless child.move_to_project_without_transaction(new_project) |
|
|||
202 | # Move failed and transaction was rollback'd |
|
|||
203 | return false |
|
|||
204 | end |
|
|||
205 | end |
|
|||
206 | end |
|
|||
207 | else |
|
|||
208 | return false |
|
181 | return false | |
209 | end |
|
182 | end | |
210 | issue |
|
183 | issue | |
@@ -227,6 +200,32 class Issue < ActiveRecord::Base | |||||
227 | result |
|
200 | result | |
228 | end |
|
201 | end | |
229 |
|
202 | |||
|
203 | def project_id=(project_id) | |||
|
204 | if project_id.to_s != self.project_id.to_s | |||
|
205 | self.project = (project_id.present? ? Project.find_by_id(project_id) : nil) | |||
|
206 | end | |||
|
207 | end | |||
|
208 | ||||
|
209 | def project=(project) | |||
|
210 | project_was = self.project | |||
|
211 | write_attribute(:project_id, project ? project.id : nil) | |||
|
212 | association_instance_set('project', project) | |||
|
213 | if project_was && project && project_was != project | |||
|
214 | # Reassign to the category with same name if any | |||
|
215 | if category | |||
|
216 | self.category = project.issue_categories.find_by_name(category.name) | |||
|
217 | end | |||
|
218 | # Keep the fixed_version if it's still valid in the new_project | |||
|
219 | if fixed_version && fixed_version.project != project && !project.shared_versions.include?(fixed_version) | |||
|
220 | self.fixed_version = nil | |||
|
221 | end | |||
|
222 | if parent && parent.project_id != project_id | |||
|
223 | self.parent_issue_id = nil | |||
|
224 | end | |||
|
225 | @custom_field_values = nil | |||
|
226 | end | |||
|
227 | end | |||
|
228 | ||||
230 | def description=(arg) |
|
229 | def description=(arg) | |
231 | if arg.is_a?(String) |
|
230 | if arg.is_a?(String) | |
232 | arg = arg.gsub(/(\r\n|\n|\r)/, "\r\n") |
|
231 | arg = arg.gsub(/(\r\n|\n|\r)/, "\r\n") | |
@@ -763,6 +762,25 class Issue < ActiveRecord::Base | |||||
763 |
|
762 | |||
764 | private |
|
763 | private | |
765 |
|
764 | |||
|
765 | def after_project_change | |||
|
766 | # Update project_id on related time entries | |||
|
767 | TimeEntry.update_all(["project_id = ?", project_id], {:issue_id => id}) | |||
|
768 | ||||
|
769 | # Delete issue relations | |||
|
770 | unless Setting.cross_project_issue_relations? | |||
|
771 | relations_from.clear | |||
|
772 | relations_to.clear | |||
|
773 | end | |||
|
774 | ||||
|
775 | # Move subtasks | |||
|
776 | children.each do |child| | |||
|
777 | child.project = project | |||
|
778 | unless child.save | |||
|
779 | raise ActiveRecord::Rollback | |||
|
780 | end | |||
|
781 | end | |||
|
782 | end | |||
|
783 | ||||
766 | def update_nested_set_attributes |
|
784 | def update_nested_set_attributes | |
767 | if root_id.nil? |
|
785 | if root_id.nil? | |
768 | # issue was just created |
|
786 | # issue was just created |
@@ -406,6 +406,27 class IssueTest < ActiveSupport::TestCase | |||||
406 | assert_equal orig.status, issue.status |
|
406 | assert_equal orig.status, issue.status | |
407 | end |
|
407 | end | |
408 |
|
408 | |||
|
409 | def test_should_not_call_after_project_change_on_creation | |||
|
410 | issue = Issue.new(:project_id => 1, :tracker_id => 1, :status_id => 1, :subject => 'Test', :author_id => 1) | |||
|
411 | issue.expects(:after_project_change).never | |||
|
412 | issue.save! | |||
|
413 | end | |||
|
414 | ||||
|
415 | def test_should_not_call_after_project_change_on_update | |||
|
416 | issue = Issue.find(1) | |||
|
417 | issue.project = Project.find(1) | |||
|
418 | issue.subject = 'No project change' | |||
|
419 | issue.expects(:after_project_change).never | |||
|
420 | issue.save! | |||
|
421 | end | |||
|
422 | ||||
|
423 | def test_should_call_after_project_change_on_project_change | |||
|
424 | issue = Issue.find(1) | |||
|
425 | issue.project = Project.find(2) | |||
|
426 | issue.expects(:after_project_change).once | |||
|
427 | issue.save! | |||
|
428 | end | |||
|
429 | ||||
409 | def test_should_close_duplicates |
|
430 | def test_should_close_duplicates | |
410 | # Create 3 issues |
|
431 | # Create 3 issues | |
411 | project = Project.find(1) |
|
432 | project = Project.find(1) |
General Comments 0
You need to be logged in to leave comments.
Login now