Commit 14669977 authored by James Lopez's avatar James Lopez 🔴

import uploads. Fixed a few things to do with members, triggers, etc...

parent 92de6309
......@@ -22,6 +22,7 @@ class Member < ActiveRecord::Base
include Gitlab::Access
attr_accessor :raw_invite_token
attr_accessor :importing
belongs_to :created_by, class_name: "User"
belongs_to :user
......@@ -54,10 +55,10 @@ class Member < ActiveRecord::Base
scope :owners, -> { where(access_level: OWNER) }
before_validation :generate_invite_token, on: :create, if: -> (member) { member.invite_email.present? }
after_create :send_invite, if: :invite?
after_create :create_notification_setting, unless: :invite?
after_create :post_create_hook, unless: :invite?
after_update :post_update_hook, unless: :invite?
after_create :send_invite, if: :invite?, unless: :importing
after_create :create_notification_setting, unless: [:invite?, :importing]
after_create :post_create_hook, unless: [:invite?, :importing]
after_update :post_update_hook, unless: [:invite?, :importing]
after_destroy :post_destroy_hook, unless: :invite?
delegate :name, :username, :email, to: :user, prefix: true
......
......@@ -27,5 +27,9 @@ module Gitlab
def version
VERSION
end
def reset_tokens?
true
end
end
end
......@@ -16,7 +16,7 @@ module Gitlab
def execute
Gitlab::ImportExport::Importer.import(archive_file: @archive_file,
shared: @shared)
if [restore_version, restore_project_tree, restore_repo, restore_wiki_repo].all?
if [restore_version, restore_project_tree, restore_repo, restore_wiki_repo, restore_uploads].all?
project_tree.project
else
project_tree.project.destroy if project_tree.project
......@@ -52,6 +52,10 @@ module Gitlab
project: ProjectWiki.new(project_tree.project)).restore
end
def restore_uploads
Gitlab::ImportExport::UploadsRestorer.restore(project: project_tree.project, shared: @shared)
end
def path_with_namespace(project_path)
File.join(@namespace.path, project_path)
end
......
......@@ -50,11 +50,11 @@ module Gitlab
end
def member_hash(member)
member.except('id').merge(source_id: @project.id)
member.except('id').merge(source_id: @project.id, importing: true)
end
def default_project_member_hash
{ user: @user, access_level: ProjectMember::MASTER, source_id: @project.id }
{ user: @user, access_level: ProjectMember::MASTER, source_id: @project.id, importing: true }
end
def find_project_user_query(member)
......
......@@ -12,7 +12,7 @@ module Gitlab
builds: 'Ci::Build',
hooks: 'ProjectHook' }.freeze
USER_REFERENCES = %w(author_id assignee_id updated_by_id).freeze
USER_REFERENCES = %w(author_id assignee_id updated_by_id user_id).freeze
def create(relation_sym:, relation_hash:, members_mapper:, user_admin:)
relation_sym = parse_relation_sym(relation_sym)
......@@ -21,6 +21,7 @@ module Gitlab
update_missing_author(relation_hash, members_mapper, user_admin) if relation_sym == :notes
update_user_references(relation_hash, members_mapper.map)
update_project_references(relation_hash, klass)
reset_tokens(relation_hash) if relation_sym == 'Ci::Trigger'
generate_imported_object(klass, relation_hash, relation_sym)
end
......@@ -88,6 +89,13 @@ module Gitlab
relation_hash['gl_project_id'] = project_id if relation_hash ['gl_project_id']
end
def reset_tokens(relation_hash)
return unless Gitlab::ImportExport.reset_tokens?
# If we import/export a project to the same instance, tokens will have to be reseated.
relation_hash['token'] = nil
end
def relation_class(relation_sym)
relation_sym.to_s.classify.constantize
end
......
module Gitlab
module ImportExport
class UploadsRestorer < UploadsSaver
class << self
alias_method :restore, :save
end
def save
return true unless File.directory?(uploads_export_path)
copy_files(uploads_export_path, uploads_path)
rescue => e
@shared.error(e)
false
end
end
end
end
......@@ -14,21 +14,26 @@ module Gitlab
def save
return true unless File.directory?(uploads_path)
FileUtils.copy_entry(uploads_path, uploads_export_path)
true
copy_files(uploads_path, uploads_export_path)
rescue => e
@shared.error(e.message)
@shared.error(e)
false
end
private
def copy_files(source, destination)
FileUtils.mkdir_p(destination)
FileUtils.copy_entry(source, destination)
true
end
def uploads_export_path
File.join(@shared.export_path, 'uploads')
end
def uploads_path
File.join(Rails.root.join('public/uploads'), project.path_with_namespace)
File.join(Rails.root.join('public/uploads'), @project.path_with_namespace)
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