Defect #8239

notes field is not propagated during issue copy

Added by Janusz Harkot over 6 years ago. Updated over 6 years ago.

Status:ClosedStart date:2011-04-27
Priority:NormalDue date:
Assignee:-% Done:

0%

Category:Issues
Target version:1.2.0
Resolution:Fixed Affected version:1.1.2

Description

scenario (vanilla installation of redmine):

- open existing issue
- click copy
- add notes
- click copy button

notes are not visible, they are lost

issue_copy.patch Magnifier (2.78 KB) Etienne Massip, 2011-05-23 19:06


Related issues

Related to Redmine - Defect #6901: Copy/Move an issue does not give any history of who actua... Closed 2010-11-15

Associated revisions

Revision 5602
Added by Jean-Philippe Lang over 6 years ago

Fixed: notes are lost when copying issue(s) (#6901, #8239).

History

#1 Updated by Etienne Massip over 6 years ago

  • Target version set to Candidate for next minor release

Confirmed with demo site, I'll try to investigate further.

#2 Updated by Etienne Massip over 6 years ago

Had a quick look yesterday evening, Issue#new.copy_from does not copy current journal.

Maybe that call to Issue#init_journal in IssueMovesController should be moved to model after call to #copy_from and only for a move action (do we really need a journal entry in a copy context if no notes are filled in) ?

#3 Updated by Etienne Massip over 6 years ago

This change prevents double #save :

Index: app/models/issue.rb
===================================================================
--- app/models/issue.rb    (revision 5543)
+++ app/models/issue.rb    (working copy)
@@ -147,10 +147,18 @@
     end || false
   end

-  def move_to_project_without_transaction(new_project, new_tracker = nil, options = {})
+  def move_to_project_without_transaction(new_project, notes = nil, new_tracker = nil, options = {})
     options ||= {}
-    issue = options[:copy] ? self.class.new.copy_from(self) : self
-    
+
+    if options[:copy]
+      issue = self.class.new.copy_from(self)
+      issue.instance_variable_set :@current_journal, Journal.new(:journalized => issue, :user => User.current, :notes => notes) if notes.present?
+    else
+      issue = self
+      issue.init_journal(User.current)
+      issue.current_journal.notes = notes if notes.present?
+    end
+
     if new_project && issue.project_id != new_project.id
       # delete issue relations
       unless Setting.cross_project_issue_relations?
@@ -867,7 +875,8 @@
                                                       :prop_key => c,
                                                       :old_value => @issue_before_change.send(c),
                                                       :value => send(c)) unless send(c)==@issue_before_change.send(c)
-      }
+      } if @issue_before_change
+
       # custom fields changes
       custom_values.each {|c|
         next if (@custom_values_before_change[c.custom_field_id]==c.value ||
@@ -876,7 +885,8 @@
                                                       :prop_key => c.custom_field_id,
                                                       :old_value => @custom_values_before_change[c.custom_field_id],
                                                       :value => c.value)
-      }      
+      } if @custom_values_before_change
+
       @current_journal.save
       # reset current journal
       init_journal @current_journal.user, @current_journal.notes
Index: app/controllers/issue_moves_controller.rb
===================================================================
--- app/controllers/issue_moves_controller.rb    (revision 5543)
+++ app/controllers/issue_moves_controller.rb    (working copy)
@@ -17,10 +17,8 @@
       moved_issues = []
       @issues.each do |issue|
         issue.reload
-        issue.init_journal(User.current)
-        issue.current_journal.notes = @notes if @notes.present?
         call_hook(:controller_issues_move_before_save, { :params => params, :issue => issue, :target_project => @target_project, :copy => !!@copy })
-        if r = issue.move_to_project(@target_project, new_tracker, {:copy => @copy, :attributes => extract_changed_attributes_for_move(params)})
+        if r = issue.move_to_project(@target_project, @notes, new_tracker, {:copy => @copy, :attributes => extract_changed_attributes_for_move(params)})
           moved_issues << r
         else
           unsaved_issue_ids << issue.id

#4 Updated by johann sebatian over 6 years ago

  • Assignee set to johann sebatian

#5 Updated by Etienne Massip over 6 years ago

  • Assignee deleted (johann sebatian)
  • Target version changed from Candidate for next minor release to 1.2.0

#6 Updated by Etienne Massip over 6 years ago

Less intrusive based on trunk ?

#7 Updated by Jean-Philippe Lang over 6 years ago

  • Status changed from New to Closed
  • Resolution set to Fixed

This was fixed in r5602. Anything wrong with it?

Also available in: Atom PDF