Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🎁 Service to split previously ingested pdf #292

Closed
wants to merge 3 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions lib/iiif_print/split_pdfs/pdf_child_works_service.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# frozen_string_literal: true

module IiifPrint
module SplitPdfs
## Encapsulates logic for cleanup when the PDF is destroyed after pdf splitting into child works
class PdfChildWorksService
def self.create_pdf_child_works_for(file_set:, user:)
locations = pdfs_only_for([Hyrax::WorkingDirectory.find_or_retrieve(file.id, file_set.id)])
return if locations.empty?
work = file_set.parent
laritakr marked this conversation as resolved.
Show resolved Hide resolved

# clean up any existing spawned child works of this file_set
IiifPrint::SplitPdfs::DestroyPdfChildWorksService.conditionally_destroy_spawned_children_of(
file_set: file_set,
work: work
)

# submit a job to split pdf into child works
work.iiif_print_config.pdf_splitter_job.perform_later(
file_set,
locations,
user,
work.admin_set_id,
0 # A no longer used parameter; but we need to preserve the method signature (for now)
)
end

# @todo: can we use mimetype instead?
def self.pdfs_only_for(paths)
paths.select { |path| path.end_with?('.pdf', '.PDF') }
end
end
end
end
Loading