Bug 14708: (QA follow-up) Use try/catch blocks when calling delete() on a patron
Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
(cherry picked from commit 1e37d9c5f7)
Signed-off-by: Andrew Fuerste-Henry <andrew@bywatersolutions.com>
This commit is contained in:
parent
93e32c77e9
commit
5ca4e7f2b2
|
|
@ -310,11 +310,23 @@ sub delete {
|
|||
$patron = Koha::Patrons->find( $c->validation->param('patron_id') );
|
||||
|
||||
# check if loans, reservations, debarrment, etc. before deletion!
|
||||
$patron->delete;
|
||||
return $c->render(
|
||||
status => 204,
|
||||
openapi => q{}
|
||||
);
|
||||
try {
|
||||
$patron->delete;
|
||||
return $c->render(
|
||||
status => 204,
|
||||
openapi => q{}
|
||||
);
|
||||
} catch {
|
||||
if ( $_->isa('Koha::Exceptions::Patron::FailedDeleteAnonymousPatron') ) {
|
||||
return $c->render(
|
||||
status => 403,
|
||||
openapi => { error => "Anonymous patron cannot be deleted" }
|
||||
);
|
||||
}
|
||||
else {
|
||||
$c->unhandled_exception($_);
|
||||
}
|
||||
};
|
||||
}
|
||||
catch {
|
||||
unless ($patron) {
|
||||
|
|
|
|||
|
|
@ -24,6 +24,9 @@
|
|||
use Modern::Perl;
|
||||
|
||||
use CGI qw ( -utf8 );
|
||||
|
||||
use Try::Tiny;
|
||||
|
||||
use C4::Context;
|
||||
use C4::Output;
|
||||
use C4::Auth;
|
||||
|
|
@ -127,9 +130,13 @@ if ( $op eq 'delete_confirm' or $countissues > 0 or $debits or $is_guarantor ) {
|
|||
});
|
||||
my $patron = Koha::Patrons->find( $member );
|
||||
$patron->move_to_deleted;
|
||||
$patron->delete;
|
||||
try {
|
||||
$patron->delete;
|
||||
print $input->redirect("/cgi-bin/koha/members/members-home.pl");
|
||||
} catch {
|
||||
print $input->redirect("/cgi-bin/koha/members/moremember.pl?borrowernumber=$member&error=CANT_DELETE_ANONYMOUS_PATRON");
|
||||
}
|
||||
# TODO Tell the user everything went ok
|
||||
print $input->redirect("/cgi-bin/koha/members/members-home.pl");
|
||||
exit 0; # Exit without error
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue