Skip to content

Commit

Permalink
fix ids in data controller
Browse files Browse the repository at this point in the history
  • Loading branch information
xhero committed Feb 9, 2024
1 parent 31bd1f5 commit 0d92995
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 5 deletions.
2 changes: 1 addition & 1 deletion app/admin/source.rb
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def show

respond_to do |format|
format.html
format.xml { render :xml => @item.marc.to_xml({ updated_at: @item.updated_at, versions: @item.versions }) }
format.xml { render :xml => @item.marc.to_xml({ updated_at: @item.updated_at, versions: @item.versions}) }
end
end

Expand Down
7 changes: 6 additions & 1 deletion app/controllers/data_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,13 @@ def show
@model = params[:model].classify.safe_constantize
@item = @model.find(params[:id])

@deprecated_ids = params.include?("deprecatedIds") ? params["deprecatedIds"] : "false"

ap params
ap params["deprecatedIds"]

if @item.respond_to?(:marc)
@xml = @item.marc.to_xml({ updated_at: @item.updated_at, versions: @item.versions })
@xml = @item.marc.to_xml({ updated_at: @item.updated_at, versions: @item.versions, deprecated_ids: @deprecated_ids })
else
@xml = @item.to_xml
end
Expand Down
4 changes: 3 additions & 1 deletion lib/marc.rb
Original file line number Diff line number Diff line change
Expand Up @@ -521,12 +521,14 @@ def to_xml_record(options = {})
updated_at = options.has_key?(:updated_at) ? options[:updated_at] : nil
versions = options.has_key?(:versions) ? options[:versions] : nil
holdings = options.has_key?(:holdings) ? options[:holdings] : true
# Temp fix to allow deprecated ids
deprecated_ids = options.has_key?(:deprecated_ids) ? !(options[:deprecated_ids] == "false") : true

load_source unless @loaded

safe_marc = self.deep_copy
safe_marc.root = @root.deep_copy
safe_marc.to_external(updated_at, versions, holdings)
safe_marc.to_external(updated_at, versions, holdings, deprecated_ids)

document = XML::Document.new()
document.root = XML::Node.new("record")
Expand Down
8 changes: 6 additions & 2 deletions lib/marc_source.rb
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ def to_internal
end
end

def to_external(updated_at = nil, versions = nil, holdings = true)
def to_external(updated_at = nil, versions = nil, holdings = true, deprecated_ids = true)
super(updated_at, versions)
parent_object = Source.find(get_id)
# See #933, supersedes #176
Expand Down Expand Up @@ -588,7 +588,11 @@ def to_external(updated_at = nil, versions = nil, holdings = true)
end
parent_object.holdings.order(:lib_siglum).each do |holding|
holding.marc.by_tags("599").each {|t| t.destroy_yourself}
id = "holdings/#{holding.id}"
if deprecated_ids
id = "#{holding.id}"
else
id = "holdings/#{holding.id}"
end
holding.marc.all_tags.each do |tag|
tag.add_at(MarcNode.new(@model, "3", id, nil), 0)
@root.add_at(tag, get_insert_position(tag.tag)) if tag.tag != "001"
Expand Down

0 comments on commit 0d92995

Please sign in to comment.