Class: BulkImports::ExportService

Inherits:
Object
  • Object
show all
Defined in:
app/services/bulk_imports/export_service.rb

Instance Method Summary collapse

Constructor Details

#initialize(portable:, user:, batched: false) ⇒ ExportService

Returns a new instance of ExportService.

Parameters:

  • portable (Project|Group)

    A project or a group to export.

  • user (User)

    A user performing the export.

  • batched (Boolean) (defaults to: false)

    Whether to export the data in batches.



8
9
10
11
12
# File 'app/services/bulk_imports/export_service.rb', line 8

def initialize(portable:, user:, batched: false)
  @portable = portable
  @current_user = user
  @batched = batched
end

Instance Method Details

#executeObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'app/services/bulk_imports/export_service.rb', line 14

def execute
  validate_user_permissions!

  FileTransfer.config_for(portable).portable_relations.each do |relation|
    RelationExportWorker.perform_async(current_user.id, portable.id, portable.class.name, relation, batched)
  end

  ServiceResponse.success
rescue StandardError => e
  ServiceResponse.error(
    message: e.class,
    http_status: :unprocessable_entity
  )
end