Browse Source

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>
20.11.x
Kyle Hall 4 years ago
committed by Jonathan Druart
parent
commit
1e37d9c5f7
  1. 22
      Koha/REST/V1/Patrons.pm
  2. 11
      members/deletemem.pl

22
Koha/REST/V1/Patrons.pm

@ -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) {

11
members/deletemem.pl

@ -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…
Cancel
Save