From 33ab22aafacd13dafe063c12cf2015fe2bc5e876 Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Wed, 6 Dec 2023 15:01:01 +0000 Subject: [PATCH] Bug 35104: Initial attempt at catching the failure on new records Whilst I can see the warning output from store, I can't seem to actually catch any exceptions.. confused --- cataloguing/addbiblio.pl | 58 ++++++++++++++++++++++++++-------------- 1 file changed, 38 insertions(+), 20 deletions(-) diff --git a/cataloguing/addbiblio.pl b/cataloguing/addbiblio.pl index e84c542092b..f8b993b6611 100755 --- a/cataloguing/addbiblio.pl +++ b/cataloguing/addbiblio.pl @@ -22,6 +22,8 @@ use Modern::Perl; use CGI; +use Try::Tiny; + use C4::Output qw( output_html_with_http_headers ); use C4::Auth qw( get_template_and_user haspermission ); use C4::Biblio qw( @@ -674,25 +676,41 @@ if ( $op eq "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 ) { - my $member = Koha::Patrons->find($loggedinuser); - ModBiblio( - $record, - $biblionumber, - $frameworkcode, - { - overlay_context => { - source => $z3950 ? 'z3950' : 'intranet', - categorycode => $member->categorycode, - userid => $member->userid + my $error = try { + if ($is_a_modif) { + warn "Attempting modify"; + my $member = Koha::Patrons->find($loggedinuser); + ModBiblio( + $record, + $biblionumber, + $frameworkcode, + { + overlay_context => { + source => $z3950 ? 'z3950' : 'intranet', + categorycode => $member->categorycode, + userid => $member->userid + } } - } - ); - } - else { - ( $biblionumber, $oldbibitemnum ) = AddBiblio( $record, $frameworkcode ); - } - if ($redirect eq "items" || ($mode ne "popup" && !$is_a_modif && $redirect ne "view" && $redirect ne "just_save")){ + ); + } else { + warn "Attempting add"; + ( $biblionumber, $oldbibitemnum ) = AddBiblio( $record, $frameworkcode ); + } + + return 0; + } catch { + warn "Caught exception"; + my $exception = $_; + if ( ref($error) eq 'Koha::Exceptions::Metadata::Invalid' ) { + warn "Found invalid metadata"; + $template->param( INVALID_METADATA => $exception ); + } else { + $exception->rethrow; + } + return 1; + }; + warn "Value of error: $error"; + if (!$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?' @@ -713,7 +731,7 @@ if ( $op eq "addbiblio" ) { exit; } } - elsif(($is_a_modif || $redirect eq "view") && $redirect ne "just_save"){ + elsif(!$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}) { @@ -728,7 +746,7 @@ if ( $op eq "addbiblio" ) { exit; } - elsif ($redirect eq "just_save"){ + elsif (!$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"); } -- 2.43.0