Bugzilla – Attachment 193994 Details for
Bug 35104
We should warn when attempting to save MARC records that contain characters invalid in XML
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 35104: Catch the failure on new and edited records
767de09.patch (text/plain), 8.54 KB, created by
Martin Renvoize (ashimema)
on 2026-02-26 13:45:39 UTC
(
hide
)
Description:
Bug 35104: Catch the failure on new and edited records
Filename:
MIME Type:
Creator:
Martin Renvoize (ashimema)
Created:
2026-02-26 13:45:39 UTC
Size:
8.54 KB
patch
obsolete
>From 767de0958769f882fe21a6a544f7e49d79c39011 Mon Sep 17 00:00:00 2001 >From: Martin Renvoize <martin.renvoize@ptfs-europe.com> >Date: Wed, 6 Dec 2023 15:01:01 +0000 >Subject: [PATCH] Bug 35104: Catch the failure on new and edited records > >We now catch the error and display it to the end user so they can fix >the issues before attempting to save again. > >Signed-off-by: Baptiste Bayche <baptiste.bayche@inlibro.com> >Signed-off-by: Baptiste Wojtkowski <baptiste.wojtkowski@biblibre.com> >Sponsored-by: OpenFifth >--- > C4/Biblio.pm | 10 +++- > cataloguing/addbiblio.pl | 122 +++++++++++++++++++++------------------ > 2 files changed, 75 insertions(+), 57 deletions(-) > >diff --git a/C4/Biblio.pm b/C4/Biblio.pm >index aaee18aebfb..60d56e6e937 100644 >--- a/C4/Biblio.pm >+++ b/C4/Biblio.pm >@@ -319,8 +319,14 @@ sub AddBiblio { > $indexer->index_records( $biblionumber, "specialUpdate", "biblioserver" ); > } > } catch { >- warn $_; >- ( $biblionumber, $biblioitemnumber ) = ( undef, undef ); >+ my $error = $_; >+ if ( ref($error) eq 'Koha::Exceptions::Metadata::Invalid' ) { >+ ( $biblionumber, $biblioitemnumber ) = ( undef, undef ); >+ $error->rethrow; >+ } else { >+ warn $error; >+ ( $biblionumber, $biblioitemnumber ) = ( undef, undef ); >+ } > }; > return ( $biblionumber, $biblioitemnumber ); > } >diff --git a/cataloguing/addbiblio.pl b/cataloguing/addbiblio.pl >index a8e2720b5c1..c9baa96b3ea 100755 >--- a/cataloguing/addbiblio.pl >+++ b/cataloguing/addbiblio.pl >@@ -20,7 +20,7 @@ > > use Modern::Perl; > use CGI; >-use POSIX qw( strftime ); >+use POSIX qw(strftime); > use Try::Tiny qw(catch try); > > use C4::Output qw( output_html_with_http_headers ); >@@ -703,72 +703,84 @@ if ( $op eq "cud-addbiblio" ) { > # it is not a duplicate (determined either by Koha itself or by user checking it's not a duplicate) > if ( !$duplicatebiblionumber or $confirm_not_duplicate ) { > my $oldbibitemnum; >- if ($is_a_modif) { >- ModBiblio( >- $record, >- $biblionumber, >- $frameworkcode, >- { >- overlay_context => { >- source => $z3950 ? 'z3950' : 'intranet', >- categorycode => $logged_in_patron->categorycode, >- userid => $logged_in_patron->userid, >+ my $encode_error = try { >+ if ( $is_a_modif ) { >+ ModBiblio( >+ $record, >+ $biblionumber, >+ $frameworkcode, >+ { >+ overlay_context => { >+ source => $z3950 ? 'z3950' : 'intranet', >+ categorycode => $logged_in_patron->categorycode, >+ userid => $logged_in_patron->userid, >+ } > } >- } >- ); >- } else { >- ( $biblionumber, $oldbibitemnum ) = AddBiblio( $record, $frameworkcode ); >- } >- if ( $redirect eq "items" >- || ( $mode ne "popup" && !$is_a_modif && $redirect ne "view" && $redirect ne "just_save" ) ) >- { >- if ( $frameworkcode eq 'FA' ) { >- print $input->redirect( '/cgi-bin/koha/cataloguing/additem.pl?' >- . 'biblionumber=' >- . $biblionumber >- . '&frameworkcode=' >- . $frameworkcode >- . '&circborrowernumber=' >- . $fa_circborrowernumber >- . '&branch=' >- . $fa_branch >- . '&barcode=' >- . uri_escape_utf8($fa_barcode) >- . '&stickyduedate=' >- . $fa_stickyduedate >- . '&duedatespec=' >- . $fa_duedatespec ); >- exit; >+ ); >+ } else { >+ ( $biblionumber, $oldbibitemnum ) = AddBiblio( $record, $frameworkcode ); >+ } >+ return 0; >+ } catch { >+ my $exception = $_; >+ if ( ref($exception) eq 'Koha::Exceptions::Metadata::Invalid' ) { >+ $template->param( INVALID_METADATA => $exception ); > } else { >- print $input->redirect( >+ $exception->rethrow; >+ } >+ return 1; >+ }; >+ if (!$encode_error && ($redirect eq "items" || ($mode ne "popup" && !$is_a_modif && $redirect ne "view" && $redirect ne "just_save"))){ >+ if ($frameworkcode eq 'FA'){ >+ print $input->redirect( >+ '/cgi-bin/koha/cataloguing/additem.pl?' >+ .'biblionumber='.$biblionumber >+ .'&frameworkcode='.$frameworkcode >+ .'&circborrowernumber='.$fa_circborrowernumber >+ .'&branch='.$fa_branch >+ .'&barcode='.uri_escape_utf8($fa_barcode) >+ .'&stickyduedate='.$fa_stickyduedate >+ .'&duedatespec='.$fa_duedatespec >+ ); >+ exit; >+ } >+ else { >+ print $input->redirect( > "/cgi-bin/koha/cataloguing/additem.pl?biblionumber=$biblionumber&frameworkcode=$frameworkcode&searchid=$searchid" >- ); >- exit; >+ ); >+ exit; > } >- } elsif ( ( $is_a_modif || $redirect eq "view" ) && $redirect ne "just_save" ) { >+ } elsif(!$encode_error && (($is_a_modif || $redirect eq "view") && $redirect ne "just_save")){ > my $defaultview = C4::Context->preference('IntranetBiblioDefaultView'); >- my $views = {C4::Search::enabled_staff_search_views}; >- if ( $defaultview eq 'isbd' && $views->{can_view_ISBD} ) { >- print $input->redirect( >- "/cgi-bin/koha/catalogue/ISBDdetail.pl?biblionumber=$biblionumber&searchid=$searchid"); >- } elsif ( $defaultview eq 'marc' && $views->{can_view_MARC} ) { >- print $input->redirect( >- "/cgi-bin/koha/catalogue/MARCdetail.pl?biblionumber=$biblionumber&frameworkcode=$frameworkcode&searchid=$searchid" >- ); >- } elsif ( $defaultview eq 'labeled_marc' && $views->{can_view_labeledMARC} ) { >- print $input->redirect( >- "/cgi-bin/koha/catalogue/labeledMARCdetail.pl?biblionumber=$biblionumber&searchid=$searchid"); >+ my $views = { C4::Search::enabled_staff_search_views }; >+ if ($defaultview eq 'isbd' && $views->{can_view_ISBD}) { >+ print $input->redirect("/cgi-bin/koha/catalogue/ISBDdetail.pl?biblionumber=$biblionumber&searchid=$searchid"); >+ } elsif ($defaultview eq 'marc' && $views->{can_view_MARC}) { >+ print $input->redirect("/cgi-bin/koha/catalogue/MARCdetail.pl?biblionumber=$biblionumber&frameworkcode=$frameworkcode&searchid=$searchid"); >+ } elsif ($defaultview eq 'labeled_marc' && $views->{can_view_labeledMARC}) { >+ print $input->redirect("/cgi-bin/koha/catalogue/labeledMARCdetail.pl?biblionumber=$biblionumber&searchid=$searchid"); > } else { >- print $input->redirect( >- "/cgi-bin/koha/catalogue/detail.pl?biblionumber=$biblionumber&searchid=$searchid"); >+ print $input->redirect("/cgi-bin/koha/catalogue/detail.pl?biblionumber=$biblionumber&searchid=$searchid"); > } > exit; >- >- } elsif ( $redirect eq "just_save" ) { >+ } >+ elsif ( !$encode_error && ( $redirect eq "just_save" ) ) { > my $tab = $input->param('current_tab'); > print $input->redirect( > "/cgi-bin/koha/cataloguing/addbiblio.pl?biblionumber=$biblionumber&framework=$frameworkcode&tab=$tab&searchid=$searchid" > ); >+ } elsif ($encode_error) { >+ build_tabs( $template, $record, $dbh, $encoding, $input ); >+ $template->param( >+ biblionumber => $biblionumber, >+ popup => $mode, >+ frameworkcode => $frameworkcode, >+ itemtype => $frameworkcode, >+ borrowernumber => $loggedinuser, >+ tab => scalar $input->param('tab') >+ ); >+ output_html_with_http_headers $input, $cookie, $template->output; >+ exit; > } else { > $template->param( > biblionumber => $biblionumber, >-- >2.53.0 >
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 35104
:
157625
|
157627
|
157628
|
157642
|
159615
|
159620
|
159621
|
159630
|
159810
|
159811
|
159812
|
159813
|
166431
|
173145
|
173146
|
176820
|
176821
|
176850
|
176851
|
176852
|
176860
|
193985
|
193986
|
193987
|
193988
|
193989
|
193990
|
193991
|
193992
|
193993
|
193994
|
193995
|
193996
|
193997
|
193998
|
193999
|
194000
|
194001
|
194004
|
194005
|
194006
|
194007
|
194008
|
194009
|
194010
|
194011
|
194012
|
194013