Commit 4e9b094b authored by James Lopez's avatar James Lopez

refactor finder

parent 825c68e2
...@@ -2,18 +2,22 @@ module Gitlab ...@@ -2,18 +2,22 @@ module Gitlab
module ImportExport module ImportExport
class GroupProjectFinder class GroupProjectFinder
def self.find_or_new(*args) def self.find_or_new(*args)
new(*args).find_or_new Project.transaction do
new(*args).find_or_new
end
end end
def self.find_or_create(*args) def self.find_or_create(*args)
new(*args).find_or_create Project.transaction do
new(*args).find_or_create
end
end end
def initialize(klass, attributes) def initialize(klass, attributes)
@klass = klass @klass = klass
@attributes = attributes @attributes = attributes
@group_id = @attributes['group_id'] @group = @attributes[:group]
@project_id = @attributes['project_id'] @project = @attributes[:project]
end end
def find_or_new def find_or_new
...@@ -27,11 +31,11 @@ module Gitlab ...@@ -27,11 +31,11 @@ module Gitlab
private private
def where_clause def where_clause
@attributes.except('group_id', 'project_id').map do |key, value| @attributes.except(:group, :project).map do |key, value|
project_clause = table[key].eq(value).and(table[:project_id].eq(@project_id)) project_clause = table[key].eq(value).and(table[:project_id].eq(@project.id))
if @group_id if @group
project_clause.or(table[key].eq(value).and(table[:group_id].eq(@group_id))) project_clause.or(table[key].eq(value).and(table[:group_id].eq(@group.id)))
else else
project_clause project_clause
end end
...@@ -43,7 +47,7 @@ module Gitlab ...@@ -43,7 +47,7 @@ module Gitlab
end end
def project_attributes def project_attributes
@attributes.except('group_id').tap do |atts| @attributes.except(:group).tap do |atts|
atts['type'] = 'ProjectLabel' if label? atts['type'] = 'ProjectLabel' if label?
end end
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment