Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rake task for updating collection_type_gid #982

Merged
merged 1 commit into from
Mar 6, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions lib/tasks/collection_type_global_id.rake
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# frozen_string_literal: true

namespace :hyrax do
namespace :collections do
desc 'Update CollectionType global id references for Hyrax 3.0.0'
# Note: the definition of collection_type_gid= changed in Hyrax 5.0. This
# rake task is known to work for updates to versions prior to Hyrax 5.
# Use for later versions is unknown.
task update_collection_type_global_ids: :environment do
Account.find_each do |account|
next if account.search_only.eql? true

puts "🎪🎪 Updating collection -> collection type GlobalId references within '#{account.name}' tenant"
AccountElevator.switch!(account.cname)

count = 0

Collection.find_each do |collection|
next if collection.collection_type_gid == collection.collection_type.to_global_id.to_s

collection.public_send(:collection_type_gid=, collection.collection_type.to_global_id, force: true)

collection.save &&
count += 1
end

puts "💯💯 Updated #{count} collections within '#{account.name}' tenant"
end
end
end
end
Loading