diff --git a/app/controllers/sites_controller.rb b/app/controllers/sites_controller.rb index 5dc8efe6b..6df161fb8 100644 --- a/app/controllers/sites_controller.rb +++ b/app/controllers/sites_controller.rb @@ -7,7 +7,20 @@ class SitesController < ApplicationController def update # FIXME: Pull these strings out to i18n locale - if @site.update(update_params) + if @site.update(update_params) + + # If updating work or collection default image, works and/or collections should be reindexed + # as they are when the default image is added. See AppearancesControllerDecorator#update + if update_params['remove_default_collection_image'] + # Reindex all Collections and AdminSets to apply new default collection image + ReindexCollectionsJob.perform_later + ReindexAdminSetsJob.perform_later + end + + if update_params['remove_default_work_image'] + # Reindex all Works to apply new default work image + ReindexWorksJob.perform_later + end remove_appearance_text(update_params) redirect_to hyrax.admin_appearance_path, notice: 'The appearance was successfully updated.' else diff --git a/app/jobs/reindex_admin_sets_job.rb b/app/jobs/reindex_admin_sets_job.rb index c1a68e4b9..2aa8418c1 100644 --- a/app/jobs/reindex_admin_sets_job.rb +++ b/app/jobs/reindex_admin_sets_job.rb @@ -2,6 +2,17 @@ class ReindexAdminSetsJob < ApplicationJob def perform - AdminSet.find_each(&:update_index) + models = Hyrax::ModelRegistry.admin_set_classes + unique_models = [] + models.each do |model| + unique_models << Wings::ModelRegistry.lookup(model) + end + + unique_models.uniq.each do |model| + admin_sets = Hyrax.query_service.find_all_of_model(model: model) + admin_sets.each do |as| + ReindexItemJob.perform_later(as.id.to_s) + end + end end end diff --git a/app/jobs/reindex_collections_job.rb b/app/jobs/reindex_collections_job.rb index 422d1c8de..42fb3fbd4 100644 --- a/app/jobs/reindex_collections_job.rb +++ b/app/jobs/reindex_collections_job.rb @@ -2,8 +2,17 @@ class ReindexCollectionsJob < ApplicationJob def perform - Collection.find_each do |collection| - ReindexItemJob.perform_later(collection) + models = Hyrax::ModelRegistry.collection_classes + unique_models = [] + models.each do |model| + unique_models << Wings::ModelRegistry.lookup(model) + end + + unique_models.uniq.each do |model| + collections = Hyrax.query_service.find_all_of_model(model: model) + collections.each do |coll| + ReindexItemJob.perform_later(coll.id.to_s) + end end end end diff --git a/app/jobs/reindex_file_sets_job.rb b/app/jobs/reindex_file_sets_job.rb index 0e2e7931d..c179e9187 100644 --- a/app/jobs/reindex_file_sets_job.rb +++ b/app/jobs/reindex_file_sets_job.rb @@ -2,8 +2,17 @@ class ReindexFileSetsJob < ApplicationJob def perform - FileSet.find_each do |file_set| - ReindexItemJob.perform_later(file_set) + models = Hyrax::ModelRegistry.file_set_classes + unique_models = [] + models.each do |model| + unique_models << Wings::ModelRegistry.lookup(model) + end + + unique_models.uniq.each do |model| + file_sets = Hyrax.query_service.find_all_of_model(model: model) + file_sets.each do |fs| + ReindexItemJob.perform_later(fs.id.to_s) + end end end end diff --git a/app/jobs/reindex_item_job.rb b/app/jobs/reindex_item_job.rb index 412aa4372..1bce9fff1 100644 --- a/app/jobs/reindex_item_job.rb +++ b/app/jobs/reindex_item_job.rb @@ -1,7 +1,9 @@ # frozen_string_literal: true class ReindexItemJob < ApplicationJob - def perform(item) + def perform(item_id) + item = Hyrax.query_service.find_by(id: item_id) + if item.is_a?(Valkyrie::Resource) Hyrax.index_adapter.save(resource: item) else diff --git a/app/jobs/reindex_works_job.rb b/app/jobs/reindex_works_job.rb index 0f042b7c7..8084b4023 100644 --- a/app/jobs/reindex_works_job.rb +++ b/app/jobs/reindex_works_job.rb @@ -9,9 +9,19 @@ def perform(work = nil) work.update_index end else - Site.instance.available_works.each do |work_type| - work_type.constantize.find_each do |w| - ReindexItemJob.perform_later(w) + # previously this used models = Site.instance.available_works + # however, this means that if we stop allowing a particular work + # class for a tenant, we would also not ever reindex it. + # It is safer to use all work classes. + models = Hyrax::ModelRegistry.work_classes + unique_models = [] + models.each do |model| + unique_models << Wings::ModelRegistry.lookup(model) + end + unique_models.uniq.each do |model| + works = Hyrax.query_service.find_all_of_model(model: model) + works.each do |w| + ReindexItemJob.perform_later(w.id.to_s) end end end