Skip to content
代码片段 群组 项目
提交 cba6e924 编辑于 作者: Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets
浏览文件

move transfer logic out of project to service

上级 0cf0487d
No related branches found
No related tags found
无相关合并请求
......@@ -247,32 +247,6 @@ def team_member_by_id(user_id)
users_projects.find_by_user_id(user_id)
end
def transfer(new_namespace)
Project.transaction do
old_namespace = namespace
self.namespace = new_namespace
old_dir = old_namespace.try(:path) || ''
new_dir = new_namespace.try(:path) || ''
old_repo = if old_dir.present?
File.join(old_dir, self.path)
else
self.path
end
if Project.where(path: self.path, namespace_id: new_namespace.try(:id)).present?
raise TransferError.new("Project with same path in target namespace already exists")
end
Gitlab::ProjectMover.new(self, old_dir, new_dir).execute
save!
end
rescue Gitlab::ProjectMover::ProjectMoveError => ex
raise Project::TransferError.new(ex.message)
end
def name_with_namespace
@name_with_namespace ||= begin
if namespace
......@@ -295,6 +269,10 @@ def path_with_namespace
end
end
def transfer(new_namespace)
ProjectTransferService.new.transfer(self, new_namespace)
end
def execute_hooks(data)
hooks.each { |hook| hook.async_execute(data) }
end
......
# ProjectTransferService class
#
# Used for transfer project to another namespace
#
class ProjectTransferService
attr_accessor :project
def transfer(project, new_namespace)
Project.transaction do
old_namespace = project.namespace
project.namespace = new_namespace
old_dir = old_namespace.try(:path) || ''
new_dir = new_namespace.try(:path) || ''
old_repo = if old_dir.present?
File.join(old_dir, project.path)
else
project.path
end
if Project.where(path: project.path, namespace_id: new_namespace.try(:id)).present?
raise TransferError.new("Project with same path in target namespace already exists")
end
Gitlab::ProjectMover.new(project, old_dir, new_dir).execute
save!
end
rescue Gitlab::ProjectMover::ProjectMoveError => ex
raise Project::TransferError.new(ex.message)
end
end
0% 加载中 .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册