2020-04-08 14:13:33 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Gitlab
|
|
|
|
module ImportExport
|
|
|
|
module Group
|
2020-04-22 19:07:51 +05:30
|
|
|
class LegacyTreeSaver
|
2020-04-08 14:13:33 +05:30
|
|
|
attr_reader :full_path, :shared
|
|
|
|
|
|
|
|
def initialize(group:, current_user:, shared:, params: {})
|
|
|
|
@params = params
|
|
|
|
@current_user = current_user
|
|
|
|
@shared = shared
|
|
|
|
@group = group
|
|
|
|
@full_path = File.join(@shared.export_path, ImportExport.group_filename)
|
|
|
|
end
|
|
|
|
|
|
|
|
def save
|
|
|
|
group_tree = serialize(@group, reader.group_tree)
|
|
|
|
tree_saver.save(group_tree, @shared.export_path, ImportExport.group_filename)
|
|
|
|
|
|
|
|
true
|
2021-06-08 01:23:25 +05:30
|
|
|
rescue StandardError => e
|
2020-04-08 14:13:33 +05:30
|
|
|
@shared.error(e)
|
|
|
|
false
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def serialize(group, relations_tree)
|
|
|
|
group_tree = tree_saver.serialize(group, relations_tree)
|
|
|
|
|
|
|
|
group.children.each do |child|
|
|
|
|
group_tree['children'] ||= []
|
|
|
|
group_tree['children'] << serialize(child, relations_tree)
|
|
|
|
end
|
|
|
|
|
|
|
|
group_tree
|
2021-06-08 01:23:25 +05:30
|
|
|
rescue StandardError => e
|
2020-04-08 14:13:33 +05:30
|
|
|
@shared.error(e)
|
|
|
|
end
|
|
|
|
|
|
|
|
def reader
|
|
|
|
@reader ||= Gitlab::ImportExport::Reader.new(
|
|
|
|
shared: @shared,
|
|
|
|
config: Gitlab::ImportExport::Config.new(
|
2020-05-24 23:13:21 +05:30
|
|
|
config: Gitlab::ImportExport.legacy_group_config_file
|
2020-04-08 14:13:33 +05:30
|
|
|
).to_h
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
def tree_saver
|
|
|
|
@tree_saver ||= LegacyRelationTreeSaver.new
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|