diff options
author | Grzegorz Bizon <grzesiek.bizon@gmail.com> | 2016-03-14 10:25:37 +0300 |
---|---|---|
committer | Grzegorz Bizon <grzesiek.bizon@gmail.com> | 2016-03-17 09:39:16 +0300 |
commit | 310b417b0f2336e5e7a9b44da2fabf5d4abb0cb4 (patch) | |
tree | 5978f51dbf31c2337721950ed5e3a22e7a0146e7 /app/services/issues | |
parent | 4354bfaba55c9238d5245fe2f5823665790c9817 (diff) |
Preserve original author when moving issue
This also wrapps entire process into transation, as rewriting references
may have large memory footprint.
Diffstat (limited to 'app/services/issues')
-rw-r--r-- | app/services/issues/move_service.rb | 40 |
1 files changed, 19 insertions, 21 deletions
diff --git a/app/services/issues/move_service.rb b/app/services/issues/move_service.rb index de12ea5c172..d1bded5c99f 100644 --- a/app/services/issues/move_service.rb +++ b/app/services/issues/move_service.rb @@ -4,7 +4,7 @@ module Issues super(project, current_user, params) @issue_old = issue - @issue_new = nil + @issue_new = issue.dup @project_old = @project @project_new = Project.find(new_project_id) if new_project_id end @@ -12,16 +12,18 @@ module Issues def execute return unless move? - # New issue tasks - # - open_new_issue - rewrite_notes - add_moved_from_note - - # Old issue tasks - # - add_moved_to_note - close_old_issue + ActiveRecord::Base.transaction do + # New issue tasks + # + open_new_issue + rewrite_notes + add_moved_from_note + + # Old issue tasks + # + add_moved_to_note + close_old_issue + end # Notifications # @@ -42,16 +44,12 @@ module Issues end def open_new_issue - create_service = CreateService.new(@project_new, current_user, new_issue_params) - @issue_new = create_service.execute - end - - def new_issue_params - new_params = { id: nil, iid: nil, milestone_id: nil, label_ids: [], - project_id: @project_new.id, - description: rewrite_references(@issue_old) } - - params.merge(new_params) + @issue_new.iid = nil + @issue_new.project = @project_new + @issue_new.labels = [] + @issue_new.milestone = nil + @issue_new.description = rewrite_references(@issue_old) + @issue_new.save! end def rewrite_notes |