Skip to content

Commit

Permalink
Ignore when item is already unpublished.
Browse files Browse the repository at this point in the history
closes #5114
  • Loading branch information
justinlittman committed Jul 3, 2024
1 parent 5bc7c45 commit 1003178
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions app/services/publish/metadata_transfer_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
22 changes: 16 additions & 6 deletions spec/services/publish/metadata_transfer_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,26 +64,36 @@
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
FileUtils.remove_entry purl_root
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
Expand Down

0 comments on commit 1003178

Please sign in to comment.