gitlab-org--gitlab-foss/app/services/groups/destroy_service.rb
Stan Hu fa93156528 Defer project destroys within a namespace in Groups::DestroyService#async_execute
Group#destroy would actually hard-delete all associated projects even
though the acts_as_paranoia gem is used, preventing Projects::DestroyService
from doing any work.

We first noticed this while trying to log all projects deletion to the Geo
log.
2017-06-29 09:23:31 -07:00

27 lines
962 B
Ruby

module Groups
class DestroyService < Groups::BaseService
def async_execute
group.soft_delete_without_removing_associations
job_id = GroupDestroyWorker.perform_async(group.id, current_user.id)
Rails.logger.info("User #{current_user.id} scheduled a deletion of group ID #{group.id} with job ID #{job_id}")
end
def execute
group.prepare_for_destroy
group.projects.each do |project|
# Execute the destruction of the models immediately to ensure atomic cleanup.
# Skip repository removal because we remove directory with namespace
# that contain all these repositories
::Projects::DestroyService.new(project, current_user, skip_repo: true).execute
end
group.children.each do |group|
# This needs to be synchronous since the namespace gets destroyed below
DestroyService.new(group, current_user).execute
end
group.really_destroy!
end
end
end