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