From 10031787ca518458867bb7e51c4b556db3fe6f37 Mon Sep 17 00:00:00 2001 From: Justin Littman Date: Wed, 3 Jul 2024 07:56:32 -0400 Subject: [PATCH] Ignore when item is already unpublished. closes #5114 --- Gemfile.lock | 2 +- .../publish/metadata_transfer_service.rb | 2 ++ .../publish/metadata_transfer_service_spec.rb | 22 ++++++++++++++----- 3 files changed, 19 insertions(+), 7 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 2f728293b..a9ce85c22 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -368,7 +368,7 @@ GEM public_suffix (6.0.0) puma (6.4.2) nio4r (~> 2.0) - purl_fetcher-client (1.5.2) + purl_fetcher-client (1.5.3) activesupport faraday (~> 2.1) racc (1.8.0) diff --git a/app/services/publish/metadata_transfer_service.rb b/app/services/publish/metadata_transfer_service.rb index a5e7d7b4a..cbcff6db2 100644 --- a/app/services/publish/metadata_transfer_service.rb +++ b/app/services/publish/metadata_transfer_service.rb @@ -109,6 +109,8 @@ def release_tags_on_success # def publish_delete_on_success PurlFetcher::Client::Unpublish.unpublish(druid:) + rescue PurlFetcher::Client::AlreadyDeletedResponseError + # It's fine. The object is already deleted. end def publish_shelve diff --git a/spec/services/publish/metadata_transfer_service_spec.rb b/spec/services/publish/metadata_transfer_service_spec.rb index c351852a9..2ef3facc2 100644 --- a/spec/services/publish/metadata_transfer_service_spec.rb +++ b/spec/services/publish/metadata_transfer_service_spec.rb @@ -64,11 +64,14 @@ context 'with no world discover access in rightsMetadata' do let(:purl_root) { Dir.mktmpdir } + let(:druid1) { DruidTools::Druid.new cocina_object.externalIdentifier, purl_root } + before do allow(Settings.stacks).to receive(:local_document_cache_root).and_return(purl_root) allow(PurlFetcher::Client::Unpublish).to receive(:unpublish) - - stub_request(:delete, "example.com/purl/purls/#{druid}") + # create druid tree and dummy content in purl root + druid1.mkdir + File.write(File.join(druid1.path, 'tmpfile'), 'junk') end after do @@ -76,14 +79,21 @@ end it "removes the item's content from the Purl document cache and notifies the purl service of the deletion" do - # create druid tree and dummy content in purl root - druid1 = DruidTools::Druid.new cocina_object.externalIdentifier, purl_root - druid1.mkdir - File.write(File.join(druid1.path, 'tmpfile'), 'junk') service.publish expect(File).not_to exist(druid1.path) # it should now be gone expect(PurlFetcher::Client::Unpublish).to have_received(:unpublish).with(druid: cocina_object.externalIdentifier) end + + context 'when already deleted' do + before do + allow(PurlFetcher::Client::Unpublish).to receive(:unpublish).and_raise(PurlFetcher::Client::AlreadyDeletedResponseError) + end + + it 'ignores the error' do + service.publish + expect(File).not_to exist(druid1.path) # it should now be gone + end + end end describe 'copies to the document cache' do