gitlab-org--gitlab-foss/app/services/projects/unlink_fork_service.rb
Bob Van Landuyt f3fba178b9 Remove the ForkedProjectLink model
This removes the `ForkedProjectLink` model that has been replaced by
the `ForkNetworkMember` and `ForkNetwork` combination. All existing
relations have been adjusted to use these new models.

The `forked_project_link` table has been dropped.

The "Forks" count on the admin dashboard has been updated to count all
`ForkNetworkMember` rows and deduct the number of `ForkNetwork`
rows. This is because now the "root-project" of a fork network also
has a `ForkNetworkMember` row. This count could become inaccurate when
the root of a fork network is deleted.
2018-10-19 11:57:20 +02:00

35 lines
1,010 B
Ruby

# frozen_string_literal: true
module Projects
class UnlinkForkService < BaseService
# rubocop: disable CodeReuse/ActiveRecord
def execute
return unless @project.forked?
if fork_source = @project.fork_source
fork_source.lfs_objects.find_each do |lfs_object|
lfs_object.projects << @project unless lfs_object.projects.include?(@project)
end
refresh_forks_count(fork_source)
end
merge_requests = @project.fork_network
.merge_requests
.opened
.where.not(target_project: @project)
.from_project(@project)
merge_requests.each do |mr|
::MergeRequests::CloseService.new(@project, @current_user).execute(mr)
end
@project.fork_network_member.destroy
end
# rubocop: enable CodeReuse/ActiveRecord
def refresh_forks_count(project)
Projects::ForksCountService.new(project).refresh_cache
end
end
end