2020-02-26 18:09:24 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Gitlab
|
|
|
|
module ImportExport
|
|
|
|
module Project
|
|
|
|
class TreeSaver
|
|
|
|
attr_reader :full_path
|
|
|
|
|
|
|
|
def initialize(project:, current_user:, shared:, params: {})
|
|
|
|
@params = params
|
|
|
|
@project = project
|
|
|
|
@current_user = current_user
|
|
|
|
@shared = shared
|
|
|
|
@full_path = File.join(@shared.export_path, ImportExport.project_filename)
|
|
|
|
end
|
|
|
|
|
|
|
|
def save
|
2020-03-17 18:09:44 +00:00
|
|
|
json_writer = ImportExport::JSON::LegacyWriter.new(@full_path)
|
|
|
|
|
|
|
|
serializer = ImportExport::JSON::StreamingSerializer.new(exportable, reader.project_tree, json_writer)
|
|
|
|
serializer.execute
|
2020-02-26 18:09:24 +00:00
|
|
|
|
|
|
|
true
|
|
|
|
rescue => e
|
|
|
|
@shared.error(e)
|
|
|
|
false
|
2020-03-17 18:09:44 +00:00
|
|
|
ensure
|
|
|
|
json_writer&.close
|
2020-02-26 18:09:24 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def reader
|
|
|
|
@reader ||= Gitlab::ImportExport::Reader.new(shared: @shared)
|
|
|
|
end
|
|
|
|
|
2020-03-17 18:09:44 +00:00
|
|
|
def exportable
|
|
|
|
@project.present(exportable_params)
|
2020-02-26 18:09:24 +00:00
|
|
|
end
|
|
|
|
|
2020-03-17 18:09:44 +00:00
|
|
|
def exportable_params
|
|
|
|
params = {
|
|
|
|
presenter_class: presenter_class,
|
|
|
|
current_user: @current_user
|
|
|
|
}
|
|
|
|
params[:override_description] = @params[:description] if @params[:description].present?
|
|
|
|
params
|
2020-02-26 18:09:24 +00:00
|
|
|
end
|
|
|
|
|
2020-03-17 18:09:44 +00:00
|
|
|
def presenter_class
|
|
|
|
Projects::ImportExport::ProjectExportPresenter
|
2020-02-26 18:09:24 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|