Browse Source

Bug 26457: Throw exception if update of issues table fails

While this won't prevent the deadlock, it should catch the case where
a deadlock causes the DB update to fail and provide feedback to the user
and rollback the transaction

I don't know how to trigger the deadlock, I can only confirm that we see it, and
that this should catch it.

To test:
1 - Apply patches
2 - Checkout several items to a patron
3 - Confirm that 'Renew all' feature continues to work as expected and all items are renewed

Signed-off-by: David Nind <david@davidnind.com>

Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
master
Nick Clemens 4 months ago
parent
commit
4062116352
3 changed files with 32 additions and 2 deletions
  1. +6
    -0
      C4/Circulation.pm
  2. +15
    -0
      Koha/Exceptions/Checkout.pm
  3. +11
    -2
      svc/renew

+ 6
- 0
C4/Circulation.pm View File

@@ -62,6 +62,7 @@ use Koha::Charges::Fees;
use Koha::Config::SysPref;
use Koha::Checkouts::ReturnClaims;
use Koha::SearchEngine::Indexer;
use Koha::Exceptions::Checkout;
use Carp;
use List::MoreUtils qw( uniq any );
use Scalar::Util qw( looks_like_number );
@@ -3039,6 +3040,11 @@ sub AddRenewal {
);

$sth->execute( $datedue->strftime('%Y-%m-%d %H:%M'), $renews, $unseen_renewals, $lastreneweddate, $borrowernumber, $itemnumber );
if ( $sth->err ){
Koha::Exceptions::Checkout::FailedRenewal->throw(
error => 'Update of issue# ' . $issue->issue_id . ' failed with error: ' . $sth->errstr
);
}

# Update the renewal count on the item, and tell zebra to reindex
$renews = ( $item_object->renewals || 0 ) + 1;


+ 15
- 0
Koha/Exceptions/Checkout.pm View File

@@ -0,0 +1,15 @@
package Koha::Exceptions::Checkout;

use Modern::Perl;

use Exception::Class (
'Koha::Exceptions::Checkout' => {
description => "Something went wrong!"
},
'Koha::Exceptions::Checkout::FailedRenewal' => {
isa => 'Koha::Exceptions::Checkout',
description => "Renewing checkout failed"
},
);

1;

+ 11
- 2
svc/renew View File

@@ -21,6 +21,7 @@ use Modern::Perl;

use CGI;
use JSON qw(to_json);
use Try::Tiny;

use C4::Circulation;
use C4::Context;
@@ -67,8 +68,16 @@ if ( $data->{error} && $data->{error} eq 'on_reserve' && C4::Context->preference
}

if ( $data->{renew_okay} ) {
$date_due = AddRenewal( $borrowernumber, $itemnumber, $branchcode, $date_due, undef, undef, $seen );
$data->{date_due} = output_pref( { dt => $date_due, as_due_date => 1 } );
try{
$date_due = AddRenewal( $borrowernumber, $itemnumber, $branchcode, $date_due, undef, undef, $seen );
$data->{date_due} = output_pref( { dt => $date_due, as_due_date => 1 } );
} catch {
if ( ref($_) eq 'Koha::Exceptions::Checkout::FailedRenewal' ) {
$data->{error} = 'renewal_failed';
} else {
$_->rethrow;
}
};
}

print to_json($data);

Loading…
Cancel
Save