blob: b3cf27373cde13c9dce3e2aee232d63a170f51ef (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
|
# frozen_string_literal: true
module Projects
class UnlinkForkService < BaseService
# If a fork is given, it:
#
# - Saves LFS objects to the root project
# - Close existing MRs coming from it
# - Is removed from the fork network
#
# If a root of fork(s) is given, it does the same,
# but not updating LFS objects (there'll be no related root to cache it).
def execute
fork_network = @project.fork_network
return unless fork_network
save_lfs_objects
merge_requests = fork_network
.merge_requests
.opened
.from_and_to_forks(@project)
merge_requests.find_each do |mr|
::MergeRequests::CloseService.new(@project, @current_user).execute(mr)
end
Project.transaction do
# Get out of the fork network as a member and
# remove references from all its direct forks.
@project.fork_network_member.destroy
@project.forked_to_members.update_all(forked_from_project_id: nil)
# The project is not necessarily a fork, so update the fork network originating
# from this project
if fork_network = @project.root_of_fork_network
fork_network.update(root_project: nil, deleted_root_project_name: @project.full_name)
end
end
# When the project getting out of the network is a node with parent
# and children, both the parent and the node needs a cache refresh.
[@project.forked_from_project, @project].compact.each do |project|
refresh_forks_count(project)
end
end
private
def refresh_forks_count(project)
Projects::ForksCountService.new(project).refresh_cache
end
# TODO: Remove this method once all LfsObjectsProject records are backfilled
# for forks.
#
# See https://gitlab.com/gitlab-org/gitlab/issues/122002 for more info.
def save_lfs_objects
return unless @project.forked?
lfs_storage_project = @project.lfs_storage_project
return unless lfs_storage_project
return if lfs_storage_project == @project # that project is being unlinked
lfs_storage_project.lfs_objects.find_each do |lfs_object|
lfs_object.projects << @project unless lfs_object.projects.include?(@project)
end
end
end
end
|