From 8dc2152e2f32b79abfe5f5531ddc225601498116 Mon Sep 17 00:00:00 2001 From: Nick Clemens Date: Tue, 17 Oct 2023 17:06:22 +0000 Subject: [PATCH] Bug 34014: Add support for advanced cataloging editor To test: 1 - Enable the advanced cataloging editor 2 - Edit record 369 in the advanced cataloging editor 3 - On load, get a notice that there were issues and to check logs 4 - Save record 5 - Close and reopen in editor 6 - Confirm warning is gone Signed-off-by: Lucas Gass Signed-off-by: Kelly McElligott Signed-off-by: Martin Renvoize Signed-off-by: Tomas Cohen Arazi --- .../lib/koha/cateditor/koha-backend.js | 6 +++++- svc/bib | 13 +++++++++++-- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/koha-tmpl/intranet-tmpl/lib/koha/cateditor/koha-backend.js b/koha-tmpl/intranet-tmpl/lib/koha/cateditor/koha-backend.js index d3556bbc1a..934c7fb4f4 100644 --- a/koha-tmpl/intranet-tmpl/lib/koha/cateditor/koha-backend.js +++ b/koha-tmpl/intranet-tmpl/lib/koha/cateditor/koha-backend.js @@ -106,7 +106,11 @@ define( [ '/cgi-bin/koha/svc/cataloguing/framework?frameworkcode=&callback=defin GetRecord: function( id, remove_control_num, callback ) { $.get( '/cgi-bin/koha/svc/bib/'+ id - ).done( function( metadata ) { + ).done( function( metadata, status, xhr ) { + let encoding_issues = xhr.getResponseHeader('invalid-metadata'); + if( encoding_issues ){ + humanMsg.displayAlert( _("Record had encoding issues, please see logs") ); + } $.get( '/cgi-bin/koha/svc/bib_framework/' + id ).done( function( frameworkcode ) { diff --git a/svc/bib b/svc/bib index d25d0710c6..fc5996168d 100755 --- a/svc/bib +++ b/svc/bib @@ -67,9 +67,18 @@ sub fetch_bib { my $query = shift; my $biblionumber = shift; my $biblio = Koha::Biblios->find( $biblionumber ); - my $record = $biblio->metadata->record({ embed_items => scalar $query->param('items') }); + my $record; + my $exception; + my $invalid_metadata; + eval { $record = $biblio->metadata->record({ embed_items => scalar $query->param('items') }) }; + if( $@ ){ + $exception = $@; + $exception->rethrow unless ( $exception->isa('Koha::Exceptions::Metadata::Invalid') ); + $record = $biblio->metadata->record_strip_nonxml({ embed_items => scalar $query->param('items') }); + $invalid_metadata = 1; + } if (defined $record) { - print $query->header(-type => 'text/xml',-charset => 'utf-8',); + print $query->header(-type => 'text/xml',-charset => 'utf-8', -invalid_metadata => $invalid_metadata ); print $record->as_xml_record(); } else { print $query->header(-type => 'text/xml', -status => '404 Not Found');