View | Details | Raw Unified | Return to bug 26457
Collapse All | Expand All

(-)a/C4/Circulation.pm (-5 / +10 lines)
Lines 60-65 use Koha::Charges::Fees; Link Here
60
use Koha::Config::SysPref;
60
use Koha::Config::SysPref;
61
use Koha::Checkouts::ReturnClaims;
61
use Koha::Checkouts::ReturnClaims;
62
use Koha::SearchEngine::Indexer;
62
use Koha::SearchEngine::Indexer;
63
use Koha::Exceptions::Checkout;
63
use Carp;
64
use Carp;
64
use List::MoreUtils qw( uniq any );
65
use List::MoreUtils qw( uniq any );
65
use Scalar::Util qw( looks_like_number );
66
use Scalar::Util qw( looks_like_number );
Lines 2970-2981 sub AddRenewal { Link Here
2970
        # Update the issues record to have the new due date, and a new count
2971
        # Update the issues record to have the new due date, and a new count
2971
        # of how many times it has been renewed.
2972
        # of how many times it has been renewed.
2972
        my $renews = ( $issue->renewals || 0 ) + 1;
2973
        my $renews = ( $issue->renewals || 0 ) + 1;
2973
        my $sth = $dbh->prepare("UPDATE issues SET date_due = ?, renewals = ?, lastreneweddate = ?
2974
        my $sth = $dbh->prepare("UPDATE issues SET date_due = ?, renewals = ?, lastreneweddate = ? WHERE issue_id = ?");
2974
                                WHERE borrowernumber=?
2975
                                AND itemnumber=?"
2976
        );
2977
2975
2978
        $sth->execute( $datedue->strftime('%Y-%m-%d %H:%M'), $renews, $lastreneweddate, $borrowernumber, $itemnumber );
2976
        eval{
2977
            $sth->execute( $datedue->strftime('%Y-%m-%d %H:%M'), $renews, $lastreneweddate, $issue->issue_id );
2978
        };
2979
        if( $sth->err ){
2980
            Koha::Exceptions::Checkout::FailedRenewal->throw(
2981
                error => 'Update of issue# ' . $issue->issue_id . ' failed with error: ' . $sth->errstr
2982
            );
2983
        }
2979
2984
2980
        # Update the renewal count on the item, and tell zebra to reindex
2985
        # Update the renewal count on the item, and tell zebra to reindex
2981
        $renews = ( $item_object->renewals || 0 ) + 1;
2986
        $renews = ( $item_object->renewals || 0 ) + 1;
(-)a/Koha/Exceptions/Checkout.pm (+15 lines)
Line 0 Link Here
1
package Koha::Exceptions::Checkout;
2
3
use Modern::Perl;
4
5
use Exception::Class (
6
    'Koha::Exceptions::Checkout' => {
7
        description => "Something went wrong!"
8
    },
9
    'Koha::Exceptions::Checkout::FailedRenewal' => {
10
        isa         => 'Koha::Exceptions::Checkout',
11
        description => "Renewing checkout failed"
12
    },
13
);
14
15
1;
(-)a/svc/renew (-2 / +11 lines)
Lines 21-26 use Modern::Perl; Link Here
21
21
22
use CGI;
22
use CGI;
23
use JSON qw(to_json);
23
use JSON qw(to_json);
24
use Try::Tiny;
24
25
25
use C4::Circulation;
26
use C4::Circulation;
26
use C4::Context;
27
use C4::Context;
Lines 66-73 if ( $data->{error} && $data->{error} eq 'on_reserve' && C4::Context->preference Link Here
66
}
67
}
67
68
68
if ( $data->{renew_okay} ) {
69
if ( $data->{renew_okay} ) {
69
    $date_due = AddRenewal( $borrowernumber, $itemnumber, $branchcode, $date_due );
70
    try{
70
    $data->{date_due} = output_pref( { dt => $date_due, as_due_date => 1 } );
71
        $date_due = AddRenewal( $borrowernumber, $itemnumber, $branchcode, $date_due );
72
        $data->{date_due} = output_pref( { dt => $date_due, as_due_date => 1 } );
73
    } catch {
74
        if ( ref($_) eq 'Koha::Exceptions::Checkout::FailedRenewal' ) {
75
            $data->{error} = 'renewal_failed';
76
        } else {
77
            $_->rethrow;
78
        }
79
    };
71
}
80
}
72
81
73
print to_json($data);
82
print to_json($data);
(-)a/t/db_dependent/Circulation.t (-2 / +6 lines)
Lines 3689-3695 subtest 'AddReturn should clear items.onloan for unissued items' => sub { Link Here
3689
3689
3690
subtest 'AddRenewal and AddIssuingCharge tests' => sub {
3690
subtest 'AddRenewal and AddIssuingCharge tests' => sub {
3691
3691
3692
    plan tests => 12;
3692
    plan tests => 13;
3693
3693
3694
3694
3695
    t::lib::Mocks::mock_preference('item-level_itypes', 1);
3695
    t::lib::Mocks::mock_preference('item-level_itypes', 1);
Lines 3732-3737 subtest 'AddRenewal and AddIssuingCharge tests' => sub { Link Here
3732
3732
3733
    # Check the item out
3733
    # Check the item out
3734
    AddIssue( $patron->unblessed, $item->barcode );
3734
    AddIssue( $patron->unblessed, $item->barcode );
3735
3736
    throws_ok {
3737
        AddRenewal( $patron->borrowernumber, $item->itemnumber, $library->id, undef, {break=>"the_renewal"} );
3738
    } 'Koha::Exceptions::Checkout::FailedRenewal', 'Exception is thrown when renewal update to issues fails';
3739
3735
    t::lib::Mocks::mock_preference( 'RenewalLog', 0 );
3740
    t::lib::Mocks::mock_preference( 'RenewalLog', 0 );
3736
    my $date = output_pref( { dt => dt_from_string(), dateonly => 1, dateformat => 'iso' } );
3741
    my $date = output_pref( { dt => dt_from_string(), dateonly => 1, dateformat => 'iso' } );
3737
    my %params_renewal = (
3742
    my %params_renewal = (
3738
- 

Return to bug 26457