BigW Consortium Gitlab

Commit 102074c8 by James Lopez

more and more refactoring

parent 7c8359b7
...@@ -16,7 +16,7 @@ module Gitlab ...@@ -16,7 +16,7 @@ module Gitlab
def execute def execute
Gitlab::ImportExport::Importer.import(archive_file: @archive_file, Gitlab::ImportExport::Importer.import(archive_file: @archive_file,
shared: @shared) shared: @shared)
if [restore_version, restore_project_tree, restore_repo, restore_wiki_repo, restore_uploads].all? if check_version! && [project_tree, repo_restorer, wiki_restorer, uploads_restorer].all?(&:restore)
project_tree.project project_tree.project
else else
project_tree.project.destroy if project_tree.project project_tree.project.destroy if project_tree.project
...@@ -26,12 +26,8 @@ module Gitlab ...@@ -26,12 +26,8 @@ module Gitlab
private private
def restore_version def check_version!
Gitlab::ImportExport::VersionRestorer.restore(shared: @shared) Gitlab::ImportExport::VersionChecker.check!(shared: @shared)
end
def restore_project_tree
project_tree.restore
end end
def project_tree def project_tree
...@@ -40,20 +36,20 @@ module Gitlab ...@@ -40,20 +36,20 @@ module Gitlab
namespace_id: @namespace.id) namespace_id: @namespace.id)
end end
def restore_repo def repo_restorer
Gitlab::ImportExport::RepoRestorer.new(path_to_bundle: repo_path, Gitlab::ImportExport::RepoRestorer.new(path_to_bundle: repo_path,
shared: @shared, shared: @shared,
project: project_tree.project).restore project: project_tree.project)
end end
def restore_wiki_repo def wiki_restorer
Gitlab::ImportExport::RepoRestorer.new(path_to_bundle: wiki_repo_path, Gitlab::ImportExport::RepoRestorer.new(path_to_bundle: wiki_repo_path,
shared: @shared, shared: @shared,
project: ProjectWiki.new(project_tree.project)).restore project: ProjectWiki.new(project_tree.project))
end end
def restore_uploads def uploads_restorer
Gitlab::ImportExport::UploadsRestorer.restore(project: project_tree.project, shared: @shared) Gitlab::ImportExport::UploadsRestorer.new(project: project_tree.project, shared: @shared)
end end
def path_with_namespace(project_path) def path_with_namespace(project_path)
......
...@@ -12,32 +12,27 @@ module Gitlab ...@@ -12,32 +12,27 @@ module Gitlab
# This needs to run first, as second call would be from generate_map # This needs to run first, as second call would be from generate_map
# which means project members already exist. # which means project members already exist.
default_project_member ensure_default_member!
@project_member_map = Hash.new do |_, key|
@note_member_list << key
default_project_member
end end
def map
@map ||= generate_map
end end
def default_project_member def default_user_id
@default_project_member ||= @user.id
begin
default_member = ProjectMember.new(default_project_member_hash)
default_member.create!
default_member.user.id
end
end end
def map private
def generate_map
@map ||= @map ||=
begin begin
@exported_members.inject(@project_member_map) do |hash, member| @exported_members.inject(missing_keys_tracking_hash) do |hash, member|
existing_user = User.where(find_project_user_query(member)).first existing_user = User.where(find_project_user_query(member)).first
if existing_user
old_user_id = member['user']['id'] old_user_id = member['user']['id']
add_user_as_team_member(existing_user, member) if existing_user && add_user_as_team_member(existing_user, member).persisted?
hash[old_user_id] = existing_user.id hash[old_user_id] = existing_user.id
end end
hash hash
...@@ -45,21 +40,27 @@ module Gitlab ...@@ -45,21 +40,27 @@ module Gitlab
end end
end end
private def missing_keys_tracking_hash
Hash.new do |_, key|
@note_member_list << key
@user.id
end
end
def ensure_default_member!
ProjectMember.create!(user: @user, access_level: ProjectMember::MASTER, source_id: @project.id, importing: true)
end
def add_user_as_team_member(existing_user, member) def add_user_as_team_member(existing_user, member)
member['user'] = existing_user member['user'] = existing_user
ProjectMember.create!(member_hash(member))
ProjectMember.create(member_hash(member))
end end
def member_hash(member) def member_hash(member)
member.except('id').merge(source_id: @project.id, importing: true) member.except('id').merge(source_id: @project.id, importing: true)
end end
def default_project_member_hash
{ user: @user, access_level: ProjectMember::MASTER, source_id: @project.id, importing: true }
end
def find_project_user_query(member) def find_project_user_query(member)
user_arel[:username].eq(member['user']['username']).or(user_arel[:email].eq(member['user']['email'])) user_arel[:username].eq(member['user']['username']).or(user_arel[:email].eq(member['user']['email']))
end end
......
...@@ -80,12 +80,14 @@ module Gitlab ...@@ -80,12 +80,14 @@ module Gitlab
end end
def create_relation(relation, relation_hash_list) def create_relation(relation, relation_hash_list)
[relation_hash_list].flatten.map do |relation_hash| relation_array = [relation_hash_list].flatten.map do |relation_hash|
Gitlab::ImportExport::RelationFactory.create(relation_sym: relation.to_sym, Gitlab::ImportExport::RelationFactory.create(relation_sym: relation.to_sym,
relation_hash: relation_hash.merge('project_id' => project.id), relation_hash: relation_hash.merge('project_id' => project.id),
members_mapper: members_mapper, members_mapper: members_mapper,
user_admin: @user.is_admin?) user_admin: @user.is_admin?)
end end
relation_hash_list.is_a?(Array) ? relation_array : relation_array.first
end end
end end
end end
......
...@@ -45,7 +45,7 @@ module Gitlab ...@@ -45,7 +45,7 @@ module Gitlab
if user_admin if user_admin
relation_hash['author_id'] = members_map.map[old_author_id] relation_hash['author_id'] = members_map.map[old_author_id]
else else
relation_hash['author_id'] = members_map.default_project_member relation_hash['author_id'] = members_map.default_user_id
end end
author = relation_hash.delete('author') author = relation_hash.delete('author')
......
...@@ -2,10 +2,6 @@ module Gitlab ...@@ -2,10 +2,6 @@ module Gitlab
module ImportExport module ImportExport
class UploadsSaver class UploadsSaver
def self.save(*args)
new(*args).save
end
def initialize(project:, shared:) def initialize(project:, shared:)
@project = project @project = project
@shared = shared @shared = shared
......
module Gitlab module Gitlab
module ImportExport module ImportExport
class VersionRestorer class VersionChecker
def self.restore(*args) def self.restore(*args)
new(*args).restore new(*args).check
end end
def initialize(shared:) def initialize(shared:)
@shared = shared @shared = shared
end end
def restore def check!
version = File.open(version_file, &:readline) version = File.open(version_file, &:readline)
verify_version!(version) verify_version!(version)
rescue => e rescue => e
......
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