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

(-)a/C4/Circulation.pm (-5 / +5 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 = {
(-)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 892-897 subtest "CanBookBeRenewed tests" => sub { Link Here
892
    # Change policy so that loans can only be renewed exactly on due date (0 days prior to due date)
894
    # Change policy so that loans can only be renewed exactly on due date (0 days prior to due date)
893
    # and test automatic renewal again
895
    # and test automatic renewal again
894
    $dbh->do(q{UPDATE circulation_rules SET rule_value = '0' WHERE rule_name = 'norenewalbefore'});
896
    $dbh->do(q{UPDATE circulation_rules SET rule_value = '0' WHERE rule_name = 'norenewalbefore'});
897
    Koha::Cache::Memory::Lite->flush();
895
    ( $renewokay, $error ) =
898
    ( $renewokay, $error ) =
896
      CanBookBeRenewed( $renewing_borrowernumber, $item_4->itemnumber );
899
      CanBookBeRenewed( $renewing_borrowernumber, $item_4->itemnumber );
897
    is( $renewokay, 0, 'Bug 14101: Cannot renew, renewal is automatic and premature' );
900
    is( $renewokay, 0, 'Bug 14101: Cannot renew, renewal is automatic and premature' );
Lines 908-913 subtest "CanBookBeRenewed tests" => sub { Link Here
908
    # Change policy so that loans can be renewed 99 days prior to the due date
911
    # Change policy so that loans can be renewed 99 days prior to the due date
909
    # and test automatic renewal again
912
    # and test automatic renewal again
910
    $dbh->do(q{UPDATE circulation_rules SET rule_value = '99' WHERE rule_name = 'norenewalbefore'});
913
    $dbh->do(q{UPDATE circulation_rules SET rule_value = '99' WHERE rule_name = 'norenewalbefore'});
914
    Koha::Cache::Memory::Lite->flush();
911
    ( $renewokay, $error ) =
915
    ( $renewokay, $error ) =
912
      CanBookBeRenewed( $renewing_borrowernumber, $item_4->itemnumber );
916
      CanBookBeRenewed( $renewing_borrowernumber, $item_4->itemnumber );
913
    is( $renewokay, 0, 'Bug 14101: Cannot renew, renewal is automatic' );
917
    is( $renewokay, 0, 'Bug 14101: Cannot renew, renewal is automatic' );
Lines 1251-1256 subtest "CanBookBeRenewed tests" => sub { Link Here
1251
        $dbh->do(q{UPDATE circulation_rules SET rule_value = '10' WHERE rule_name = 'norenewalbefore'});
1255
        $dbh->do(q{UPDATE circulation_rules SET rule_value = '10' WHERE rule_name = 'norenewalbefore'});
1252
        $dbh->do(q{UPDATE circulation_rules SET rule_value = '15' WHERE rule_name = 'no_auto_renewal_after'});
1256
        $dbh->do(q{UPDATE circulation_rules SET rule_value = '15' WHERE rule_name = 'no_auto_renewal_after'});
1253
        $dbh->do(q{UPDATE circulation_rules SET rule_value = NULL WHERE rule_name = 'no_auto_renewal_after_hard_limit'});
1257
        $dbh->do(q{UPDATE circulation_rules SET rule_value = NULL WHERE rule_name = 'no_auto_renewal_after_hard_limit'});
1258
        Koha::Cache::Memory::Lite->flush();
1254
        Koha::CirculationRules->set_rules(
1259
        Koha::CirculationRules->set_rules(
1255
            {
1260
            {
1256
                categorycode => undef,
1261
                categorycode => undef,
1257
- 

Return to bug 29623