Skip to content

Commit

Permalink
Merge pull request #373 from CottageLabs/bug_fix/fix_nesting_of_colle…
Browse files Browse the repository at this point in the history
…ctions

Rake task to fix collection type
  • Loading branch information
dfmurphy-wpi authored Nov 9, 2022
2 parents 7801fd2 + 0ca96b1 commit f72fe47
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions lib/tasks/fix_collection_type.rake
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
require 'json'

namespace :wpi do
desc 'Fix collection type to match Hyrax 3. usage: wpi:fix_collection_type'
task fix_collection_type: :environment do
new_collection_type_gid = Hyrax::CollectionType.find_by_title('Nestable Collection').gid
old_collection_type_gid = "gid://digital-wpi/hyrax-collectiontype/1"
errors = {}
Collection.find_each do |collection|
next unless collection.collection_type_gid == old_collection_type_gid
begin
collection.send(:collection_type_gid=, new_collection_type_gid, force: true)
collection.reindex_extent = Hyrax::Adapters::NestingIndexAdapter::LIMITED_REINDEX
collection.save
rescue => e
errors[collection.id] = e.message
end
end
JSON.pretty_generate(errors) if errors
end
end

0 comments on commit f72fe47

Please sign in to comment.