-
Notifications
You must be signed in to change notification settings - Fork 3
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 #373 from CottageLabs/bug_fix/fix_nesting_of_colle…
…ctions Rake task to fix collection type
- Loading branch information
Showing
1 changed file
with
21 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,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 |