From fb94bd5ac998cf6656574d442be281c009df6949 Mon Sep 17 00:00:00 2001 From: Shana Moore Date: Thu, 30 May 2024 14:10:58 -0700 Subject: [PATCH 1/5] :bug: Correct thumbnail_path_ss value --- app/forms/hyrax/forms/pcdm_collection_form_decorator.rb | 2 +- app/indexers/collection_resource_indexer.rb | 1 + app/services/hyrax/indexes_thumbnails_decorator.rb | 3 ++- ...migrate_hyku_commons_collection_thumbnails_to_valkyrie.rake | 2 +- 4 files changed, 5 insertions(+), 3 deletions(-) diff --git a/app/forms/hyrax/forms/pcdm_collection_form_decorator.rb b/app/forms/hyrax/forms/pcdm_collection_form_decorator.rb index ee5e377533..a239b7b879 100644 --- a/app/forms/hyrax/forms/pcdm_collection_form_decorator.rb +++ b/app/forms/hyrax/forms/pcdm_collection_form_decorator.rb @@ -12,7 +12,7 @@ if thumbnail_info thumbnail_file = File.split(thumbnail_info.local_path).last alttext = thumbnail_info.alt_text - file_location = thumbnail_info.local_path + file_location = thumbnail_info.local_path.gsub('/app/samvera', '') relative_path = "/" + thumbnail_info.local_path.split("/")[-4..-1].join("/") { file: thumbnail_file, full_path: file_location, relative_path:, alttext: } else diff --git a/app/indexers/collection_resource_indexer.rb b/app/indexers/collection_resource_indexer.rb index fe2113e259..c5af47560c 100644 --- a/app/indexers/collection_resource_indexer.rb +++ b/app/indexers/collection_resource_indexer.rb @@ -6,6 +6,7 @@ class CollectionResourceIndexer < Hyrax::Indexers::PcdmCollectionIndexer include Hyrax::Indexer(:basic_metadata) include Hyrax::Indexer(:bulkrax_metadata) include Hyrax::Indexer(:collection_resource) + include Hyrax::IndexesThumbnails def to_solr super.tap do |index_document| diff --git a/app/services/hyrax/indexes_thumbnails_decorator.rb b/app/services/hyrax/indexes_thumbnails_decorator.rb index 6620d5f979..d639830483 100644 --- a/app/services/hyrax/indexes_thumbnails_decorator.rb +++ b/app/services/hyrax/indexes_thumbnails_decorator.rb @@ -6,10 +6,11 @@ module Hyrax module IndexesThumbnailsDecorator # Returns the value for the thumbnail path to put into the solr document def thumbnail_path + object ||= @object || resource if object.try(:collection?) && UploadedCollectionThumbnailPathService.uploaded_thumbnail?(object) UploadedCollectionThumbnailPathService.call(object) else - super + CollectionResourceIndexer.thumbnail_path_service.call(object).gsub('/app/samvera', '') end end end diff --git a/lib/tasks/migrate_hyku_commons_collection_thumbnails_to_valkyrie.rake b/lib/tasks/migrate_hyku_commons_collection_thumbnails_to_valkyrie.rake index de8a4cd56a..af97805142 100644 --- a/lib/tasks/migrate_hyku_commons_collection_thumbnails_to_valkyrie.rake +++ b/lib/tasks/migrate_hyku_commons_collection_thumbnails_to_valkyrie.rake @@ -7,7 +7,7 @@ namespace :hyku 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']) + original_thumbnail_path = File.join('public/branding/', doc['thumbnail_path_ss']) next unless File.exist?(original_thumbnail_path) From 24de07c37a3e2515c3688da81de7b1de990f9c02 Mon Sep 17 00:00:00 2001 From: Shana Moore Date: Thu, 30 May 2024 18:04:52 -0700 Subject: [PATCH 2/5] Guard against nil --- app/services/hyrax/indexes_thumbnails_decorator.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/services/hyrax/indexes_thumbnails_decorator.rb b/app/services/hyrax/indexes_thumbnails_decorator.rb index d639830483..8a0be63064 100644 --- a/app/services/hyrax/indexes_thumbnails_decorator.rb +++ b/app/services/hyrax/indexes_thumbnails_decorator.rb @@ -10,7 +10,7 @@ def thumbnail_path if object.try(:collection?) && UploadedCollectionThumbnailPathService.uploaded_thumbnail?(object) UploadedCollectionThumbnailPathService.call(object) else - CollectionResourceIndexer.thumbnail_path_service.call(object).gsub('/app/samvera', '') + CollectionResourceIndexer.thumbnail_path_service.call(object)&.gsub('/app/samvera', '') end end end From bfacef03525e046331b42542875398f49f80506a Mon Sep 17 00:00:00 2001 From: Shana Moore Date: Thu, 30 May 2024 18:17:46 -0700 Subject: [PATCH 3/5] =?UTF-8?q?=F0=9F=A7=B9=20discards=20any=20prefixes=20?= =?UTF-8?q?before=20/branding?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/forms/hyrax/forms/pcdm_collection_form_decorator.rb | 2 +- app/services/hyrax/indexes_thumbnails_decorator.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/forms/hyrax/forms/pcdm_collection_form_decorator.rb b/app/forms/hyrax/forms/pcdm_collection_form_decorator.rb index a239b7b879..803e9a22f8 100644 --- a/app/forms/hyrax/forms/pcdm_collection_form_decorator.rb +++ b/app/forms/hyrax/forms/pcdm_collection_form_decorator.rb @@ -12,7 +12,7 @@ if thumbnail_info thumbnail_file = File.split(thumbnail_info.local_path).last alttext = thumbnail_info.alt_text - file_location = thumbnail_info.local_path.gsub('/app/samvera', '') + file_location = thumbnail_info.local_path.gsub(/.*?(\/branding)/, '\1') relative_path = "/" + thumbnail_info.local_path.split("/")[-4..-1].join("/") { file: thumbnail_file, full_path: file_location, relative_path:, alttext: } else diff --git a/app/services/hyrax/indexes_thumbnails_decorator.rb b/app/services/hyrax/indexes_thumbnails_decorator.rb index 8a0be63064..40e0476105 100644 --- a/app/services/hyrax/indexes_thumbnails_decorator.rb +++ b/app/services/hyrax/indexes_thumbnails_decorator.rb @@ -10,7 +10,7 @@ def thumbnail_path if object.try(:collection?) && UploadedCollectionThumbnailPathService.uploaded_thumbnail?(object) UploadedCollectionThumbnailPathService.call(object) else - CollectionResourceIndexer.thumbnail_path_service.call(object)&.gsub('/app/samvera', '') + CollectionResourceIndexer.thumbnail_path_service.call(object)&.gsub(/.*?(\/branding)/, '\1') end end end From 233e4f63cb6f8af79e099edf35338ade3da67606 Mon Sep 17 00:00:00 2001 From: Shana Moore Date: Fri, 31 May 2024 11:45:55 -0700 Subject: [PATCH 4/5] revert changes --- app/forms/hyrax/forms/pcdm_collection_form_decorator.rb | 2 +- app/services/hyrax/indexes_thumbnails_decorator.rb | 5 ++++- ...grate_hyku_commons_collection_thumbnails_to_valkyrie.rake | 2 +- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/app/forms/hyrax/forms/pcdm_collection_form_decorator.rb b/app/forms/hyrax/forms/pcdm_collection_form_decorator.rb index 803e9a22f8..ee5e377533 100644 --- a/app/forms/hyrax/forms/pcdm_collection_form_decorator.rb +++ b/app/forms/hyrax/forms/pcdm_collection_form_decorator.rb @@ -12,7 +12,7 @@ if thumbnail_info thumbnail_file = File.split(thumbnail_info.local_path).last alttext = thumbnail_info.alt_text - file_location = thumbnail_info.local_path.gsub(/.*?(\/branding)/, '\1') + file_location = thumbnail_info.local_path relative_path = "/" + thumbnail_info.local_path.split("/")[-4..-1].join("/") { file: thumbnail_file, full_path: file_location, relative_path:, alttext: } else diff --git a/app/services/hyrax/indexes_thumbnails_decorator.rb b/app/services/hyrax/indexes_thumbnails_decorator.rb index 40e0476105..d90e9cca9a 100644 --- a/app/services/hyrax/indexes_thumbnails_decorator.rb +++ b/app/services/hyrax/indexes_thumbnails_decorator.rb @@ -7,10 +7,13 @@ module IndexesThumbnailsDecorator # Returns the value for the thumbnail path to put into the solr document def thumbnail_path object ||= @object || resource + file_path = CollectionResourceIndexer.thumbnail_path_service.call(object) if object.try(:collection?) && UploadedCollectionThumbnailPathService.uploaded_thumbnail?(object) UploadedCollectionThumbnailPathService.call(object) + elsif file_path.include?('/branding') + file_path.gsub(/.*?(\/branding)/, '\1') else - CollectionResourceIndexer.thumbnail_path_service.call(object)&.gsub(/.*?(\/branding)/, '\1') + super end end end diff --git a/lib/tasks/migrate_hyku_commons_collection_thumbnails_to_valkyrie.rake b/lib/tasks/migrate_hyku_commons_collection_thumbnails_to_valkyrie.rake index af97805142..de8a4cd56a 100644 --- a/lib/tasks/migrate_hyku_commons_collection_thumbnails_to_valkyrie.rake +++ b/lib/tasks/migrate_hyku_commons_collection_thumbnails_to_valkyrie.rake @@ -7,7 +7,7 @@ namespace :hyku 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('public/branding/', doc['thumbnail_path_ss']) + original_thumbnail_path = File.join(Rails.public_path, doc['thumbnail_path_ss']) next unless File.exist?(original_thumbnail_path) From ddd1655a39f4e5b64b3a9f3ba5f8179c964a81ed Mon Sep 17 00:00:00 2001 From: Shana Moore Date: Fri, 31 May 2024 13:10:04 -0700 Subject: [PATCH 5/5] Update indexes_thumbnails_decorator.rb --- app/services/hyrax/indexes_thumbnails_decorator.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/services/hyrax/indexes_thumbnails_decorator.rb b/app/services/hyrax/indexes_thumbnails_decorator.rb index d90e9cca9a..25225bb12a 100644 --- a/app/services/hyrax/indexes_thumbnails_decorator.rb +++ b/app/services/hyrax/indexes_thumbnails_decorator.rb @@ -10,10 +10,10 @@ def thumbnail_path file_path = CollectionResourceIndexer.thumbnail_path_service.call(object) if object.try(:collection?) && UploadedCollectionThumbnailPathService.uploaded_thumbnail?(object) UploadedCollectionThumbnailPathService.call(object) - elsif file_path.include?('/branding') + elsif file_path&.include?('/branding') file_path.gsub(/.*?(\/branding)/, '\1') else - super + file_path end end end