From 377c96d30223376931b0adb0df41e46f96c64a4d Mon Sep 17 00:00:00 2001 From: Kirk Wang Date: Thu, 1 Feb 2024 16:16:47 -0800 Subject: [PATCH 1/2] =?UTF-8?q?=F0=9F=A7=B9=20Correct=20transactions=20nam?= =?UTF-8?q?es=20and=20set=20condition?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This commit will fix names since it changed somewhere along the way. The set child flag was being called when IIIF Print was not being used which resulted in an error. This commit will set the condition to only call if the HYKU_IIIF_PRINT env var is true. --- .../iiif_print_container_decorator.rb | 34 ++++++++++--------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/app/transactions/hyrax/transactions/iiif_print_container_decorator.rb b/app/transactions/hyrax/transactions/iiif_print_container_decorator.rb index 18a9999a..c7492606 100644 --- a/app/transactions/hyrax/transactions/iiif_print_container_decorator.rb +++ b/app/transactions/hyrax/transactions/iiif_print_container_decorator.rb @@ -28,27 +28,29 @@ class IiifPrintContainerDecorator end end - namespace 'change_set' do |ops| - ops.register 'update_work' do - steps = Hyrax::Transactions::WorkUpdate::DEFAULT_STEPS.dup - 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) - namespace 'work_resource' do |ops| - ops.register Bulkrax::Container::UPDATE_WITH_BULK_BEHAVIOR do - steps = Bulkrax::Container::UPDATE_WITH_BULK_BEHAVIOR_STEPS.dup + if ENV['HYKU_IIIF_PRINT'] + namespace 'change_set' do |ops| + ops.register 'update_work' do + steps = Hyrax::Transactions::WorkUpdate::DEFAULT_STEPS.dup steps.insert(steps.index('work_resource.update_work_members') + 1, 'work_resource.set_child_flag') Hyrax::Transactions::WorkUpdate.new(steps: steps) end end - end - namespace 'work_resource' do |ops| - ops.register 'set_child_flag' do - Steps::SetChildFlag.new + if defined?(Bulkrax::Transactions::Container) + namespace 'work_resource' do |ops| + ops.register Bulkrax::Transactions::Container::UPDATE_WITH_BULK_BEHAVIOR do + steps = Bulkrax::Transactions::Container::UPDATE_WITH_BULK_BEHAVIOR_STEPS.dup + steps.insert(steps.index('work_resource.update_work_members') + 1, 'work_resource.set_child_flag') + Hyrax::Transactions::WorkUpdate.new(steps: steps) + end + end + end + + namespace 'work_resource' do |ops| + ops.register 'set_child_flag' do + Steps::SetChildFlag.new + end end end end From 9dec8418c879cf5f9346e4105ae221bdd9946902 Mon Sep 17 00:00:00 2001 From: Jeremy Friesen Date: Fri, 2 Feb 2024 11:26:39 -0500 Subject: [PATCH 2/2] =?UTF-8?q?=F0=9F=A7=B9=20Remove=20`ENV['HYKU=5FIIIF?= =?UTF-8?q?=5FPRINT']`=20conditional?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The knowledge of why we do or don't have `HYKU_IIIF_PRINT` is a bit odd. I'm not excited to have an `ENV` from Hyku show up here; especially an `ENV` that only partially removes the full functionality of IIIF Print. What I'm wondering is if we should have Hyku decorate the work_resource.set_child_flag to account for it's implementation foibles relative to how Hyku is using the HYKU_IIIF_PRINT. Put another, when we see this variable, my read is HYKU_IIIF_PRINT == false means don't do anything IIIF Print related. But that is not what it means in Hyku, thus we should limit the knowledge/foibles of that ENV to Hyku only. --- .../iiif_print_container_decorator.rb | 38 ++++++++++--------- .../transactions/steps/set_child_flag.rb | 6 +++ 2 files changed, 26 insertions(+), 18 deletions(-) diff --git a/app/transactions/hyrax/transactions/iiif_print_container_decorator.rb b/app/transactions/hyrax/transactions/iiif_print_container_decorator.rb index c7492606..09ff253e 100644 --- a/app/transactions/hyrax/transactions/iiif_print_container_decorator.rb +++ b/app/transactions/hyrax/transactions/iiif_print_container_decorator.rb @@ -28,29 +28,31 @@ class IiifPrintContainerDecorator end end - if ENV['HYKU_IIIF_PRINT'] - namespace 'change_set' do |ops| - ops.register 'update_work' do - steps = Hyrax::Transactions::WorkUpdate::DEFAULT_STEPS.dup - steps.insert(steps.index('work_resource.update_work_members') + 1, 'work_resource.set_child_flag') - Hyrax::Transactions::WorkUpdate.new(steps: steps) - end + 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::Transactions::Container) - namespace 'work_resource' do |ops| - ops.register Bulkrax::Transactions::Container::UPDATE_WITH_BULK_BEHAVIOR do - steps = Bulkrax::Transactions::Container::UPDATE_WITH_BULK_BEHAVIOR_STEPS.dup - steps.insert(steps.index('work_resource.update_work_members') + 1, 'work_resource.set_child_flag') - Hyrax::Transactions::WorkUpdate.new(steps: steps) - end + if defined?(Bulkrax::Transactions::Container) + namespace 'work_resource' do |ops| + 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 end + end - namespace 'work_resource' do |ops| - ops.register 'set_child_flag' do - Steps::SetChildFlag.new - end + namespace 'work_resource' do |ops| + ops.register 'set_child_flag' do + Steps::SetChildFlag.new end end end diff --git a/app/transactions/hyrax/transactions/steps/set_child_flag.rb b/app/transactions/hyrax/transactions/steps/set_child_flag.rb index c4851e52..89d85272 100644 --- a/app/transactions/hyrax/transactions/steps/set_child_flag.rb +++ b/app/transactions/hyrax/transactions/steps/set_child_flag.rb @@ -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)