Class: Import::BulkImports::RemoveExportUploadsService

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

Overview

When a group or project is deleted, database-level ‘ON DELETE CASCADE` then removes all records in the hierarchy down to and including BulkImports::ExportUpload. There is no FK relation between ExportUpload and Upload records, so those must be cleaned up at the code level. We can leave the other records (BulkImport::*) intact, as they will be removed by the FK cascade.

Instance Method Summary collapse

Constructor Details

#initialize(portable) ⇒ RemoveExportUploadsService

Returns a new instance of RemoveExportUploadsService.

Parameters:



13
14
15
# File 'app/services/import/bulk_imports/remove_export_uploads_service.rb', line 13

def initialize(portable)
  @portable = portable
end

Instance Method Details

#executeObject



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'app/services/import/bulk_imports/remove_export_uploads_service.rb', line 17

def execute
  exports.each do |export|
    next if export.upload.nil?

    # As `BulkImports::Export` and `BulkImports::ExportUpload` will be
    # removed by the foreign key cascade, we can't rely on them still
    # existing by the time this job executes. Consequently, we find and
    # pass each upload ID.
    export.upload.uploads.each do |upload|
      ::Import::BulkImports::RemoveExportUploadWorker.perform_async(upload.id)
    end
  end

  ServiceResponse.success
end