2018-07-17 16:50:37 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-04-06 15:23:49 +00:00
|
|
|
module Projects
|
|
|
|
class MoveForksService < BaseMoveRelationsService
|
|
|
|
def execute(source_project, remove_remaining_elements: true)
|
|
|
|
return unless super && source_project.fork_network
|
|
|
|
|
|
|
|
Project.transaction(requires_new: true) do
|
|
|
|
move_fork_network_members
|
|
|
|
update_root_project
|
|
|
|
refresh_forks_count
|
|
|
|
|
|
|
|
success
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
2018-08-27 15:31:01 +00:00
|
|
|
# rubocop: disable CodeReuse/ActiveRecord
|
2018-04-06 15:23:49 +00:00
|
|
|
def move_fork_network_members
|
|
|
|
ForkNetworkMember.where(project: source_project).update_all(project_id: @project.id)
|
|
|
|
ForkNetworkMember.where(forked_from_project: source_project).update_all(forked_from_project_id: @project.id)
|
|
|
|
end
|
2018-08-27 15:31:01 +00:00
|
|
|
# rubocop: enable CodeReuse/ActiveRecord
|
2018-04-06 15:23:49 +00:00
|
|
|
|
2018-08-27 15:31:01 +00:00
|
|
|
# rubocop: disable CodeReuse/ActiveRecord
|
2018-04-06 15:23:49 +00:00
|
|
|
def update_root_project
|
|
|
|
# Update root network project
|
|
|
|
ForkNetwork.where(root_project: source_project).update_all(root_project_id: @project.id)
|
|
|
|
end
|
2018-08-27 15:31:01 +00:00
|
|
|
# rubocop: enable CodeReuse/ActiveRecord
|
2018-04-06 15:23:49 +00:00
|
|
|
|
|
|
|
def refresh_forks_count
|
|
|
|
Projects::ForksCountService.new(@project).refresh_cache
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|