Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
李少辉-开发者
gitlab-foss
提交
eb55cb92
G
gitlab-foss
项目概览
李少辉-开发者
/
gitlab-foss
通知
15
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
G
gitlab-foss
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
eb55cb92
编写于
4月 12, 2016
作者:
J
James Lopez
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
more refactoring
上级
4ffcd427
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
27 addition
and
32 deletion
+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
未找到文件。
app/services/projects/import_export/project_tree_restorer.rb
浏览文件 @
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
|
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
app/services/projects/import_export/relation_factory.rb
浏览文件 @
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
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录