Feature #1847 ยป move_as_copy.diff
models/issue.rb (working copy) | ||
---|---|---|
100 | 100 |
end |
101 | 101 |
return true |
102 | 102 |
end |
103 |
|
|
103 |
# Move an issue to a new project and tracker |
|
104 |
def move_to_return_issue(new_project, new_tracker = nil,is_copy = nill) |
|
105 |
transaction do |
|
106 |
if new_project && project_id != new_project.id |
|
107 |
# delete issue relations |
|
108 |
unless Setting.cross_project_issue_relations? |
|
109 |
self.relations_from.clear |
|
110 |
self.relations_to.clear |
|
111 |
end |
|
112 |
# issue is moved to another project |
|
113 |
# reassign to the category with same name if any |
|
114 |
new_category = category.nil? ? nil : new_project.issue_categories.find_by_name(category.name) |
|
115 |
self.category = new_category |
|
116 |
self.fixed_version = nil |
|
117 |
self.project = new_project |
|
118 |
end |
|
119 |
if new_tracker |
|
120 |
self.tracker = new_tracker |
|
121 |
end |
|
122 |
if(is_copy) |
|
123 |
new_issue=self.clone |
|
124 |
new_issue.id=nil |
|
125 |
if new_issue.save |
|
126 |
# Manually update project_id on related time entries |
|
127 |
TimeEntry.update_all("project_id = #{new_project.id}", {:issue_id => id}) |
|
128 |
return new_issue |
|
129 |
else |
|
130 |
rollback_db_transaction |
|
131 |
end |
|
132 |
else |
|
133 |
if save |
|
134 |
# Manually update project_id on related time entries |
|
135 |
TimeEntry.update_all("project_id = #{new_project.id}", {:issue_id => id}) |
|
136 |
else |
|
137 |
rollback_db_transaction |
|
138 |
end |
|
139 |
end |
|
140 |
|
|
141 |
end |
|
142 |
return self |
|
143 |
end |
|
104 | 144 |
def priority_id=(pid) |
105 | 145 |
self.priority = nil |
106 | 146 |
write_attribute(:priority_id, pid) |
controllers/issues_controller.rb (working copy) | ||
---|---|---|
280 | 280 |
@trackers = @target_project.trackers |
281 | 281 |
if request.post? |
282 | 282 |
new_tracker = params[:new_tracker_id].blank? ? nil : @target_project.trackers.find_by_id(params[:new_tracker_id]) |
283 |
unsaved_issue_ids = [] |
|
284 |
@issues.each do |issue| |
|
285 |
issue.init_journal(User.current) |
|
286 |
unsaved_issue_ids << issue.id unless issue.move_to(@target_project, new_tracker) |
|
287 |
end |
|
288 |
if unsaved_issue_ids.empty? |
|
289 |
flash[:notice] = l(:notice_successful_update) unless @issues.empty? |
|
283 |
is_copy=params["is_copy"] |
|
284 |
if(@issues.size>1) |
|
285 |
unsaved_issue_ids = [] |
|
286 |
@issues.each do |issue| |
|
287 |
issue.init_journal(User.current) |
|
288 |
unsaved_issue_ids << issue.id unless issue.move_to(@target_project, new_tracker,is_copy) |
|
289 |
end |
|
290 |
if unsaved_issue_ids.empty? |
|
291 |
flash[:notice] = l(:notice_successful_update) unless @issues.empty? |
|
292 |
else |
|
293 |
flash[:error] = l(:notice_failed_to_save_issues, unsaved_issue_ids.size, @issues.size, '#' + unsaved_issue_ids.join(', #')) |
|
294 |
end |
|
295 |
redirect_to :controller => 'issues', :action => 'index', :project_id => @target_project |
|
290 | 296 |
else |
291 |
flash[:error] = l(:notice_failed_to_save_issues, unsaved_issue_ids.size, @issues.size, '#' + unsaved_issue_ids.join(', #')) |
|
297 |
issue=@issues[0].move_to_return_issue(@target_project, new_tracker,is_copy) |
|
298 |
redirect_to :controller => 'issues', :action => 'show', :id => issue |
|
292 | 299 |
end |
293 |
redirect_to :controller => 'issues', :action => 'index', :project_id => @project |
|
294 | 300 |
return |
295 | 301 |
end |
296 | 302 |
render :layout => false if request.xhr? |
views/issues/move.rhtml (working copy) | ||
---|---|---|
16 | 16 | |
17 | 17 |
<p><label for="new_tracker_id"><%=l(:field_tracker)%> :</label> |
18 | 18 |
<%= select_tag "new_tracker_id", "<option value=\"\">#{l(:label_no_change_option)}</option>" + options_from_collection_for_select(@trackers, "id", "name") %></p> |
19 |
<p><label for="is_copy">Move a Copy? </label> |
|
20 |
<%=check_box_tag("is_copy", '1', 0, :id => "is_copy") + hidden_field_tag("is_copy", '0')%> |
|
21 |
</p> |
|
19 | 22 |
</div> |
20 | 23 | |
21 | 24 |
<%= submit_tag l(:button_move) %> |