mirror of
https://github.com/wahyd4/gitlabhq.git
synced 2026-08-17 16:46:06 +10:00
@@ -14,12 +14,12 @@ module Projects
|
||||
json = IO.read(@path)
|
||||
tree_hash = ActiveSupport::JSON.decode(json)
|
||||
relation_hash = {}
|
||||
project_params = tree_hash.reject { |_key, value | value.is_a?(Array)}
|
||||
@project = ::Projects::CreateService.new(@user, project_params.except('id')).execute
|
||||
ImportExport.project_tree.each do |relation|
|
||||
next if tree_hash[relation.to_s].empty?
|
||||
relation_hash[relation.to_s] = create_relation(relation, tree_hash[relation.to_s])
|
||||
end
|
||||
project_params = tree_hash.delete_if { |_key, value | value.is_a?(Array)}
|
||||
@project = ::Projects::CreateService.new(@user, project_params).execute
|
||||
@project.saved?
|
||||
end
|
||||
|
||||
@@ -28,7 +28,7 @@ module Projects
|
||||
def create_relation(relation, relation_hash_list)
|
||||
relation_hash_list.map do |relation_hash|
|
||||
Projects::ImportExport::RelationFactory.create(
|
||||
relation_sym: relation, relation_hash: relation_hash, project: @project, user: @user)
|
||||
relation_sym: relation, relation_hash: relation_hash)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,43 +1,24 @@
|
||||
module Projects
|
||||
module ImportExport
|
||||
class RelationFactory
|
||||
module RelationFactory
|
||||
extend self
|
||||
|
||||
OVERRIDES = { snippets: :project_snippets }
|
||||
|
||||
def self.create(*args)
|
||||
new(*args).create
|
||||
end
|
||||
|
||||
def initialize(relation_sym:, relation_hash:, project:, user:)
|
||||
@relation_sym = parsed_relation_sym(relation_sym)
|
||||
@relation_hash = relation_hash
|
||||
@project = project
|
||||
@user = user
|
||||
end
|
||||
|
||||
def create
|
||||
@relation_hash.delete('id')
|
||||
init_service_or_class
|
||||
def create(relation_sym:, relation_hash:)
|
||||
relation_sym = parse_relation_sym(relation_sym)
|
||||
klass = relation_class(relation_sym)
|
||||
relation_hash.delete('id') #screw IDs for now
|
||||
klass.new(relation_hash)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def init_service_or_class
|
||||
# Attempt service first
|
||||
relation_service.new(@project, @user, @relation_hash).execute
|
||||
rescue NameError
|
||||
relation_class.new(@relation_hash)
|
||||
def relation_class(relation_sym)
|
||||
relation_sym.to_s.classify.constantize
|
||||
end
|
||||
|
||||
def relation_service
|
||||
"#{@relation_sym.to_s.classify}::CreateService".constantize
|
||||
end
|
||||
|
||||
def relation_class
|
||||
@relation_sym.to_s.classify.constantize
|
||||
end
|
||||
|
||||
def parsed_relation_sym(relation_sym)
|
||||
def parse_relation_sym(relation_sym)
|
||||
OVERRIDES[relation_sym] || relation_sym
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user