Defect #3657 ยป copy_issue_disabled_tracker.patch
| app/models/issue.rb | ||
|---|---|---|
|
def move_to(new_project, new_tracker = nil, options = {})
|
||
|
options ||= {}
|
||
|
issue = options[:copy] ? self.clone : self
|
||
|
transaction do
|
||
|
if new_project && issue.project_id != new_project.id
|
||
|
# delete issue relations
|
||
|
unless Setting.cross_project_issue_relations?
|
||
|
issue.relations_from.clear
|
||
|
issue.relations_to.clear
|
||
|
begin
|
||
|
transaction do
|
||
|
if new_project && issue.project_id != new_project.id
|
||
|
# delete issue relations
|
||
|
unless Setting.cross_project_issue_relations?
|
||
|
issue.relations_from.clear
|
||
|
issue.relations_to.clear
|
||
|
end
|
||
|
# issue is moved to another project
|
||
|
# reassign to the category with same name if any
|
||
|
new_category = issue.category.nil? ? nil : new_project.issue_categories.find_by_name(issue.category.name)
|
||
|
issue.category = new_category
|
||
|
issue.fixed_version = nil
|
||
|
issue.project = new_project
|
||
|
end
|
||
|
# issue is moved to another project
|
||
|
# reassign to the category with same name if any
|
||
|
new_category = issue.category.nil? ? nil : new_project.issue_categories.find_by_name(issue.category.name)
|
||
|
issue.category = new_category
|
||
|
issue.fixed_version = nil
|
||
|
issue.project = new_project
|
||
|
end
|
||
|
if new_tracker
|
||
|
issue.tracker = new_tracker
|
||
|
end
|
||
|
if options[:copy]
|
||
|
issue.custom_field_values = self.custom_field_values.inject({}) {|h,v| h[v.custom_field_id] = v.value; h}
|
||
|
issue.status = self.status
|
||
|
end
|
||
|
if issue.save
|
||
|
if new_tracker
|
||
|
issue.tracker = new_tracker
|
||
|
end
|
||
|
if options[:copy]
|
||
|
issue.custom_field_values = self.custom_field_values.inject({}) {|h,v| h[v.custom_field_id] = v.value; h}
|
||
|
issue.status = self.status
|
||
|
end
|
||
|
issue.save!
|
||
|
unless options[:copy]
|
||
|
# Manually update project_id on related time entries
|
||
|
TimeEntry.update_all("project_id = #{new_project.id}", {:issue_id => id})
|
||
|
end
|
||
|
else
|
||
|
Issue.connection.rollback_db_transaction
|
||
|
return false
|
||
|
end
|
||
|
rescue ActiveRecord::RecordInvalid
|
||
|
# #Issue.connection.rollback_db_transaction
|
||
|
return false
|
||
|
end
|
||
|
return issue
|
||
|
end
|
||
| ... | ... | |
|
if start_date && soonest_start && start_date < soonest_start
|
||
|
errors.add :start_date, :invalid
|
||
|
end
|
||
|
end
|
||
|
|
||
|
def validate_on_create
|
||
|
|
||
|
errors.add :tracker_id, :invalid unless project.trackers.include?(tracker)
|
||
|
end
|
||
|
|
||
| test/unit/issue_test.rb | ||
|---|---|---|
|
assert_equal orig.tracker, issue.tracker
|
||
|
assert_equal orig.custom_values.first.value, issue.custom_values.first.value
|
||
|
end
|
||
|
|
||
|
def test_should_close_duplicates
|
||
|
# Create 3 issues
|
||
|
issue1 = Issue.new(:project_id => 1, :tracker_id => 1, :author_id => 1, :status_id => 1, :priority => IssuePriority.all.first, :subject => 'Duplicates test', :description => 'Duplicates test')
|
||
| ... | ... | |
|
assert_nil copy.custom_value_for(2)
|
||
|
end
|
||
|
|
||
|
def test_copy_to_another_project_with_disabled_tracker
|
||
|
assert !Project.find(3).trackers.include?(Tracker.find(1))
|
||
|
issue = Issue.find(1)
|
||
|
assert_equal 1, issue.tracker_id
|
||
|
assert !issue.move_to(Project.find(3), nil, :copy => true)
|
||
|
end
|
||
|
def test_issue_destroy
|
||
|
Issue.find(1).destroy
|
||
|
assert_nil Issue.find_by_id(1)
|
||