Project

General

Profile

Defect #24693 » issue-destroy-also-reassign-descendants-spent-hours.patch

Anonymous, 2016-12-26 17:02

View differences:

app/controllers/issues_controller.rb
343 343

  
344 344
  def destroy
345 345
    raise Unauthorized unless @issues.all?(&:deletable?)
346
    @hours = TimeEntry.where(:issue_id => @issues.map(&:id)).sum(:hours).to_f
346
    issues_and_descendants_time_entries = TimeEntry.where([
347
      'issue_id IN (?)', @issues.collect(&:self_and_descendants).flatten
348
    ])
349
    @hours = issues_and_descendants_time_entries.sum(:hours).to_f
347 350
    if @hours > 0
348 351
      case params[:todo]
349 352
      when 'destroy'
350 353
        # nothing to do
351 354
      when 'nullify'
352
        TimeEntry.where(['issue_id IN (?)', @issues]).update_all('issue_id = NULL')
355
        issues_and_descendants_time_entries.update_all('issue_id = NULL')
353 356
      when 'reassign'
354 357
        reassign_to = @project.issues.find_by_id(params[:reassign_to_id])
355 358
        if reassign_to.nil?
356 359
          flash.now[:error] = l(:error_issue_not_found_in_project)
357 360
          return
358 361
        else
359
          TimeEntry.where(['issue_id IN (?)', @issues]).
360
            update_all("issue_id = #{reassign_to.id}")
362
          issues_and_descendants_time_entries.update_all("issue_id = #{reassign_to.id}")
361 363
        end
362 364
      else
363 365
        # display the destroy form if it's a user request
(1-1/4)