2018-06-27 03:23:28 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-05-08 11:13:02 -04:00
|
|
|
# Worker to destroy projects that do not have a namespace
|
|
|
|
#
|
|
|
|
# It destroys everything it can without having the info about the namespace it
|
|
|
|
# used to belong to. Projects in this state should be rare.
|
|
|
|
# The worker will reject doing anything for projects that *do* have a
|
|
|
|
# namespace. For those use ProjectDestroyWorker instead.
|
2020-02-19 13:09:10 -05:00
|
|
|
class NamespacelessProjectDestroyWorker # rubocop:disable Scalability/IdempotentWorker
|
2017-11-28 11:08:30 -05:00
|
|
|
include ApplicationWorker
|
2021-04-30 14:10:09 -04:00
|
|
|
|
2021-07-21 08:09:35 -04:00
|
|
|
data_consistency :always
|
|
|
|
|
2021-04-30 14:10:09 -04:00
|
|
|
sidekiq_options retry: 3
|
2017-08-24 15:24:58 -04:00
|
|
|
include ExceptionBacktrace
|
2017-05-08 11:13:02 -04:00
|
|
|
|
2019-10-18 07:11:44 -04:00
|
|
|
feature_category :authentication_and_authorization
|
|
|
|
|
2017-05-09 16:16:52 -04:00
|
|
|
def perform(project_id)
|
2017-05-08 11:13:02 -04:00
|
|
|
begin
|
|
|
|
project = Project.unscoped.find(project_id)
|
|
|
|
rescue ActiveRecord::RecordNotFound
|
|
|
|
return
|
|
|
|
end
|
2017-08-16 08:46:26 -04:00
|
|
|
|
2019-01-16 07:09:29 -05:00
|
|
|
return if project.namespace # Reject doing anything for projects that *do* have a namespace
|
2017-05-08 11:13:02 -04:00
|
|
|
|
|
|
|
project.team.truncate
|
|
|
|
|
|
|
|
unlink_fork(project) if project.forked?
|
|
|
|
|
|
|
|
project.destroy!
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def unlink_fork(project)
|
|
|
|
merge_requests = project.forked_from_project.merge_requests.opened.from_project(project)
|
|
|
|
|
2019-10-18 07:11:44 -04:00
|
|
|
merge_requests.update_all(state_id: MergeRequest.available_states[:closed])
|
2017-05-08 11:13:02 -04:00
|
|
|
end
|
|
|
|
end
|