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

(-)a/C4/Circulation.pm (-15 / +22 lines)
Lines 1349-1355 sub checkHighHolds { Link Here
1349
1349
1350
        my $orig_due = C4::Circulation::CalcDateDue( $issuedate, $itype, $branchcode, $borrower );
1350
        my $orig_due = C4::Circulation::CalcDateDue( $issuedate, $itype, $branchcode, $borrower );
1351
1351
1352
        my $rule = Koha::CirculationRules->get_effective_rule(
1352
        my $rule = Koha::CirculationRules->get_effective_rule_value(
1353
            {
1353
            {
1354
                categorycode => $borrower->{categorycode},
1354
                categorycode => $borrower->{categorycode},
1355
                itemtype     => $item_object->effective_itemtype,
1355
                itemtype     => $item_object->effective_itemtype,
Lines 1359-1367 sub checkHighHolds { Link Here
1359
        );
1359
        );
1360
1360
1361
        my $duration;
1361
        my $duration;
1362
        if ( defined($rule) && $rule->rule_value ne '' ){
1362
        if ( defined($rule) && $rule ne '' ){
1363
            # overrides decreaseLoanHighHoldsDuration syspref
1363
            # overrides decreaseLoanHighHoldsDuration syspref
1364
            $duration = $rule->rule_value;
1364
            $duration = $rule;
1365
        } else {
1365
        } else {
1366
            $duration = C4::Context->preference('decreaseLoanHighHoldsDuration');
1366
            $duration = C4::Context->preference('decreaseLoanHighHoldsDuration');
1367
        }
1367
        }
Lines 1520-1526 sub AddIssue { Link Here
1520
1520
1521
            # If automatic renewal wasn't selected while issuing, set the value according to the issuing rule.
1521
            # If automatic renewal wasn't selected while issuing, set the value according to the issuing rule.
1522
            unless ($auto_renew) {
1522
            unless ($auto_renew) {
1523
                my $rule = Koha::CirculationRules->get_effective_rule(
1523
                my $rule = Koha::CirculationRules->get_effective_rule_value(
1524
                    {
1524
                    {
1525
                        categorycode => $borrower->{categorycode},
1525
                        categorycode => $borrower->{categorycode},
1526
                        itemtype     => $item_object->effective_itemtype,
1526
                        itemtype     => $item_object->effective_itemtype,
Lines 1529-1535 sub AddIssue { Link Here
1529
                    }
1529
                    }
1530
                );
1530
                );
1531
1531
1532
                $auto_renew = $rule->rule_value if $rule;
1532
                $auto_renew = $rule if defined $rule && $rule ne '';
1533
            }
1533
            }
1534
1534
1535
            my $issue_attributes = {
1535
            my $issue_attributes = {
Lines 2763-2773 sub CanBookBeRenewed { Link Here
2763
                branchcode   => $branchcode,
2763
                branchcode   => $branchcode,
2764
                rules => [
2764
                rules => [
2765
                    'renewalsallowed',
2765
                    'renewalsallowed',
2766
                    'lengthunit',
2767
                    'unseen_renewals_allowed',
2766
                    'unseen_renewals_allowed',
2768
                    'no_auto_renewal_after',
2769
                    'no_auto_renewal_after_hard_limit',
2770
                    'norenewalbefore'
2771
                ]
2767
                ]
2772
            }
2768
            }
2773
        );
2769
        );
Lines 2792-2805 sub CanBookBeRenewed { Link Here
2792
            return ( 0, 'overdue');
2788
            return ( 0, 'overdue');
2793
        }
2789
        }
2794
2790
2795
        $soonest_renew_date = GetSoonestRenewDate($borrowernumber, $itemnumber, $branchcode, $issuing_rule);
2791
        $soonest_renew_date = GetSoonestRenewDate($borrowernumber, $itemnumber, $branchcode);
2796
2792
2797
        $auto_renew = _CanBookBeAutoRenewed({
2793
        $auto_renew = _CanBookBeAutoRenewed({
2798
            patron     => $patron,
2794
            patron     => $patron,
2799
            item       => $item,
2795
            item       => $item,
2800
            branchcode => $branchcode,
2796
            branchcode => $branchcode,
2801
            issue      => $issue,
2797
            issue      => $issue,
2802
            issuing_rule => $issuing_rule,
2803
            soonest    => $soonest_renew_date
2798
            soonest    => $soonest_renew_date
2804
        }) if $issue->auto_renew && $patron->autorenew_checkouts;
2799
        }) if $issue->auto_renew && $patron->autorenew_checkouts;
2805
2800
Lines 3168-3174 cannot be found. Link Here
3168
=cut
3163
=cut
3169
3164
3170
sub GetSoonestRenewDate {
3165
sub GetSoonestRenewDate {
3171
    my ( $borrowernumber, $itemnumber, $branchcode, $issuing_rule ) = @_;
3166
    my ( $borrowernumber, $itemnumber, $branchcode ) = @_;
3172
3167
3173
    my $dbh = C4::Context->dbh;
3168
    my $dbh = C4::Context->dbh;
3174
3169
Lines 3180-3186 sub GetSoonestRenewDate { Link Here
3180
      or return;
3175
      or return;
3181
3176
3182
    $branchcode = _GetCircControlBranch( $item->unblessed, $patron->unblessed ) unless $branchcode;
3177
    $branchcode = _GetCircControlBranch( $item->unblessed, $patron->unblessed ) unless $branchcode;
3183
    $issuing_rule = Koha::CirculationRules->get_effective_rules(
3178
    my $issuing_rule = Koha::CirculationRules->get_effective_rules(
3184
        {   categorycode => $patron->categorycode,
3179
        {   categorycode => $patron->categorycode,
3185
            itemtype     => $item->effective_itemtype,
3180
            itemtype     => $item->effective_itemtype,
3186
            branchcode   => $branchcode,
3181
            branchcode   => $branchcode,
Lines 3189-3195 sub GetSoonestRenewDate { Link Here
3189
                'lengthunit',
3184
                'lengthunit',
3190
            ]
3185
            ]
3191
        }
3186
        }
3192
    ) unless $issuing_rule;
3187
    );
3193
3188
3194
    my $now = dt_from_string;
3189
    my $now = dt_from_string;
3195
3190
Lines 4278-4289 sub _CanBookBeAutoRenewed { Link Here
4278
    my $branchcode = $params->{branchcode};
4273
    my $branchcode = $params->{branchcode};
4279
    my $issue = $params->{issue};
4274
    my $issue = $params->{issue};
4280
    my $soonest_renew_date = $params->{soonest};
4275
    my $soonest_renew_date = $params->{soonest};
4281
    my $issuing_rule = $params->{issuing_rule};
4282
4276
4283
    if ( $patron->category->effective_BlockExpiredPatronOpacActions and $patron->is_expired ) {
4277
    if ( $patron->category->effective_BlockExpiredPatronOpacActions and $patron->is_expired ) {
4284
        return 'auto_account_expired';
4278
        return 'auto_account_expired';
4285
    }
4279
    }
4286
4280
4281
    my $issuing_rule = Koha::CirculationRules->get_effective_rules(
4282
        {
4283
            categorycode => $patron->categorycode,
4284
            itemtype     => $item->effective_itemtype,
4285
            branchcode   => $branchcode,
4286
            rules => [
4287
                'no_auto_renewal_after',
4288
                'no_auto_renewal_after_hard_limit',
4289
                'lengthunit'
4290
            ]
4291
        }
4292
    );
4293
4287
    if ( defined $issuing_rule->{no_auto_renewal_after}
4294
    if ( defined $issuing_rule->{no_auto_renewal_after}
4288
            and $issuing_rule->{no_auto_renewal_after} ne "" ) {
4295
            and $issuing_rule->{no_auto_renewal_after} ne "" ) {
4289
        # Get issue_date and add no_auto_renewal_after
4296
        # Get issue_date and add no_auto_renewal_after
(-)a/Koha/CirculationRules.pm (-2 / +33 lines)
Lines 22-27 use Carp qw( croak ); Link Here
22
22
23
use Koha::Exceptions;
23
use Koha::Exceptions;
24
use Koha::CirculationRule;
24
use Koha::CirculationRule;
25
use Koha::Caches;
26
use Koha::Cache::Memory::Lite;
25
27
26
use base qw(Koha::Objects);
28
use base qw(Koha::Objects);
27
29
Lines 229-234 sub get_effective_rule { Link Here
229
    return $rule;
231
    return $rule;
230
}
232
}
231
233
234
sub get_effective_rule_value {
235
    my ( $self, $params ) = @_;
236
237
    my $rule_name    = $params->{rule_name};
238
    my $categorycode = $params->{categorycode};
239
    my $itemtype     = $params->{itemtype};
240
    my $branchcode   = $params->{branchcode};
241
242
    my $memory_cache = Koha::Cache::Memory::Lite->get_instance;
243
    my $cache_key = sprintf "CircRules:%s:%s:%s:%s", $rule_name // q{},
244
      $categorycode // q{}, $branchcode // q{}, $itemtype // q{};
245
246
    my $cached       = $memory_cache->get_from_cache($cache_key);
247
    return $cached if $cached;
248
249
    my $rule = $self->get_effective_rule($params);
250
251
    my $value= $rule ? $rule->rule_value : undef;
252
    $memory_cache->set_in_cache( $cache_key, $value );
253
    return $value;
254
}
255
232
=head3 get_effective_rules
256
=head3 get_effective_rules
233
257
234
=cut
258
=cut
Lines 243-249 sub get_effective_rules { Link Here
243
267
244
    my $r;
268
    my $r;
245
    foreach my $rule (@$rules) {
269
    foreach my $rule (@$rules) {
246
        my $effective_rule = $self->get_effective_rule(
270
        my $effective_rule = $self->get_effective_rule_value(
247
            {
271
            {
248
                rule_name    => $rule,
272
                rule_name    => $rule,
249
                categorycode => $categorycode,
273
                categorycode => $categorycode,
Lines 252-258 sub get_effective_rules { Link Here
252
            }
276
            }
253
        );
277
        );
254
278
255
        $r->{$rule} = $effective_rule->rule_value if $effective_rule;
279
        $r->{$rule} = $effective_rule if defined $effective_rule;
256
    }
280
    }
257
281
258
    return $r;
282
    return $r;
Lines 331-336 sub set_rule { Link Here
331
        }
355
        }
332
    }
356
    }
333
357
358
    my $memory_cache = Koha::Cache::Memory::Lite->get_instance;
359
    my $cache_key = sprintf "CircRules:%s:%s:%s:%s", $rule_name // q{},
360
      $categorycode // q{}, $branchcode // q{}, $itemtype // q{};
361
362
    Koha::Cache::Memory::Lite->flush();
363
334
    return $rule;
364
    return $rule;
335
}
365
}
336
366
Lines 359-364 sub set_rules { Link Here
359
        push( @$rule_objects, $rule_object );
389
        push( @$rule_objects, $rule_object );
360
    }
390
    }
361
391
392
    Koha::Cache::Memory::Lite->flush();
362
    return $rule_objects;
393
    return $rule_objects;
363
}
394
}
364
395
(-)a/t/db_dependent/Circulation.t (-1 / +5 lines)
Lines 54-59 use Koha::Account::Lines; Link Here
54
use Koha::Account::Offsets;
54
use Koha::Account::Offsets;
55
use Koha::ActionLogs;
55
use Koha::ActionLogs;
56
use Koha::Notice::Messages;
56
use Koha::Notice::Messages;
57
use Koha::Cache::Memory::Lite;
57
58
58
sub set_userenv {
59
sub set_userenv {
59
    my ( $library ) = @_;
60
    my ( $library ) = @_;
Lines 827-832 subtest "CanBookBeRenewed tests" => sub { Link Here
827
    is( $renewokay, 0, 'Still should not be able to renew' );
828
    is( $renewokay, 0, 'Still should not be able to renew' );
828
    is( $error, 'on_reserve', 'returned code is on_reserve, auto_too_soon limit is overridden' );
829
    is( $error, 'on_reserve', 'returned code is on_reserve, auto_too_soon limit is overridden' );
829
    $dbh->do('UPDATE circulation_rules SET rule_value = 0 where rule_name = "norenewalbefore"');
830
    $dbh->do('UPDATE circulation_rules SET rule_value = 0 where rule_name = "norenewalbefore"');
831
    Koha::Cache::Memory::Lite->flush();
830
    ( $renewokay, $error ) = CanBookBeRenewed( $renewing_borrowernumber, $item_4->itemnumber, 1 );
832
    ( $renewokay, $error ) = CanBookBeRenewed( $renewing_borrowernumber, $item_4->itemnumber, 1 );
831
    is( $renewokay, 0, 'Still should not be able to renew' );
833
    is( $renewokay, 0, 'Still should not be able to renew' );
832
    is( $error, 'on_reserve', 'returned code is on_reserve, auto_renew only happens if not on reserve' );
834
    is( $error, 'on_reserve', 'returned code is on_reserve, auto_renew only happens if not on reserve' );
Lines 874-879 subtest "CanBookBeRenewed tests" => sub { Link Here
874
    # Change policy so that loans can only be renewed exactly on due date (0 days prior to due date)
876
    # Change policy so that loans can only be renewed exactly on due date (0 days prior to due date)
875
    # and test automatic renewal again
877
    # and test automatic renewal again
876
    $dbh->do(q{UPDATE circulation_rules SET rule_value = '0' WHERE rule_name = 'norenewalbefore'});
878
    $dbh->do(q{UPDATE circulation_rules SET rule_value = '0' WHERE rule_name = 'norenewalbefore'});
879
    Koha::Cache::Memory::Lite->flush();
877
    ( $renewokay, $error ) =
880
    ( $renewokay, $error ) =
878
      CanBookBeRenewed( $renewing_borrowernumber, $item_4->itemnumber );
881
      CanBookBeRenewed( $renewing_borrowernumber, $item_4->itemnumber );
879
    is( $renewokay, 0, 'Bug 14101: Cannot renew, renewal is automatic and premature' );
882
    is( $renewokay, 0, 'Bug 14101: Cannot renew, renewal is automatic and premature' );
Lines 890-895 subtest "CanBookBeRenewed tests" => sub { Link Here
890
    # Change policy so that loans can be renewed 99 days prior to the due date
893
    # Change policy so that loans can be renewed 99 days prior to the due date
891
    # and test automatic renewal again
894
    # and test automatic renewal again
892
    $dbh->do(q{UPDATE circulation_rules SET rule_value = '99' WHERE rule_name = 'norenewalbefore'});
895
    $dbh->do(q{UPDATE circulation_rules SET rule_value = '99' WHERE rule_name = 'norenewalbefore'});
896
    Koha::Cache::Memory::Lite->flush();
893
    ( $renewokay, $error ) =
897
    ( $renewokay, $error ) =
894
      CanBookBeRenewed( $renewing_borrowernumber, $item_4->itemnumber );
898
      CanBookBeRenewed( $renewing_borrowernumber, $item_4->itemnumber );
895
    is( $renewokay, 0, 'Bug 14101: Cannot renew, renewal is automatic' );
899
    is( $renewokay, 0, 'Bug 14101: Cannot renew, renewal is automatic' );
Lines 1233-1238 subtest "CanBookBeRenewed tests" => sub { Link Here
1233
        $dbh->do(q{UPDATE circulation_rules SET rule_value = '10' WHERE rule_name = 'norenewalbefore'});
1237
        $dbh->do(q{UPDATE circulation_rules SET rule_value = '10' WHERE rule_name = 'norenewalbefore'});
1234
        $dbh->do(q{UPDATE circulation_rules SET rule_value = '15' WHERE rule_name = 'no_auto_renewal_after'});
1238
        $dbh->do(q{UPDATE circulation_rules SET rule_value = '15' WHERE rule_name = 'no_auto_renewal_after'});
1235
        $dbh->do(q{UPDATE circulation_rules SET rule_value = NULL WHERE rule_name = 'no_auto_renewal_after_hard_limit'});
1239
        $dbh->do(q{UPDATE circulation_rules SET rule_value = NULL WHERE rule_name = 'no_auto_renewal_after_hard_limit'});
1240
        Koha::Cache::Memory::Lite->flush();
1236
        Koha::CirculationRules->set_rules(
1241
        Koha::CirculationRules->set_rules(
1237
            {
1242
            {
1238
                categorycode => undef,
1243
                categorycode => undef,
1239
- 

Return to bug 29623