From 658a15786f736fe61a80318661efb1bba0aeace7 Mon Sep 17 00:00:00 2001 From: Kirk Wang Date: Thu, 8 Aug 2024 10:49:03 -0700 Subject: [PATCH] Remove migrate collection thumbnails rake We discovered on staging that we don't actually need this because the collection thumbnails are still presenter after migrating the collection to a collection resource. Hyrax::IndexesThumbnailsDecorator#thumbnail_path will handle the fallback which is why it is working. Ref: - https://github.com/scientist-softserv/palni_palci_knapsack/issues/110 --- ...ons_collection_thumbnails_to_valkyrie.rake | 32 -------------- ..._collection_thumbnails_to_valkyrie_spec.rb | 44 ------------------- 2 files changed, 76 deletions(-) delete mode 100644 lib/tasks/migrate_hyku_commons_collection_thumbnails_to_valkyrie.rake delete mode 100644 spec/tasks/migrate_hyku_commons_collection_thumbnails_to_valkyrie_spec.rb diff --git a/lib/tasks/migrate_hyku_commons_collection_thumbnails_to_valkyrie.rake b/lib/tasks/migrate_hyku_commons_collection_thumbnails_to_valkyrie.rake deleted file mode 100644 index de8a4cd56..000000000 --- a/lib/tasks/migrate_hyku_commons_collection_thumbnails_to_valkyrie.rake +++ /dev/null @@ -1,32 +0,0 @@ -# frozen_string_literal: true - -namespace :hyku do - desc 'migrate Hyku Commons collection thumbnails to Valkyrie' - task migrate_hyku_commons_collection_thumbnails_to_valkyrie: :environment do - in_each_account do - Collection.find_each do |collection| - # get collection solr document's thumbnail_path for each collection - doc = collection.to_solr - original_thumbnail_path = File.join(Rails.public_path, doc['thumbnail_path_ss']) - - next unless File.exist?(original_thumbnail_path) - - # save collection to make it a valkyrie resource - collection.save - collection_resource = Hyrax.query_service.find_by(id: collection.id) - - # make CollectionBrandingInfo object - CollectionBrandingInfo.new( - collection_id: collection_resource.id, - filename: File.basename(original_thumbnail_path), - role: "thumbnail", - alt_txt: "", - target_url: "" - ).save(original_thumbnail_path) - - # update solr document - Hyrax.index_adapter.save(resource: collection_resource) - end - end - end -end diff --git a/spec/tasks/migrate_hyku_commons_collection_thumbnails_to_valkyrie_spec.rb b/spec/tasks/migrate_hyku_commons_collection_thumbnails_to_valkyrie_spec.rb deleted file mode 100644 index 71e9abacb..000000000 --- a/spec/tasks/migrate_hyku_commons_collection_thumbnails_to_valkyrie_spec.rb +++ /dev/null @@ -1,44 +0,0 @@ -# frozen_string_literal: true - -RSpec.describe 'migrate_hyku_commons_collection_thumbnails_to_valkyrie' do - let!(:account) { FactoryBot.create(:account) } - let(:collection) { FactoryBot.create(:collection, title: ['Hyku Commons Collection']) } - let(:thumbnail_path) { File.join('/', 'uploads', 'uploaded_collection_thumbnails', collection.id, "#{collection.id}_card.jpg") } - let(:new_thumbnail_path) { Rails.root.join('public', 'branding', collection.id.to_s, 'thumbnail', "#{collection.id}_card.jpg").to_s } - let(:old_thumbnail_path) { Rails.root.join(File.join('public', thumbnail_path)) } - - before do - Rails.application.load_tasks if Rake::Task.tasks.empty? - FileUtils.mkdir_p(File.dirname(old_thumbnail_path)) - FileUtils.touch(old_thumbnail_path) - allow(Apartment::Tenant).to receive(:switch!).with(account.tenant) { |&block| block&.call } - allow(collection).to receive(:to_solr).and_return({ 'id' => collection.id, 'thumbnail_path_ss' => thumbnail_path }) - allow(Collection).to receive(:find_each).and_yield(collection) - end - - after do - FileUtils.rm_rf(File.dirname(thumbnail_path)) - Collection.destroy_all - end - - it 'migrates the old thumbnail to the branding directory' do - expect(File.exist?(old_thumbnail_path)).to eq true - expect(File.exist?(new_thumbnail_path)).to eq false - run_task('hyku:migrate_hyku_commons_collection_thumbnails_to_valkyrie') - expect(File.exist?(new_thumbnail_path)).to eq true - end - - it 'creates a CollectionBrandingInfo object for the new thumbnail path' do - expect(CollectionBrandingInfo.where(collection_id: collection.id, role: 'thumbnail').count).to eq 0 - run_task('hyku:migrate_hyku_commons_collection_thumbnails_to_valkyrie') - expect(CollectionBrandingInfo.where(collection_id: collection.id, role: 'thumbnail').count).to eq 1 - end - - it 'indexes the new thumbnail path onto the collection resource' do - original_thumbnail_path_ss = collection.to_solr['thumbnail_path_ss'] - expect(original_thumbnail_path_ss).to eq old_thumbnail_path.to_s.gsub(Rails.public_path.to_s, '') - run_task('hyku:migrate_hyku_commons_collection_thumbnails_to_valkyrie') - collection_resource = Hyrax.query_service.find_by(id: collection.id) - expect(collection_resource.to_solr['thumbnail_path_ss']).to eq new_thumbnail_path.to_s.gsub(Rails.public_path.to_s, '') - end -end