2018-07-16 12:31:01 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-11-25 10:04:45 -05:00
|
|
|
module Issuable
|
|
|
|
class DestroyService < IssuableBaseService
|
|
|
|
def execute(issuable)
|
2021-05-12 08:10:24 -04:00
|
|
|
after_destroy(issuable) if issuable.destroy
|
2021-04-07 23:09:23 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
2021-04-16 05:09:16 -04:00
|
|
|
def after_destroy(issuable)
|
2021-05-12 08:10:24 -04:00
|
|
|
delete_associated_records(issuable)
|
2021-04-16 05:09:16 -04:00
|
|
|
issuable.update_project_counter_caches
|
|
|
|
issuable.assignees.each(&:invalidate_cache_counts)
|
|
|
|
end
|
|
|
|
|
|
|
|
def group_for(issuable)
|
2021-04-20 05:09:48 -04:00
|
|
|
issuable.resource_parent.group
|
2021-04-16 05:09:16 -04:00
|
|
|
end
|
|
|
|
|
2021-05-12 08:10:24 -04:00
|
|
|
def delete_associated_records(issuable)
|
2021-04-20 05:09:48 -04:00
|
|
|
actor = group_for(issuable)
|
2021-04-07 23:09:23 -04:00
|
|
|
|
2021-05-12 08:10:24 -04:00
|
|
|
delete_todos(actor, issuable)
|
|
|
|
delete_label_links(actor, issuable)
|
|
|
|
end
|
|
|
|
|
|
|
|
def delete_todos(actor, issuable)
|
2022-04-21 05:10:19 -04:00
|
|
|
issuable.run_after_commit_or_now do
|
|
|
|
TodosDestroyer::DestroyedIssuableWorker.perform_async(issuable.id, issuable.class.name)
|
|
|
|
end
|
2017-11-25 10:04:45 -05:00
|
|
|
end
|
2021-05-12 08:10:24 -04:00
|
|
|
|
|
|
|
def delete_label_links(actor, issuable)
|
2022-04-21 05:10:19 -04:00
|
|
|
issuable.run_after_commit_or_now do
|
|
|
|
Issuable::LabelLinksDestroyWorker.perform_async(issuable.id, issuable.class.name)
|
|
|
|
end
|
2021-05-12 08:10:24 -04:00
|
|
|
end
|
2017-11-25 10:04:45 -05:00
|
|
|
end
|
|
|
|
end
|
2021-04-16 05:09:16 -04:00
|
|
|
|
2021-05-11 17:10:21 -04:00
|
|
|
Issuable::DestroyService.prepend_mod_with('Issuable::DestroyService')
|