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:, user: nil) ⇒ 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
18
19
# File 'lib/iiif_print/split_pdfs/destroy_pdf_child_works_service.rb', line 10

def self.conditionally_destroy_spawned_children_of(file_set:, work:, user: nil)
  child_model = work.try(:iiif_print_config)&.pdf_split_child_model
  return unless child_model
  return unless IiifPrint.pdf?(file_set)

  # NOTE: The IiifPrint::PendingRelationship is an ActiveRecord object; hence we don't need to
  # leverage an adapter.
  IiifPrint::PendingRelationship.where(parent_id: work.id, file_id: file_set.id).find_each(&:destroy)
  IiifPrint.destroy_children_split_from(file_set: file_set, work: work, model: child_model, user: user)
end