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
Léo-Paul Géneau
gitlab-ce
Commits
f0ce83b1
Commit
f0ce83b1
authored
Mar 10, 2016
by
James Lopez
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
modify model creation to use services when they are available
parent
2cc6aaec
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
32 additions
and
13 deletions
+32
-13
app/services/projects/import_export/project_tree_restorer.rb
app/services/projects/import_export/project_tree_restorer.rb
+3
-3
app/services/projects/import_export/relation_factory.rb
app/services/projects/import_export/relation_factory.rb
+29
-10
No files found.
app/services/projects/import_export/project_tree_restorer.rb
View file @
f0ce83b1
...
@@ -14,12 +14,12 @@ module Projects
...
@@ -14,12 +14,12 @@ module Projects
json
=
IO
.
read
(
@path
)
json
=
IO
.
read
(
@path
)
tree_hash
=
ActiveSupport
::
JSON
.
decode
(
json
)
tree_hash
=
ActiveSupport
::
JSON
.
decode
(
json
)
relation_hash
=
{}
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
|
ImportExport
.
project_tree
.
each
do
|
relation
|
next
if
tree_hash
[
relation
.
to_s
].
empty?
next
if
tree_hash
[
relation
.
to_s
].
empty?
relation_hash
[
relation
.
to_s
]
=
create_relation
(
relation
,
tree_hash
[
relation
.
to_s
])
relation_hash
[
relation
.
to_s
]
=
create_relation
(
relation
,
tree_hash
[
relation
.
to_s
])
end
end
project_params
=
tree_hash
.
delete_if
{
|
_key
,
value
|
value
.
is_a?
(
Array
)}
@project
=
::
Projects
::
CreateService
.
new
(
@user
,
project_params
).
execute
@project
.
saved?
@project
.
saved?
end
end
...
@@ -28,7 +28,7 @@ module Projects
...
@@ -28,7 +28,7 @@ module Projects
def
create_relation
(
relation
,
relation_hash_list
)
def
create_relation
(
relation
,
relation_hash_list
)
relation_hash_list
.
map
do
|
relation_hash
|
relation_hash_list
.
map
do
|
relation_hash
|
Projects
::
ImportExport
::
RelationFactory
.
create
(
Projects
::
ImportExport
::
RelationFactory
.
create
(
relation_sym:
relation
,
relation_hash:
relation_hash
)
relation_sym:
relation
,
relation_hash:
relation_hash
,
project:
@project
,
user:
@user
)
end
end
end
end
end
end
...
...
app/services/projects/import_export/relation_factory.rb
View file @
f0ce83b1
module
Projects
module
Projects
module
ImportExport
module
ImportExport
module
RelationFactory
class
RelationFactory
extend
self
OVERRIDES
=
{
snippets: :project_snippets
}
OVERRIDES
=
{
snippets: :project_snippets
}
def
create
(
relation_sym
:,
relation_hash
:)
def
self
.
create
(
*
args
)
relation_sym
=
parse_relation_sym
(
relation_sym
)
new
(
*
args
).
create
klass
=
relation_class
(
relation_sym
)
end
relation_hash
.
delete
(
'id'
)
#screw IDs for now
klass
.
new
(
relation_hash
)
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
end
end
private
private
def
relation_class
(
relation_sym
)
def
init_service_or_class
relation_sym
.
to_s
.
classify
.
constantize
# Attempt service first
relation_service
.
new
(
@project
,
@user
,
@relation_hash
).
execute
rescue
NameError
relation_class
.
new
(
@relation_hash
)
end
def
relation_service
"
#{
@relation_sym
.
to_s
.
classify
}
::CreateService"
.
constantize
end
def
relation_class
@relation_sym
.
to_s
.
classify
.
constantize
end
end
def
parse_relation_sym
(
relation_sym
)
def
parse
d
_relation_sym
(
relation_sym
)
OVERRIDES
[
relation_sym
]
||
relation_sym
OVERRIDES
[
relation_sym
]
||
relation_sym
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