Skip to content

Instantly share code, notes, and snippets.

@rococodogs
Last active August 13, 2019 16:27
Show Gist options
  • Save rococodogs/ceb253c313ecc6b8bdeaff24c2a75ed9 to your computer and use it in GitHub Desktop.
Save rococodogs/ceb253c313ecc6b8bdeaff24c2a75ed9 to your computer and use it in GitHub Desktop.
a hyrax job to add files that were previously missed

i originally wrote this as a single script to be run as bundle exec rails runner update-files.rb but that required having a terminal window open + connected, so i rewrote it as a job.

in a rails console:

Publication.where(file_set_ids_ssim: nil).each { |pub| UpdateMissingFilesJob.perform_later(pub) }

make sure you restart the sidekiq server after adding the job file and before you run the above enqueuing! otherwise you'll get a gajillion 'missing const' errors

class UpdateMissingFilesJob < ApplicationJob
def perform(publication)
file_ids = publication.identifier.select { |id| id.start_with? 'islandora:', 'newspaper:' }
return if file_ids.empty?
files = file_ids.map { |id| Dir["/mnt/share/ingest-tmp/#{id}/data/files/*"] }.flatten
files.each do |file|
attrs = { remote_files: [{url: "file://#{file}", name: File.basename(file)}] }
env = Hyrax::Actors::Environment.new(publication, Ability.new(User.find_by(email: publication.depositor)), attrs)
Hyrax::CurationConcern.actor.update(env)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment