mirror of
https://github.com/wahyd4/gitlabhq.git
synced 2026-08-18 17:16:08 +10:00
more refactoring
This commit is contained in:
@@ -30,24 +30,8 @@ module Projects
|
||||
relation_key = relation.is_a?(Hash) ? relation.keys.first : relation
|
||||
relation_hash = create_relation(relation_key, tree_hash[relation_key.to_s])
|
||||
project.update_attribute(relation_key, relation_hash)
|
||||
# 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)
|
||||
# FIXME
|
||||
# next if tree_hash[relation.to_s].blank?
|
||||
end
|
||||
end
|
||||
|
||||
@@ -68,14 +52,11 @@ module Projects
|
||||
end
|
||||
|
||||
def create_sub_relations(relation, tree_hash)
|
||||
# TODO refactor this
|
||||
relation_key = relation.keys.first
|
||||
tree_hash[relation_key.to_s].each do |relation_item|
|
||||
tree_hash[relation.keys.first.to_s].each do |relation_item|
|
||||
relation.values.flatten.each do |sub_relation|
|
||||
relation_hash = relation_item[sub_relation.to_s]
|
||||
next if relation_hash.blank?
|
||||
sub_relation_object = Projects::ImportExport::RelationFactory.create(
|
||||
relation_sym: sub_relation, relation_hash: relation_hash.merge!('project_id' => project.id), members_map: members_map)
|
||||
sub_relation_object = relation_from_factory(relation, relation_hash)
|
||||
relation_item[sub_relation.to_s] = sub_relation_object
|
||||
end
|
||||
end
|
||||
@@ -83,10 +64,14 @@ module Projects
|
||||
|
||||
def create_relation(relation, relation_hash_list)
|
||||
[relation_hash_list].flatten.map do |relation_hash|
|
||||
Projects::ImportExport::RelationFactory.create(
|
||||
relation_sym: relation, relation_hash: relation_hash.merge('project_id' => project.id), members_map: members_map)
|
||||
relation_from_factory(relation, relation_hash)
|
||||
end
|
||||
end
|
||||
|
||||
def relation_from_factory(relation, relation_hash)
|
||||
Projects::ImportExport::RelationFactory.create(
|
||||
relation_sym: relation, relation_hash: relation_hash.merge('project_id' => project.id), members_map: members_map)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -7,16 +7,13 @@ module Projects
|
||||
USER_REFERENCES = %w(author_id assignee_id updated_by_id).freeze
|
||||
|
||||
def create(relation_sym:, relation_hash:, members_map:)
|
||||
#TODO refactor this
|
||||
relation_sym = parse_relation_sym(relation_sym)
|
||||
klass = relation_class(relation_sym)
|
||||
relation_hash.delete('id') #screw IDs for now
|
||||
relation_hash.delete('project_id') unless klass.column_names.include?(:project_id)
|
||||
klass = parse_relation(relation_hash, relation_sym)
|
||||
|
||||
handle_merge_requests(relation_hash) if relation_sym == :merge_requests
|
||||
update_user_references(relation_hash, members_map)
|
||||
imported_object = klass.new(relation_hash)
|
||||
imported_object.importing = true if imported_object.respond_to?(:importing)
|
||||
imported_object
|
||||
|
||||
imported_object(klass, relation_hash)
|
||||
end
|
||||
|
||||
private
|
||||
@@ -42,6 +39,19 @@ module Projects
|
||||
def parse_relation_sym(relation_sym)
|
||||
OVERRIDES[relation_sym] || relation_sym
|
||||
end
|
||||
|
||||
def imported_object(klass, relation_hash)
|
||||
imported_object = klass.new(relation_hash)
|
||||
imported_object.importing = true if imported_object.respond_to?(:importing)
|
||||
imported_object
|
||||
end
|
||||
|
||||
def parse_relation(relation_hash, relation_sym)
|
||||
klass = relation_class(relation_sym)
|
||||
relation_hash.delete('id') #screw IDs for now
|
||||
relation_hash.delete('project_id') unless klass.column_names.include?(:project_id)
|
||||
klass
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user