namespaceless_project_destroy_worker.rb 1000 Bytes
Newer Older
1 2 3 4 5 6 7
# 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.
class NamespacelessProjectDestroyWorker
8
  include ApplicationWorker
9
  include ExceptionBacktrace
10

11
  def perform(project_id)
12 13 14 15 16
    begin
      project = Project.unscoped.find(project_id)
    rescue ActiveRecord::RecordNotFound
      return
    end
17

18
    return if project.namespace  # Reject doing anything for projects that *do* have a namespace
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36

    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)

    merge_requests.update_all(state: 'closed')

    project.forked_project_link.destroy
  end
end