diff options
Diffstat (limited to 'lib/bulk_imports/common/pipelines/uploads_pipeline.rb')
-rw-r--r-- | lib/bulk_imports/common/pipelines/uploads_pipeline.rb | 29 |
1 files changed, 27 insertions, 2 deletions
diff --git a/lib/bulk_imports/common/pipelines/uploads_pipeline.rb b/lib/bulk_imports/common/pipelines/uploads_pipeline.rb index 15e126e1646..49c16209661 100644 --- a/lib/bulk_imports/common/pipelines/uploads_pipeline.rb +++ b/lib/bulk_imports/common/pipelines/uploads_pipeline.rb @@ -8,6 +8,9 @@ module BulkImports include Gitlab::ImportExport::CommandLineUtil FILENAME = 'uploads.tar.gz' + AVATAR_PATTERN = %r{.*\/#{BulkImports::UploadsExportService::AVATAR_PATH}\/(?<identifier>.*)}.freeze + + AvatarLoadingError = Class.new(StandardError) def extract(context) download_service(tmp_dir, context).execute @@ -18,14 +21,18 @@ module BulkImports end def load(context, file_path) - dynamic_path = FileUploader.extract_dynamic_path(file_path) + avatar_path = AVATAR_PATTERN.match(file_path) + + return save_avatar(file_path) if avatar_path + + dynamic_path = file_uploader.extract_dynamic_path(file_path) return unless dynamic_path return if File.directory?(file_path) named_captures = dynamic_path.named_captures.symbolize_keys - UploadService.new(context.portable, File.open(file_path, 'r'), FileUploader, **named_captures).execute + UploadService.new(context.portable, File.open(file_path, 'r'), file_uploader, **named_captures).execute end def after_run(_) @@ -46,6 +53,24 @@ module BulkImports def tmp_dir @tmp_dir ||= Dir.mktmpdir('bulk_imports') end + + def file_uploader + @file_uploader ||= if context.entity.group? + NamespaceFileUploader + else + FileUploader + end + end + + def save_avatar(file_path) + File.open(file_path) do |avatar| + service = context.entity.update_service.new(portable, current_user, avatar: avatar) + + unless service.execute + raise AvatarLoadingError, portable.errors.full_messages.to_sentence + end + end + end end end end |