-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #982 from scientist-softserv/i783-missing-subcolle…
…ction-options Rake task for updating collection_type_gid
- Loading branch information
Showing
1 changed file
with
31 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |