Feature #1847 ยป move_as_copy.diff
| models/issue.rb (working copy) | ||
|---|---|---|
|
end
|
||
|
return true
|
||
|
end
|
||
|
|
||
|
# Move an issue to a new project and tracker
|
||
|
def move_to_return_issue(new_project, new_tracker = nil,is_copy = nill)
|
||
|
transaction do
|
||
|
if new_project && project_id != new_project.id
|
||
|
# delete issue relations
|
||
|
unless Setting.cross_project_issue_relations?
|
||
|
self.relations_from.clear
|
||
|
self.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
|
||
|
end
|
||
|
if new_tracker
|
||
|
self.tracker = new_tracker
|
||
|
end
|
||
|
if(is_copy)
|
||
|
new_issue=self.clone
|
||
|
new_issue.id=nil
|
||
|
if new_issue.save
|
||
|
# Manually update project_id on related time entries
|
||
|
TimeEntry.update_all("project_id = #{new_project.id}", {:issue_id => id})
|
||
|
return new_issue
|
||
|
else
|
||
|
rollback_db_transaction
|
||
|
end
|
||
|
else
|
||
|
if save
|
||
|
# Manually update project_id on related time entries
|
||
|
TimeEntry.update_all("project_id = #{new_project.id}", {:issue_id => id})
|
||
|
else
|
||
|
rollback_db_transaction
|
||
|
end
|
||
|
end
|
||
|
|
||
|
end
|
||
|
return self
|
||
|
end
|
||
|
def priority_id=(pid)
|
||
|
self.priority = nil
|
||
|
write_attribute(:priority_id, pid)
|
||
| controllers/issues_controller.rb (working copy) | ||
|---|---|---|
|
@trackers = @target_project.trackers
|
||
|
if request.post?
|
||
|
new_tracker = params[:new_tracker_id].blank? ? nil : @target_project.trackers.find_by_id(params[:new_tracker_id])
|
||
|
unsaved_issue_ids = []
|
||
|
@issues.each do |issue|
|
||
|
issue.init_journal(User.current)
|
||
|
unsaved_issue_ids << issue.id unless issue.move_to(@target_project, new_tracker)
|
||
|
end
|
||
|
if unsaved_issue_ids.empty?
|
||
|
flash[:notice] = l(:notice_successful_update) unless @issues.empty?
|
||
|
is_copy=params["is_copy"]
|
||
|
if(@issues.size>1)
|
||
|
unsaved_issue_ids = []
|
||
|
@issues.each do |issue|
|
||
|
issue.init_journal(User.current)
|
||
|
unsaved_issue_ids << issue.id unless issue.move_to(@target_project, new_tracker,is_copy)
|
||
|
end
|
||
|
if unsaved_issue_ids.empty?
|
||
|
flash[:notice] = l(:notice_successful_update) unless @issues.empty?
|
||
|
else
|
||
|
flash[:error] = l(:notice_failed_to_save_issues, unsaved_issue_ids.size, @issues.size, '#' + unsaved_issue_ids.join(', #'))
|
||
|
end
|
||
|
redirect_to :controller => 'issues', :action => 'index', :project_id => @target_project
|
||
|
else
|
||
|
flash[:error] = l(:notice_failed_to_save_issues, unsaved_issue_ids.size, @issues.size, '#' + unsaved_issue_ids.join(', #'))
|
||
|
issue=@issues[0].move_to_return_issue(@target_project, new_tracker,is_copy)
|
||
|
redirect_to :controller => 'issues', :action => 'show', :id => issue
|
||
|
end
|
||
|
redirect_to :controller => 'issues', :action => 'index', :project_id => @project
|
||
|
return
|
||
|
end
|
||
|
render :layout => false if request.xhr?
|
||
| views/issues/move.rhtml (working copy) | ||
|---|---|---|
|
<p><label for="new_tracker_id"><%=l(:field_tracker)%> :</label>
|
||
|
<%= select_tag "new_tracker_id", "<option value=\"\">#{l(:label_no_change_option)}</option>" + options_from_collection_for_select(@trackers, "id", "name") %></p>
|
||
|
<p><label for="is_copy">Move a Copy? </label>
|
||
|
<%=check_box_tag("is_copy", '1', 0, :id => "is_copy") + hidden_field_tag("is_copy", '0')%>
|
||
|
</p>
|
||
|
</div>
|
||
|
<%= submit_tag l(:button_move) %>
|
||