2018-07-17 16:50:37 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-03-22 14:34:35 +00:00
|
|
|
module Projects
|
|
|
|
class UnlinkForkService < BaseService
|
|
|
|
def execute
|
|
|
|
return unless @project.forked?
|
|
|
|
|
2017-11-03 10:31:29 +00:00
|
|
|
if fork_source = @project.fork_source
|
|
|
|
fork_source.lfs_objects.find_each do |lfs_object|
|
2017-12-19 09:57:12 +00:00
|
|
|
lfs_object.projects << @project unless lfs_object.projects.include?(@project)
|
2017-11-03 10:31:29 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
refresh_forks_count(fork_source)
|
2016-03-22 14:34:35 +00:00
|
|
|
end
|
|
|
|
|
2017-11-03 10:31:29 +00:00
|
|
|
merge_requests = @project.fork_network
|
|
|
|
.merge_requests
|
|
|
|
.opened
|
|
|
|
.where.not(target_project: @project)
|
|
|
|
.from_project(@project)
|
2016-03-22 14:34:35 +00:00
|
|
|
|
|
|
|
merge_requests.each do |mr|
|
2017-06-13 22:12:31 +00:00
|
|
|
::MergeRequests::CloseService.new(@project, @current_user).execute(mr)
|
2016-03-22 14:34:35 +00:00
|
|
|
end
|
|
|
|
|
2017-09-30 18:21:08 +00:00
|
|
|
@project.fork_network_member.destroy
|
2017-10-17 14:33:30 +00:00
|
|
|
@project.forked_project_link.destroy
|
2016-03-22 14:34:35 +00:00
|
|
|
end
|
2017-08-14 13:22:09 +00:00
|
|
|
|
|
|
|
def refresh_forks_count(project)
|
|
|
|
Projects::ForksCountService.new(project).refresh_cache
|
|
|
|
end
|
2016-03-22 14:34:35 +00:00
|
|
|
end
|
|
|
|
end
|