BigW Consortium Gitlab

importer.rb 2.46 KB
Newer Older
1 2 3
module Gitlab
  module ImportExport
    class Importer
4 5 6 7
      def self.imports_repository?
        true
      end

8 9 10
      def initialize(project)
        @archive_file = project.import_source
        @current_user = project.creator
11 12
        @project = project
        @shared = Gitlab::ImportExport::Shared.new(relative_path: path_with_namespace)
13 14
      end

15
      def execute
16
        if import_file && check_version! && [repo_restorer, wiki_restorer, project_tree, avatar_restorer, uploads_restorer].all?(&:restore)
17
          project_tree.restored_project
18
        else
19
          raise Projects::ImportService::Error.new(@shared.errors.join(', '))
20
        end
21 22

        remove_import_file
23 24 25 26
      end

      private

27 28 29 30 31
      def import_file
        Gitlab::ImportExport::FileImporter.import(archive_file: @archive_file,
                                                  shared: @shared)
      end

32 33 34 35 36 37 38 39 40 41
      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

42 43 44 45
      def avatar_restorer
        Gitlab::ImportExport::AvatarRestorer.new(project: project_tree.restored_project, shared: @shared)
      end

46 47 48
      def repo_restorer
        Gitlab::ImportExport::RepoRestorer.new(path_to_bundle: repo_path,
                                               shared: @shared,
49
                                               project: project_tree.restored_project)
50 51 52 53 54
      end

      def wiki_restorer
        Gitlab::ImportExport::RepoRestorer.new(path_to_bundle: wiki_repo_path,
                                               shared: @shared,
55
                                               project: ProjectWiki.new(project_tree.restored_project))
56 57 58
      end

      def uploads_restorer
59
        Gitlab::ImportExport::UploadsRestorer.new(project: project_tree.restored_project, shared: @shared)
60 61
      end

62
      def path_with_namespace
63
        File.join(@project.namespace.full_path, @project.path)
64 65 66 67 68 69 70 71 72
      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
73 74 75 76

      def remove_import_file
        FileUtils.rm_rf(@archive_file)
      end
77 78 79
    end
  end
end