Class: IiifPrint::SplitPdfs::DestroyPdfChildWorksService

Inherits:
Object
  • Object
show all
Defined in:
lib/iiif_print/split_pdfs/destroy_pdf_child_works_service.rb

Overview

Encapsulates logic for cleanup when the PDF is destroyed after pdf splitting into child works

Class Method Summary collapse

Class Method Details

.conditionally_destroy_spawned_children_of(file_set:, work:) ⇒ Object

Parameters:

  • file_set (FileSet)

    What is the containing file set for the provided file.

  • work (Hydra::PCDM::Work)

    Parent of the fileset being deleted



10
11
12
13
14
15
16
17
# File 'lib/iiif_print/split_pdfs/destroy_pdf_child_works_service.rb', line 10

def self.conditionally_destroy_spawned_children_of(file_set:, work:)
  child_model = work.try(:iiif_print_config)&.pdf_split_child_model
  return unless child_model
  return unless file_set.class.pdf_mime_types.include?(file_set.mime_type)

  IiifPrint::PendingRelationship.where(parent_id: work.id, file_id: file_set.id).find_each(&:destroy)
  destroy_spawned_children(model: child_model, file_set: file_set, work: work)
end