Skip to content

Commit fddb867

Browse files
author
Kirk Wang
committed
🧹 Make DeleteJob work wth new class method .find
The DeleteJob previously was not working with the old factory#find method because when it is doing a delete action, the parsed_metadata does not get generated like during a regular import. Because of this, the #search_by_identifier method fails to find anything because we don't have a `work_identifier` field which would have came from the parsed_metadata. So instead, we are using the new class method .find which will take an id (which we find on the raw_metadata) to find the object. We make sure to reindex and publish the action to any relevant listeners.
1 parent e9a527b commit fddb867

File tree

2 files changed

+21
-9
lines changed

2 files changed

+21
-9
lines changed

‎app/jobs/bulkrax/delete_job.rb

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,16 @@ class DeleteJob < ApplicationJob
55
queue_as :import
66

77
def perform(entry, importer_run)
8-
obj = entry.factory.find
9-
obj&.delete
8+
obj = entry.factory.class.find(entry.raw_metadata["id"])
9+
10+
if defined?(Valkyrie) && obj.class < Valkyrie::Resource
11+
Hyrax.persister.delete(resource: obj)
12+
Hyrax.index_adapter.delete(resource: obj)
13+
Hyrax.publisher.publish('object.deleted', object: obj, user: importer_run.importer.user)
14+
else
15+
obj&.delete
16+
end
17+
1018
# rubocop:disable Rails/SkipsModelValidations
1119
ImporterRun.increment_counter(:deleted_records, importer_run.id)
1220
ImporterRun.decrement_counter(:enqueued_records, importer_run.id)

‎spec/jobs/bulkrax/delete_work_job_spec.rb

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,19 @@ module Bulkrax
77
subject(:delete_work_job) { described_class.new }
88
let(:entry) { create(:bulkrax_entry) }
99
let(:importer_run) { create(:bulkrax_importer_run) }
10+
let(:factory) do
11+
Bulkrax::ObjectFactory.new(attributes: {},
12+
source_identifier_value: '123',
13+
work_identifier: :source,
14+
work_identifier_search_field: :source_identifier)
15+
end
1016

1117
describe 'successful job object removed' do
1218
before do
1319
work = instance_double("Work")
14-
factory = instance_double("Bulkrax::ObjectFactory")
15-
expect(work).to receive(:delete).and_return true
16-
expect(factory).to receive(:find).and_return(work)
17-
expect(entry).to receive(:factory).and_return(factory)
20+
allow(work).to receive(:delete).and_return true
21+
allow(factory.class).to receive(:find).and_return(work)
22+
allow(entry).to receive(:factory).and_return(factory)
1823
end
1924

2025
it 'increments :deleted_records' do
@@ -31,9 +36,8 @@ module Bulkrax
3136

3237
describe 'successful job object not found' do
3338
before do
34-
factory = instance_double("Bulkrax::ObjectFactory")
35-
expect(factory).to receive(:find).and_return(nil)
36-
expect(entry).to receive(:factory).and_return(factory)
39+
allow(factory.class).to receive(:find).and_return(nil)
40+
allow(entry).to receive(:factory).and_return(factory)
3741
end
3842

3943
it 'increments :deleted_records' do

0 commit comments

Comments
 (0)