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

(-)a/C4/Circulation.pm (-6 / +11 lines)
Lines 61-66 use Koha::Config::SysPrefs; Link Here
61
use Koha::Charges::Fees;
61
use Koha::Charges::Fees;
62
use Koha::Util::SystemPreferences;
62
use Koha::Util::SystemPreferences;
63
use Koha::Checkouts::ReturnClaims;
63
use Koha::Checkouts::ReturnClaims;
64
use Koha::Exceptions::Checkout;
64
use Carp;
65
use Carp;
65
use List::MoreUtils qw( uniq any );
66
use List::MoreUtils qw( uniq any );
66
use Scalar::Util qw( looks_like_number );
67
use Scalar::Util qw( looks_like_number );
Lines 2961-2973 sub AddRenewal { Link Here
2961
2962
2962
        # Update the issues record to have the new due date, and a new count
2963
        # Update the issues record to have the new due date, and a new count
2963
        # of how many times it has been renewed.
2964
        # of how many times it has been renewed.
2964
        my $renews = $issue->renewals + 1;
2965
        my $renews = ( $issue->renewals || 0 ) + 1;
2965
        my $sth = $dbh->prepare("UPDATE issues SET date_due = ?, renewals = ?, lastreneweddate = ?
2966
        my $sth = $dbh->prepare("UPDATE issues SET date_due = ?, renewals = ?, lastreneweddate = ? WHERE issue_id = ?");
2966
                                WHERE borrowernumber=?
2967
                                AND itemnumber=?"
2968
        );
2969
2967
2970
        $sth->execute( $datedue->strftime('%Y-%m-%d %H:%M'), $renews, $lastreneweddate, $borrowernumber, $itemnumber );
2968
        eval{
2969
            $sth->execute( $datedue->strftime('%Y-%m-%d %H:%M'), $renews, $lastreneweddate, $issue->issue_id );
2970
        };
2971
        if( $sth->err ){
2972
            Koha::Exceptions::Checkout::FailedRenewal->throw(
2973
                error => 'Update of issue# ' . $issue->issue_id . ' failed with error: ' . $sth->errstr
2974
            );
2975
        }
2971
2976
2972
        # Update the renewal count on the item, and tell zebra to reindex
2977
        # Update the renewal count on the item, and tell zebra to reindex
2973
        $renews = $item_object->renewals + 1;
2978
        $renews = $item_object->renewals + 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 / +7 lines)
Lines 19-24 use Modern::Perl; Link Here
19
use utf8;
19
use utf8;
20
20
21
use Test::More tests => 47;
21
use Test::More tests => 47;
22
use Test::Exception;
22
use Test::MockModule;
23
use Test::MockModule;
23
24
24
use Data::Dumper;
25
use Data::Dumper;
Lines 3099-3105 subtest 'AddReturn should clear items.onloan for unissued items' => sub { Link Here
3099
3100
3100
subtest 'AddRenewal and AddIssuingCharge tests' => sub {
3101
subtest 'AddRenewal and AddIssuingCharge tests' => sub {
3101
3102
3102
    plan tests => 11;
3103
    plan tests => 12;
3103
3104
3104
3105
3105
    t::lib::Mocks::mock_preference('item-level_itypes', 1);
3106
    t::lib::Mocks::mock_preference('item-level_itypes', 1);
Lines 3142-3147 subtest 'AddRenewal and AddIssuingCharge tests' => sub { Link Here
3142
3143
3143
    # Check the item out
3144
    # Check the item out
3144
    AddIssue( $patron->unblessed, $item->barcode );
3145
    AddIssue( $patron->unblessed, $item->barcode );
3146
3147
    throws_ok {
3148
        AddRenewal( $patron->borrowernumber, $item->itemnumber, $library->id, undef, {break=>"the_renewal"} );
3149
    } 'Koha::Exceptions::Checkout::FailedRenewal', 'Exception is thrown when renewal update to issues fails';
3150
3145
    t::lib::Mocks::mock_preference( 'RenewalLog', 0 );
3151
    t::lib::Mocks::mock_preference( 'RenewalLog', 0 );
3146
    my $date = output_pref( { dt => dt_from_string(), dateonly => 1, dateformat => 'iso' } );
3152
    my $date = output_pref( { dt => dt_from_string(), dateonly => 1, dateformat => 'iso' } );
3147
    my %params_renewal = (
3153
    my %params_renewal = (
3148
- 

Return to bug 26457