-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Migration script for collections (#2310)
* Add rake task to migrate collections Uses lazy migration to migrate all AdminSets & Collections via rake task `migrate_collections` * Set default solr method The default method used for Solr queries. Values are :get or :post. Post is suggested to prevent issues with URL length. config.solr_default_method = :post * Finish Migration job Fixes migrate resources job Adds spec for job * Rubocop fixes
- Loading branch information
Showing
4 changed files
with
74 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,30 @@ | ||
# frozen_string_literal: true | ||
|
||
# migrates models from AF to valkyrie | ||
class MigrateResourcesJob < ApplicationJob | ||
# input [Array>>String] Array of ActiveFedora model names to migrate to valkyrie objects | ||
# defaults to AdminSet & Collection models if empty | ||
def perform(models: []) | ||
models = collection_models_list if models.empty? | ||
|
||
models.each do |model| | ||
model.constantize.find_each do |item| | ||
res = Hyrax.query_service.find_by(id: item.id) | ||
# start with a form for the resource | ||
fm = form_for(model:).constantize.new(resource: res) | ||
# save the form | ||
converted = Hyrax.persister.save(resource: fm) | ||
# reindex | ||
Hyrax.index_adapter.save(resource: converted) | ||
end | ||
end | ||
end | ||
|
||
def form_for(model:) | ||
model.to_s + 'ResourceForm' | ||
end | ||
|
||
def collection_models_list | ||
%w[AdminSet Collection] | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,6 +39,10 @@ | |
# breadcrumbs. | ||
config.file_set_model = 'Hyrax::FileSet' | ||
|
||
# The default method used for Solr queries. Values are :get or :post. | ||
# Post is suggested to prevent issues with URL length. | ||
config.solr_default_method = :post | ||
|
||
# The email address that messages submitted via the contact page are sent to | ||
# This is set by account settings | ||
# config.contact_email = '[email protected]' | ||
|
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,33 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'freyja/persister' | ||
RSpec.describe MigrateResourcesJob, clean: true do | ||
before do | ||
ActiveJob::Base.queue_adapter = :test | ||
FactoryBot.create(:group, name: "public") | ||
end | ||
|
||
after do | ||
clear_enqueued_jobs | ||
end | ||
|
||
let(:account) { create(:account_with_public_schema) } | ||
|
||
let!(:af_admin_set) do | ||
as = AdminSet.new(title: ['AF Admin Set']) | ||
as.save | ||
AdminSet.find(as.id) | ||
end | ||
|
||
describe '#perform' do | ||
it "migrates admin sets to valkyrie", active_fedora_to_valkyrie: true do | ||
expect(Valkyrie::Persistence::Postgres::ORM::Resource.find_by(id: af_admin_set.id.to_s)).to be_nil | ||
|
||
ActiveJob::Base.queue_adapter.perform_enqueued_jobs = true | ||
switch!(account) | ||
MigrateResourcesJob.perform_now | ||
|
||
expect(Valkyrie::Persistence::Postgres::ORM::Resource.find_by(id: af_admin_set.id.to_s)).to be_present | ||
end | ||
end | ||
end |