2016-04-25 16:00:15 +00:00
|
|
|
module Gitlab
|
2016-03-09 15:21:02 +00:00
|
|
|
module ImportExport
|
2016-04-25 16:00:15 +00:00
|
|
|
class ImportService
|
|
|
|
|
|
|
|
def self.execute(*args)
|
2016-05-03 10:41:23 +00:00
|
|
|
new(*args).execute
|
2016-04-25 16:00:15 +00:00
|
|
|
end
|
|
|
|
|
2016-05-03 10:41:23 +00:00
|
|
|
def initialize(archive_file:, owner:, namespace_id:, project_path:)
|
|
|
|
@archive_file = archive_file
|
|
|
|
@current_user = owner
|
2016-05-04 15:42:02 +00:00
|
|
|
@namespace = Namespace.find(namespace_id)
|
2016-05-12 08:57:28 +00:00
|
|
|
@shared = Gitlab::ImportExport::Shared.new(relative_path: path_with_namespace(project_path), project_path: project_path)
|
2016-04-25 16:00:15 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def execute
|
2016-05-05 16:12:24 +00:00
|
|
|
Gitlab::ImportExport::Importer.import(archive_file: @archive_file,
|
2016-05-11 15:22:45 +00:00
|
|
|
shared: @shared)
|
2016-06-02 08:59:54 +00:00
|
|
|
if check_version! && [project_tree, repo_restorer, wiki_restorer, uploads_restorer].all?(&:restore)
|
2016-05-13 14:25:27 +00:00
|
|
|
project_tree.project
|
|
|
|
else
|
|
|
|
project_tree.project.destroy if project_tree.project
|
|
|
|
nil
|
|
|
|
end
|
2016-03-09 15:21:02 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
2016-06-02 08:59:54 +00:00
|
|
|
def check_version!
|
|
|
|
Gitlab::ImportExport::VersionChecker.check!(shared: @shared)
|
2016-03-09 15:21:02 +00:00
|
|
|
end
|
|
|
|
|
2016-04-15 16:14:28 +00:00
|
|
|
def project_tree
|
2016-05-11 15:22:45 +00:00
|
|
|
@project_tree ||= Gitlab::ImportExport::ProjectTreeRestorer.new(user: @current_user,
|
|
|
|
shared: @shared,
|
2016-05-05 16:12:24 +00:00
|
|
|
namespace_id: @namespace.id)
|
2016-04-15 16:14:28 +00:00
|
|
|
end
|
2016-03-09 15:21:02 +00:00
|
|
|
|
2016-06-02 08:59:54 +00:00
|
|
|
def repo_restorer
|
2016-05-05 16:12:24 +00:00
|
|
|
Gitlab::ImportExport::RepoRestorer.new(path_to_bundle: repo_path,
|
2016-05-11 15:22:45 +00:00
|
|
|
shared: @shared,
|
2016-06-02 08:59:54 +00:00
|
|
|
project: project_tree.project)
|
2016-05-05 10:39:18 +00:00
|
|
|
end
|
|
|
|
|
2016-06-02 08:59:54 +00:00
|
|
|
def wiki_restorer
|
2016-05-05 16:12:24 +00:00
|
|
|
Gitlab::ImportExport::RepoRestorer.new(path_to_bundle: wiki_repo_path,
|
2016-05-11 15:22:45 +00:00
|
|
|
shared: @shared,
|
2016-06-02 12:44:59 +00:00
|
|
|
project: ProjectWiki.new(project_tree.project),
|
|
|
|
wiki: true)
|
2016-04-22 10:45:20 +00:00
|
|
|
end
|
|
|
|
|
2016-06-02 08:59:54 +00:00
|
|
|
def uploads_restorer
|
|
|
|
Gitlab::ImportExport::UploadsRestorer.new(project: project_tree.project, shared: @shared)
|
2016-05-19 13:36:20 +00:00
|
|
|
end
|
|
|
|
|
2016-05-12 08:57:28 +00:00
|
|
|
def path_with_namespace(project_path)
|
|
|
|
File.join(@namespace.path, project_path)
|
2016-03-09 15:21:02 +00:00
|
|
|
end
|
2016-05-05 10:39:18 +00:00
|
|
|
|
|
|
|
def repo_path
|
2016-05-11 15:22:45 +00:00
|
|
|
File.join(@shared.export_path, 'project.bundle')
|
2016-05-05 10:39:18 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def wiki_repo_path
|
2016-05-11 15:22:45 +00:00
|
|
|
File.join(@shared.export_path, 'project.wiki.bundle')
|
2016-05-05 10:39:18 +00:00
|
|
|
end
|
2016-05-20 08:57:10 +00:00
|
|
|
|
|
|
|
def attributes_for_todo
|
|
|
|
{ user_id: @current_user.id,
|
|
|
|
project_id: project_tree.project.id,
|
|
|
|
target_type: 'Project',
|
|
|
|
target: project_tree.project,
|
|
|
|
action: Todo::IMPORTED,
|
|
|
|
author_id: @current_user.id,
|
|
|
|
state: :pending,
|
|
|
|
target_id: project_tree.project.id
|
|
|
|
}
|
|
|
|
end
|
2016-03-09 15:21:02 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|