2016-04-15 12:14:28 -04:00
|
|
|
module Gitlab
|
|
|
|
module ImportExport
|
|
|
|
class Importer
|
2017-11-15 07:27:37 -05:00
|
|
|
def self.imports_repository?
|
|
|
|
true
|
|
|
|
end
|
|
|
|
|
2016-06-14 06:47:07 -04:00
|
|
|
def initialize(project)
|
|
|
|
@archive_file = project.import_source
|
|
|
|
@current_user = project.creator
|
2016-06-14 14:32:19 -04:00
|
|
|
@project = project
|
2018-03-05 14:53:40 -05:00
|
|
|
@shared = project.import_export_shared
|
2016-04-15 12:14:28 -04:00
|
|
|
end
|
|
|
|
|
2016-06-14 06:47:07 -04:00
|
|
|
def execute
|
2017-04-04 12:34:19 -04:00
|
|
|
if import_file && check_version! && [repo_restorer, wiki_restorer, project_tree, avatar_restorer, uploads_restorer].all?(&:restore)
|
2016-06-14 14:32:19 -04:00
|
|
|
project_tree.restored_project
|
2016-06-14 06:47:07 -04:00
|
|
|
else
|
2016-06-15 11:31:00 -04:00
|
|
|
raise Projects::ImportService::Error.new(@shared.errors.join(', '))
|
2016-06-14 06:47:07 -04:00
|
|
|
end
|
2016-06-24 04:50:23 -04:00
|
|
|
|
|
|
|
remove_import_file
|
2016-04-15 12:14:28 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
2016-06-24 04:50:23 -04:00
|
|
|
def import_file
|
|
|
|
Gitlab::ImportExport::FileImporter.import(archive_file: @archive_file,
|
|
|
|
shared: @shared)
|
|
|
|
end
|
|
|
|
|
2016-06-14 06:47:07 -04:00
|
|
|
def check_version!
|
|
|
|
Gitlab::ImportExport::VersionChecker.check!(shared: @shared)
|
|
|
|
end
|
|
|
|
|
|
|
|
def project_tree
|
|
|
|
@project_tree ||= Gitlab::ImportExport::ProjectTreeRestorer.new(user: @current_user,
|
|
|
|
shared: @shared,
|
|
|
|
project: @project)
|
|
|
|
end
|
|
|
|
|
2016-07-15 10:03:31 -04:00
|
|
|
def avatar_restorer
|
|
|
|
Gitlab::ImportExport::AvatarRestorer.new(project: project_tree.restored_project, shared: @shared)
|
|
|
|
end
|
|
|
|
|
2016-06-14 06:47:07 -04:00
|
|
|
def repo_restorer
|
|
|
|
Gitlab::ImportExport::RepoRestorer.new(path_to_bundle: repo_path,
|
|
|
|
shared: @shared,
|
2016-06-14 14:32:19 -04:00
|
|
|
project: project_tree.restored_project)
|
2016-06-14 06:47:07 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def wiki_restorer
|
2018-02-12 10:38:10 -05:00
|
|
|
Gitlab::ImportExport::WikiRestorer.new(path_to_bundle: wiki_repo_path,
|
2016-06-14 06:47:07 -04:00
|
|
|
shared: @shared,
|
2018-02-12 10:38:10 -05:00
|
|
|
project: ProjectWiki.new(project_tree.restored_project),
|
|
|
|
wiki_enabled: @project.wiki_enabled?)
|
2016-06-14 06:47:07 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def uploads_restorer
|
2016-06-14 14:32:19 -04:00
|
|
|
Gitlab::ImportExport::UploadsRestorer.new(project: project_tree.restored_project, shared: @shared)
|
2016-06-14 06:47:07 -04:00
|
|
|
end
|
|
|
|
|
2016-06-14 14:32:19 -04:00
|
|
|
def path_with_namespace
|
2017-02-14 09:03:24 -05:00
|
|
|
File.join(@project.namespace.full_path, @project.path)
|
2016-06-14 06:47:07 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def repo_path
|
|
|
|
File.join(@shared.export_path, 'project.bundle')
|
|
|
|
end
|
|
|
|
|
|
|
|
def wiki_repo_path
|
|
|
|
File.join(@shared.export_path, 'project.wiki.bundle')
|
|
|
|
end
|
2016-06-24 04:50:23 -04:00
|
|
|
|
|
|
|
def remove_import_file
|
|
|
|
FileUtils.rm_rf(@archive_file)
|
|
|
|
end
|
2016-04-15 12:14:28 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|