Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Boxiang Sun
gitlab-ce
Commits
eb55cb92
Commit
eb55cb92
authored
Apr 12, 2016
by
James Lopez
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
more refactoring
parent
4ffcd427
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
27 additions
and
32 deletions
+27
-32
app/services/projects/import_export/project_tree_restorer.rb
app/services/projects/import_export/project_tree_restorer.rb
+10
-25
app/services/projects/import_export/relation_factory.rb
app/services/projects/import_export/relation_factory.rb
+17
-7
No files found.
app/services/projects/import_export/project_tree_restorer.rb
View file @
eb55cb92
...
...
@@ -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
|
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
end
app/services/projects/import_export/relation_factory.rb
View file @
eb55cb92
...
...
@@ -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
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment