Commit a59ba217 authored by James Lopez's avatar James Lopez

WIP - building up import tree with sub relations, etc

parent 25e078c1
...@@ -10,6 +10,10 @@ module Projects ...@@ -10,6 +10,10 @@ module Projects
%i(name path description issues_enabled wall_enabled merge_requests_enabled wiki_enabled snippets_enabled visibility_level archived) %i(name path description issues_enabled wall_enabled merge_requests_enabled wiki_enabled snippets_enabled visibility_level archived)
end end
def project_tree_list
project_tree.map {|r| r.is_a?(Hash) ? r.keys.first : r }
end
def project_tree def project_tree
%i(issues labels milestones snippets releases events) + [members, merge_requests, commit_statuses] %i(issues labels milestones snippets releases events) + [members, merge_requests, commit_statuses]
end end
......
...@@ -12,6 +12,7 @@ module Projects ...@@ -12,6 +12,7 @@ module Projects
json = IO.read(@path) json = IO.read(@path)
@tree_hash = ActiveSupport::JSON.decode(json) @tree_hash = ActiveSupport::JSON.decode(json)
create_relations create_relations
puts project.inspect
end end
private private
...@@ -21,14 +22,36 @@ module Projects ...@@ -21,14 +22,36 @@ module Projects
exported_members: @tree_hash.delete('project_members'), user: @user, project_id: project.id) exported_members: @tree_hash.delete('project_members'), user: @user, project_id: project.id)
end end
def create_relations #TODO Definitely refactor this method!
(ImportExport.project_tree - [:project_members]).each do |relation| def create_relations(relation_list = default_relation_list, tree_hash = @tree_hash)
next if @tree_hash[relation.to_s].empty? relation_list.each do |relation|
relation_hash = create_relation(relation, @tree_hash[relation.to_s]) relation_hash = nil
# FIXME
# next if tree_hash[relation.to_s].blank?
if (relation.is_a?(Hash) && relation.values.first[:include])
#TODO name stuff properly
relation_sym = relation.keys.first
#TODO remove sub-relation hashes from here so we can save the parent relation first
relation_hash = create_relation(relation_sym, tree_hash[relation_sym.to_s])
sub_relations = []
sub_relation = relation.values.first[:include]
sub_relation_hash_list = tree_hash[relation.keys.first.to_s]
sub_relation_hash_list.each do |sub_relation_hash|
sub_relations << create_relation(relation, sub_relation_hash[relation.to_s])
end
relation_hash.update_attribute(sub_relation, sub_relations)
end
relation_hash ||= create_relation(relation, tree_hash[relation.to_s])
project.update_attribute(relation, relation_hash) project.update_attribute(relation, relation_hash)
end end
end end
def default_relation_list
ImportExport.project_tree.reject do |rel|
rel.is_a?(Hash) && !rel[:project_members].blank?
end
end
def project def project
@project ||= create_project @project ||= create_project
end end
...@@ -42,7 +65,7 @@ module Projects ...@@ -42,7 +65,7 @@ module Projects
end end
def create_relation(relation, relation_hash_list) def create_relation(relation, relation_hash_list)
relation_hash_list.map do |relation_hash| [relation_hash_list].flatten.map do |relation_hash|
Projects::ImportExport::RelationFactory.create( Projects::ImportExport::RelationFactory.create(
relation_sym: relation, relation_hash: relation_hash.merge('project_id' => project.id), members_map: members_map) relation_sym: relation, relation_hash: relation_hash.merge('project_id' => project.id), members_map: members_map)
end end
......
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment