issue_copy.patch

Etienne Massip, 2011-05-23 19:06

Download (2.78 KB)

View differences:

app/controllers/issue_moves_controller.rb (working copy)
17 17
      moved_issues = []
18 18
      @issues.each do |issue|
19 19
        issue.reload
20
        issue.init_journal(User.current)
21
        issue.current_journal.notes = @notes if @notes.present?
22 20
        call_hook(:controller_issues_move_before_save, { :params => params, :issue => issue, :target_project => @target_project, :copy => !!@copy })
23
        if r = issue.move_to_project(@target_project, new_tracker, {:copy => @copy, :attributes => extract_changed_attributes_for_move(params)})
21
        if r = issue.move_to_project(@target_project, @notes, new_tracker, {:copy => @copy, :attributes => extract_changed_attributes_for_move(params)})
24 22
          moved_issues << r
25 23
        else
26 24
          unsaved_issue_ids << issue.id
app/models/issue.rb (working copy)
146 146
      move_to_project_without_transaction(*args) || raise(ActiveRecord::Rollback)
147 147
    end || false
148 148
  end
149

  
150
  def move_to_project_without_transaction(new_project, new_tracker = nil, options = {})
149
  
150
  def move_to_project_without_transaction(new_project, notes = '', new_tracker = nil, options = {})
151 151
    options ||= {}
152
    issue = options[:copy] ? self.class.new.copy_from(self) : self
152

  
153
    if options[:copy]
154
       issue = self.class.new.copy_from(self)
155
       issue.init_journal(User.current, notes, false) if notes.present?
156
     else
157
       issue = self
158
       issue.init_journal(User.current, notes)
159
     end
153 160

  
154 161
    if new_project && issue.project_id != new_project.id
155 162
      # delete issue relations
......
188 195
      issue.attributes = options[:attributes]
189 196
    end
190 197
    if issue.save
191
      if options[:copy]
192
        if current_journal && current_journal.notes.present?
193
          issue.init_journal(current_journal.user, current_journal.notes)
194
          issue.current_journal.notify = false
195
          issue.save
196
        end
197
      else
198
      unless options[:copy]
198 199
        # Manually update project_id on related time entries
199 200
        TimeEntry.update_all("project_id = #{new_project.id}", {:issue_id => id})
200 201

  
......
381 382
    end
382 383
  end
383 384

  
384
  def init_journal(user, notes = "")
385
  def init_journal(user, notes = '', notify_on_save = true)
385 386
    @current_journal ||= Journal.new(:journalized => self, :user => user, :notes => notes)
387
    @current_journal.notify = notify_on_save
386 388
    @issue_before_change = self.clone
387 389
    @issue_before_change.status = self.status
388 390
    @custom_values_before_change = {}