gitlab-org--gitlab-foss/app/services/projects/unlink_fork_service.rb
Bob Van Landuyt ac86249039 Don't link LFS-objects multiple times.
If Unlinking a fork would fail somewhere after this, the LFS objects
might still be linked. Which would cause issues when trying to destroy
a project.
2017-12-19 17:06:18 +01:00

32 lines
931 B
Ruby

module Projects
class UnlinkForkService < BaseService
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
@project.forked_project_link.destroy
end
def refresh_forks_count(project)
Projects::ForksCountService.new(project).refresh_cache
end
end
end