Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Solution to show child work #609

Draft
wants to merge 1 commit into
base: dev
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions app/controllers/controller_utils.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
module ControllerUtils
def self.included(base)
# This block will run when the module is included in a class
base.before_action :fix_missing_order_members, only: :show
end

def additional_response_formats(format)
format.endnote do
send_data(presenter.solr_document.export_as_endnote,
Expand Down Expand Up @@ -60,4 +65,11 @@ def add_date_and_creator_to_note(model)
params[model]['editorial_note'] = notes if notes.present?
end

def fix_missing_order_members
@curation_concern = _curation_concern_type.find(params[:id]) unless curation_concern
if @curation_concern.member_ids.count > @curation_concern.ordered_member_ids.count
UpdateOrderMembersJob.perform_later(_curation_concern_type.to_s, presenter.id)
end
end

end
18 changes: 18 additions & 0 deletions app/jobs/update_order_members_job.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
class UpdateOrderMembersJob < ApplicationJob
queue_as :default

def perform(curation_concern_type, document_id)
curation_concern = curation_concern_type.constantize.find(document_id)

if curation_concern.member_ids.count > curation_concern.ordered_member_ids.count
missing_ids = curation_concern.member_ids - curation_concern.ordered_member_ids
missing_ids.each do |doc_id|
missing_member = ActiveFedora::Base.find(doc_id)
curation_concern.ordered_members << missing_member
curation_concern.save
rescue ActiveFedora::ObjectNotFoundError
Rails.logger.error("Unable to fetch document with id: #{doc_id}.")
end
end
end
end