Class: MigrateSipityEntityJob

Inherits:
ApplicationJob
  • Object
show all
Defined in:
app/jobs/migrate_sipity_entity_job.rb

Overview

migrates a resource’s sipity entity so it can be found

Instance Method Summary collapse

Instance Method Details

#perform(id:) ⇒ Object

input [String] id of a migrated resource



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'app/jobs/migrate_sipity_entity_job.rb', line 6

def perform(id:)
  resource = Hyrax.query_service.find_by(id: id)
  new_gid = Hyrax::GlobalID(resource).to_s
  return if Sipity::Entity.find_by(proxy_for_global_id: new_gid)

  work = resource.internal_resource.constantize.find(id)
  original_gid = Hyrax::GlobalID(work).to_s
  return if new_gid == original_gid
  original_entity = Sipity::Entity.find_by(proxy_for_global_id: original_gid)
  return if original_entity.nil?
  original_entity.update(proxy_for_global_id: new_gid)
rescue ActiveFedora::ObjectNotFoundError
  # this happens when the resource was never in Fedora so there is nothing to migrate.
  # We don't want to retry the job so we don't raise an error.
end