Skip to content

Commit

Permalink
Merge pull request #328 from scientist-softserv/correct-transactions-…
Browse files Browse the repository at this point in the history
…names

🧹 Correct transactions names and set condition
  • Loading branch information
Shana Moore authored Feb 2, 2024
2 parents 7037a9b + 9dec841 commit a74ffef
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,19 @@ class IiifPrintContainerDecorator
namespace 'change_set' do |ops|
ops.register 'update_work' do
steps = Hyrax::Transactions::WorkUpdate::DEFAULT_STEPS.dup
# NOTE: applications that don't want the file splitting of IIIF Print will want to remove
# this step from their transactions.
steps.insert(steps.index('work_resource.update_work_members') + 1, 'work_resource.set_child_flag')
Hyrax::Transactions::WorkUpdate.new(steps: steps)
end
end

if defined?(Bulkrax::Container)
if defined?(Bulkrax::Transactions::Container)
namespace 'work_resource' do |ops|
ops.register Bulkrax::Container::UPDATE_WITH_BULK_BEHAVIOR do
steps = Bulkrax::Container::UPDATE_WITH_BULK_BEHAVIOR_STEPS.dup
ops.register Bulkrax::Transactions::Container::UPDATE_WITH_BULK_BEHAVIOR do
steps = Bulkrax::Transactions::Container::UPDATE_WITH_BULK_BEHAVIOR_STEPS.dup
# NOTE: applications that don't want the file splitting of IIIF Print will want to remove
# this step from their transactions.
steps.insert(steps.index('work_resource.update_work_members') + 1, 'work_resource.set_child_flag')
Hyrax::Transactions::WorkUpdate.new(steps: steps)
end
Expand Down
6 changes: 6 additions & 0 deletions app/transactions/hyrax/transactions/steps/set_child_flag.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,18 @@ module Steps
class SetChildFlag
include Dry::Monads[:result]

# @see IiifPrint.model_configuration
def call(resource)
return Failure(:resource_not_persisted) unless resource.persisted?

user = ::User.find_by_user_key(resource.depositor)

Hyrax.custom_queries.find_child_works(resource: resource).each do |child_work|
# not all child works might have the is_child property that we define when we configure
# the a model for iiif_print. see IiifPrint.model_configuration
#
# Put another the existence of the is_child property is optional.
next unless child_work.respond_to?(:is_child)
next if child_work.is_child
child_work.is_child = true
Hyrax.persister.save(resource: child_work)
Expand Down

0 comments on commit a74ffef

Please sign in to comment.