diff options
Diffstat (limited to 'app/services')
-rw-r--r-- | app/services/groups/import_export/export_service.rb | 71 | ||||
-rw-r--r-- | app/services/projects/import_export/export_service.rb | 2 |
2 files changed, 72 insertions, 1 deletions
diff --git a/app/services/groups/import_export/export_service.rb b/app/services/groups/import_export/export_service.rb new file mode 100644 index 00000000000..26886fc67dc --- /dev/null +++ b/app/services/groups/import_export/export_service.rb @@ -0,0 +1,71 @@ +# frozen_string_literal: true + +module Groups + module ImportExport + class ExportService + def initialize(group:, user:, params: {}) + @group = group + @current_user = user + @params = params + @shared = @params[:shared] || Gitlab::ImportExport::Shared.new(@group) + end + + def execute + save! + end + + private + + attr_accessor :shared + + def save! + if savers.all?(&:save) + notify_success + else + cleanup_and_notify_error! + end + end + + def savers + [tree_exporter, file_saver] + end + + def tree_exporter + Gitlab::ImportExport::GroupTreeSaver.new(group: @group, current_user: @current_user, shared: @shared, params: @params) + end + + def file_saver + Gitlab::ImportExport::Saver.new(exportable: @group, shared: @shared) + end + + def cleanup_and_notify_error + FileUtils.rm_rf(shared.export_path) + + notify_error + end + + def cleanup_and_notify_error! + cleanup_and_notify_error + + raise Gitlab::ImportExport::Error.new(shared.errors.to_sentence) + end + + def notify_success + @shared.logger.info( + group_id: @group.id, + group_name: @group.name, + message: 'Group Import/Export: Export succeeded' + ) + end + + def notify_error + @shared.logger.error( + group_id: @group.id, + group_name: @group.name, + error: @shared.errors.join(', '), + message: 'Group Import/Export: Export failed' + ) + end + end + end +end diff --git a/app/services/projects/import_export/export_service.rb b/app/services/projects/import_export/export_service.rb index d3638c57552..8344397f67d 100644 --- a/app/services/projects/import_export/export_service.rb +++ b/app/services/projects/import_export/export_service.rb @@ -24,7 +24,7 @@ module Projects def save_all! if save_exporters - Gitlab::ImportExport::Saver.save(project: project, shared: shared) + Gitlab::ImportExport::Saver.save(exportable: project, shared: shared) notify_success else cleanup_and_notify_error! |