From bc9bedaaa627bfc2bbef7932e5f227cd0a2704b5 Mon Sep 17 00:00:00 2001 From: LaRita Robinson Date: Wed, 6 Mar 2024 15:24:43 -0500 Subject: [PATCH] Rake task for updating collection_type_gid The structure of the stored collection type gid changed in Hyrax 3.0 A rake task is needed to update the collection_type_gid that is stored on the collection as part of the upgrade from Hyrax 2.x process. This references the logic from the rake task that Hyrax has in versons 3 & 4, and updates it to work within Hyku tenants. 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. Functionality for later versions is unknown. --- lib/tasks/collection_type_global_id.rake | 30 ++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 lib/tasks/collection_type_global_id.rake diff --git a/lib/tasks/collection_type_global_id.rake b/lib/tasks/collection_type_global_id.rake new file mode 100644 index 000000000..2268e6e46 --- /dev/null +++ b/lib/tasks/collection_type_global_id.rake @@ -0,0 +1,30 @@ +# 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