Skip to content

Commit

Permalink
Merge pull request #385 from notch8/more-fixes-for-resplit
Browse files Browse the repository at this point in the history
Fixes for resplit
  • Loading branch information
laritakr authored Feb 7, 2025
2 parents b27b0d6 + 621fdb3 commit 3457b84
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
3 changes: 2 additions & 1 deletion app/jobs/iiif_print/jobs/child_works_from_pdf_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ def perform(id, pdf_paths, user, admin_set_id, *)
# rubocop:disable Metrics/MethodLength
def split_pdf(original_pdf_path, user, child_model, pdf_file_set)
user = User.find_by_user_key(user) unless user.is_a?(User)
image_files = @parent_work.iiif_print_config.pdf_splitter_service.call(original_pdf_path)
# split the pdf into individual pages; pdf_file_set needed for derivative rodeo splitter
image_files = @parent_work.iiif_print_config.pdf_splitter_service.call(original_pdf_path, file_set: pdf_file_set)

# give as much info as possible if we don't have image files to work with.
if image_files.blank?
Expand Down
13 changes: 11 additions & 2 deletions lib/iiif_print/persistence_layer/valkyrie_adapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def self.solr_name(field_name)
# Building a custom query to find these child works directly via the attribute would be more efficient.
# However, it would require more effort for a lesser-used feature, and would not allow for the fallback
# of finding child works by title.
# rubocop:disable Lint/UnusedMethodArgument
# rubocop:disable Lint/UnusedMethodArgument, Metrics/AbcSize, Metrics/MethodLength
def self.destroy_children_split_from(file_set:, work:, model:, user:)
all_child_works = Hyrax.custom_queries.find_child_works(resource: work)
return if all_child_works.blank?
Expand All @@ -97,14 +97,23 @@ def self.destroy_children_split_from(file_set:, work:, model:, user:)
children = all_child_works.select { |m| m.title.include?(file_set.label) && m.title.include?(work.to_param) }
end
return if children.blank?
# we have to update the work's members first, then delete the children
# otherwise Hyrax tries to save the parent as each child is deleted, resulting
# in failing jobs
remaining_members = work.member_ids - children.map(&:id)
work.member_ids = remaining_members
Hyrax.persister.save(resource: work)
Hyrax.index_adapter.save(resource: work)
Hyrax.publisher.publish('object.membership.updated', object: work, user: user)

children.each do |rcd|
Hyrax.persister.delete(resource: rcd)
Hyrax.index_adapter.delete(resource: rcd)
Hyrax.publisher.publish('object.deleted', object: rcd, user: user)
end
true
end
# rubocop:enable Lint/UnusedMethodArgument
# rubocop:enable Lint/UnusedMethodArgument, Metrics/AbcSize, Metrics/MethodLength

def self.pdf?(file_set)
file_set.original_file&.pdf?
Expand Down

0 comments on commit 3457b84

Please sign in to comment.