2018-07-17 12:50:37 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2015-08-31 00:51:34 -04:00
|
|
|
module Milestones
|
|
|
|
class DestroyService < Milestones::BaseService
|
|
|
|
def execute(milestone)
|
|
|
|
Milestone.transaction do
|
2018-11-02 12:29:32 -04:00
|
|
|
update_params = { milestone: nil, skip_milestone_email: true }
|
2015-09-18 11:39:19 -04:00
|
|
|
|
2015-08-31 00:51:34 -04:00
|
|
|
milestone.issues.each do |issue|
|
2021-05-11 23:10:21 -04:00
|
|
|
Issues::UpdateService.new(project: parent, current_user: current_user, params: update_params).execute(issue)
|
2015-08-31 00:51:34 -04:00
|
|
|
end
|
|
|
|
|
2015-09-18 11:39:19 -04:00
|
|
|
milestone.merge_requests.each do |merge_request|
|
2021-05-11 23:10:21 -04:00
|
|
|
MergeRequests::UpdateService.new(project: parent, current_user: current_user, params: update_params).execute(merge_request)
|
2015-09-18 11:39:19 -04:00
|
|
|
end
|
|
|
|
|
2018-08-06 15:02:52 -04:00
|
|
|
log_destroy_event_for(milestone)
|
2015-08-31 00:51:34 -04:00
|
|
|
|
|
|
|
milestone.destroy
|
|
|
|
end
|
|
|
|
end
|
2018-08-06 15:02:52 -04:00
|
|
|
|
|
|
|
def log_destroy_event_for(milestone)
|
|
|
|
return if milestone.group_milestone?
|
|
|
|
|
|
|
|
event_service.destroy_milestone(milestone, current_user)
|
|
|
|
|
|
|
|
Event.for_milestone_id(milestone.id).each do |event|
|
|
|
|
event.target_id = nil
|
|
|
|
event.save
|
|
|
|
end
|
|
|
|
end
|
2015-08-31 00:51:34 -04:00
|
|
|
end
|
|
|
|
end
|