diff options
author | James Lopez <james@jameslopez.es> | 2018-06-20 16:45:15 +0300 |
---|---|---|
committer | James Lopez <james@jameslopez.es> | 2018-06-20 16:45:15 +0300 |
commit | 8522173e0ad912c41aaa68f4e01f03ac73cc4514 (patch) | |
tree | 52f90785e2c12eca84cfcd19e7c2e4705cdd224f /lib/gitlab/import_export/relation_factory.rb | |
parent | cc061cd1c664f2003d4c7abb3930834704d2eb9e (diff) |
refactor code once again to fix IID issues
Diffstat (limited to 'lib/gitlab/import_export/relation_factory.rb')
-rw-r--r-- | lib/gitlab/import_export/relation_factory.rb | 32 |
1 files changed, 6 insertions, 26 deletions
diff --git a/lib/gitlab/import_export/relation_factory.rb b/lib/gitlab/import_export/relation_factory.rb index ff3873bc8ed..992e3e708d5 100644 --- a/lib/gitlab/import_export/relation_factory.rb +++ b/lib/gitlab/import_export/relation_factory.rb @@ -257,15 +257,7 @@ module Gitlab end def existing_object - @existing_object ||= - begin - existing_object = find_or_create_object! - - # Done in two steps, as MySQL behaves differently than PostgreSQL using - # the +find_or_create_by+ method and does not return the ID the second time. - existing_object.update!(parsed_relation_hash) - existing_object - end + @existing_object ||= find_or_create_object! end def unknown_service? @@ -275,29 +267,17 @@ module Gitlab def find_or_create_object! # Can't use IDs as validation exists calilng `.group` or `.project` - finder_hash = { project: @project }.tap do |hash| + finder_hash = parsed_relation_hash.tap do |hash| hash[:group] = @project.group if relation_class.attribute_method?('group_id') + hash[:project] = @project hash[:title] = parsed_relation_hash['title'] if parsed_relation_hash['title'] + hash.delete('project_id') end if label? - label = GroupProjectFinder.find_or_new(Label, finder_hash) - parsed_relation_hash.delete('priorities') if label.persisted? - parsed_relation_hash.delete('type') - - label.save! - label + GroupProjectFinder.find_or_new(Label, finder_hash) else - object = GroupProjectFinder.find_or_create(relation_class, finder_hash) - - if milestone? - parsed_relation_hash.delete('group_id') if object.project - parsed_relation_hash.delete('project_id') if object.group - parsed_relation_hash.delete('iid') - parsed_relation_hash.delete('id') - end - - object + GroupProjectFinder.find_or_create(relation_class, finder_hash) end end |