Project

General

Profile

Defect #15044 ยป git.patch

Jordan Hollinger, 2013-10-04 23:12

View differences:

app/controllers/issues_controller.rb
176 176
    @issue.save_attachments(params[:attachments] || (params[:issue] && params[:issue][:uploads]))
177 177
    saved = false
178 178
    begin
179
      saved = @issue.save_issue_with_child_records(params, @time_entry)
179
      saved = save_issue_with_child_records
180 180
    rescue ActiveRecord::StaleObjectError
181 181
      @conflict = true
182 182
      if params[:last_journal_id]
......
436 436
    end
437 437
    attributes
438 438
  end
439

  
440
  # Saves @issue and a time_entry from the parameters
441
  def save_issue_with_child_records
442
    Issue.transaction do
443
      if params[:time_entry] && (params[:time_entry][:hours].present? || params[:time_entry][:comments].present?) && User.current.allowed_to?(:log_time, project)
444
        time_entry = @time_entry || TimeEntry.new
445
        time_entry.project = project
446
        time_entry.issue = @issue
447
        time_entry.user = User.current
448
        time_entry.spent_on = User.current.today
449
        time_entry.attributes = params[:time_entry]
450
        @issue.time_entries << time_entry
451
      end
452

  
453
      # TODO: Rename hook
454
      call_hook(:controller_issues_edit_before_save, { :params => params, :issue => @issue, :time_entry => time_entry, :journal => @issue.current_journal})
455
      if @issue.save
456
        # TODO: Rename hook
457
        call_hook(:controller_issues_edit_after_save, { :params => params, :issue => @issue, :time_entry => time_entry, :journal => @issue.current_journal})
458
      else
459
        raise ActiveRecord::Rollback
460
      end
461
    end
462
  end
439 463
end
app/models/issue.rb
1057 1057
    s
1058 1058
  end
1059 1059

  
1060
  # Saves an issue and a time_entry from the parameters
1061
  def save_issue_with_child_records(params, existing_time_entry=nil)
1062
    Issue.transaction do
1063
      if params[:time_entry] && (params[:time_entry][:hours].present? || params[:time_entry][:comments].present?) && User.current.allowed_to?(:log_time, project)
1064
        @time_entry = existing_time_entry || TimeEntry.new
1065
        @time_entry.project = project
1066
        @time_entry.issue = self
1067
        @time_entry.user = User.current
1068
        @time_entry.spent_on = User.current.today
1069
        @time_entry.attributes = params[:time_entry]
1070
        self.time_entries << @time_entry
1071
      end
1072

  
1073
      # TODO: Rename hook
1074
      Redmine::Hook.call_hook(:controller_issues_edit_before_save, { :params => params, :issue => self, :time_entry => @time_entry, :journal => @current_journal})
1075
      if save
1076
        # TODO: Rename hook
1077
        Redmine::Hook.call_hook(:controller_issues_edit_after_save, { :params => params, :issue => self, :time_entry => @time_entry, :journal => @current_journal})
1078
      else
1079
        raise ActiveRecord::Rollback
1080
      end
1081
    end
1082
  end
1083

  
1084 1060
  # Unassigns issues from +version+ if it's no longer shared with issue's project
1085 1061
  def self.update_versions_from_sharing_change(version)
1086 1062
    # Update issues assigned to the version
    (1-1/1)