-
Notifications
You must be signed in to change notification settings - Fork 124
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add a rake task to update collection references to collection types
as part of #4696: since we're deprecating our older semi-custom global id syntax, we need to be able to support applications updating their collections. the rake task `hyrax:collections:update_collection_type_global_ids` provides a way to do this, and is a non-destructive if collections all use the standard syntax. note that this task may create substantial load, even if all collections are already up to date; so it shouldn't be run repeatedly.
- Loading branch information
tamsin johnson
committed
Jan 6, 2021
1 parent
ef8c559
commit 97093fe
Showing
3 changed files
with
56 additions
and
3 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
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,18 @@ | ||
# frozen_string_literal: true | ||
namespace :hyrax do | ||
namespace :collections do | ||
desc 'Update CollectionType global id references for Hyrax 3.0.0' | ||
task :update_collection_type_global_ids do | ||
count = Collection.all.each_with_object(0) do |collection, updated_count| | ||
next if collection.collection_type_gid == collection.collection_type.to_global_id | ||
|
||
collection.public_send(:collection_type_gid=, collection.collection_type.to_global_id, force: true) | ||
|
||
collection.save && | ||
updated_count += 1 | ||
end | ||
|
||
puts "Updated #{count} collections." | ||
end | ||
end | ||
end |
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