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
|
|
|
|
end
|
|
|
|
|
|
|
|
def save
|
2020-03-26 18:08:03 +00:00
|
|
|
ImportExport::JSON::StreamingSerializer.new(
|
|
|
|
exportable,
|
|
|
|
reader.project_tree,
|
|
|
|
json_writer,
|
|
|
|
exportable_path: "project"
|
|
|
|
).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
|
2020-04-06 12:10:44 +00:00
|
|
|
|
|
|
|
def json_writer
|
|
|
|
@json_writer ||= begin
|
2020-05-18 15:08:15 +00:00
|
|
|
if ::Feature.enabled?(:project_export_as_ndjson, @project.namespace, default_enabled: true)
|
2020-04-06 12:10:44 +00:00
|
|
|
full_path = File.join(@shared.export_path, 'tree')
|
|
|
|
Gitlab::ImportExport::JSON::NdjsonWriter.new(full_path)
|
|
|
|
else
|
|
|
|
full_path = File.join(@shared.export_path, ImportExport.project_filename)
|
|
|
|
Gitlab::ImportExport::JSON::LegacyWriter.new(full_path, allowed_path: 'project')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2020-02-26 18:09:24 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|