2c0b677604
The problem would occur when the `ForkedProjectLink` was deleted, but the `ForkNetworkMember` was not. The delete would be rolled back and retried. But the error would not be saved because `Project#forked?` would still be true, because the `ForkNetworkMember` exists. But the `Project#forked_project_link` would be `nil`. So the validation for the visibility level would fail.
26 lines
724 B
Ruby
26 lines
724 B
Ruby
module Projects
|
|
class UnlinkForkService < BaseService
|
|
def execute
|
|
return unless @project.forked?
|
|
|
|
@project.forked_from_project.lfs_objects.find_each do |lfs_object|
|
|
lfs_object.projects << @project
|
|
end
|
|
|
|
merge_requests = @project.forked_from_project.merge_requests.opened.from_project(@project)
|
|
|
|
merge_requests.each do |mr|
|
|
::MergeRequests::CloseService.new(@project, @current_user).execute(mr)
|
|
end
|
|
|
|
refresh_forks_count(@project.forked_from_project)
|
|
|
|
@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
|