@ -71,34 +71,43 @@ class Issue < ActiveRecord::Base
self
end
# Move an issue to a new project and tracker
def move_to ( new_project , new_tracker = nil )
# Moves/copies an issue to a new project and tracker
# Returns the moved/copied issue on success, false on failure
def move_to ( new_project , new_tracker = nil , options = { } )
options || = { }
issue = options [ :copy ] ? self . clone : self
transaction do
if new_project && project_id != new_project . id
if new_project && issue . project_id != new_project . id
# delete issue relations
unless Setting . cross_project_issue_relations?
self . relations_from . clear
self . relations_to . clear
is su e. relations_from . clear
is su e. relations_to . clear
end
# issue is moved to another project
# reassign to the category with same name if any
new_category = category . nil? ? nil : new_project . issue_categories . find_by_name ( category . name )
self . category = new_category
self . fixed_version = nil
self . project = new_project
new_category = issue . category . nil? ? nil : new_project . issue_categories . find_by_name ( issue . category . name )
is su e. category = new_category
is su e. fixed_version = nil
is su e. project = new_project
end
if new_tracker
self . tracker = new_tracker
is su e. tracker = new_tracker
end
if save
# Manually update project_id on related time entries
TimeEntry . update_all ( " project_id = #{ new_project . id } " , { :issue_id = > id } )
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
unless options [ :copy ]
# Manually update project_id on related time entries
TimeEntry . update_all ( " project_id = #{ new_project . id } " , { :issue_id = > id } )
end
else
rollback_db_transaction
Issue . connection . rollback_db_transaction
return false
end
end
return true
return iss ue
end
def priority_id = ( pid )