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

(-)a/C4/Circulation.pm (-5 / +5 lines)
Lines 1428-1434 sub checkHighHolds { Link Here
1428
1428
1429
        my $orig_due = C4::Circulation::CalcDateDue( $issuedate, $itype, $branchcode, $patron->unblessed );
1429
        my $orig_due = C4::Circulation::CalcDateDue( $issuedate, $itype, $branchcode, $patron->unblessed );
1430
1430
1431
        my $rule = Koha::CirculationRules->get_effective_rule(
1431
        my $rule = Koha::CirculationRules->get_effective_rule_value(
1432
            {
1432
            {
1433
                categorycode => $patron->categorycode,
1433
                categorycode => $patron->categorycode,
1434
                itemtype     => $item->effective_itemtype,
1434
                itemtype     => $item->effective_itemtype,
Lines 1438-1446 sub checkHighHolds { Link Here
1438
        );
1438
        );
1439
1439
1440
        my $duration;
1440
        my $duration;
1441
        if ( defined($rule) && $rule->rule_value ne '' ){
1441
        if ( defined($rule) && $rule ne '' ){
1442
            # overrides decreaseLoanHighHoldsDuration syspref
1442
            # overrides decreaseLoanHighHoldsDuration syspref
1443
            $duration = $rule->rule_value;
1443
            $duration = $rule;
1444
        } else {
1444
        } else {
1445
            $duration = C4::Context->preference('decreaseLoanHighHoldsDuration');
1445
            $duration = C4::Context->preference('decreaseLoanHighHoldsDuration');
1446
        }
1446
        }
Lines 1616-1622 sub AddIssue { Link Here
1616
1616
1617
            # If automatic renewal wasn't selected while issuing, set the value according to the issuing rule.
1617
            # If automatic renewal wasn't selected while issuing, set the value according to the issuing rule.
1618
            unless ($auto_renew) {
1618
            unless ($auto_renew) {
1619
                my $rule = Koha::CirculationRules->get_effective_rule(
1619
                my $rule = Koha::CirculationRules->get_effective_rule_value(
1620
                    {
1620
                    {
1621
                        categorycode => $borrower->{categorycode},
1621
                        categorycode => $borrower->{categorycode},
1622
                        itemtype     => $item_object->effective_itemtype,
1622
                        itemtype     => $item_object->effective_itemtype,
Lines 1625-1631 sub AddIssue { Link Here
1625
                    }
1625
                    }
1626
                );
1626
                );
1627
1627
1628
                $auto_renew = $rule->rule_value if $rule;
1628
                $auto_renew = $rule if defined $rule && $rule ne '';
1629
            }
1629
            }
1630
1630
1631
            my $issue_attributes = {
1631
            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 250-255 sub get_effective_rule { Link Here
250
    return $rule;
252
    return $rule;
251
}
253
}
252
254
255
sub get_effective_rule_value {
256
    my ( $self, $params ) = @_;
257
258
    my $rule_name    = $params->{rule_name};
259
    my $categorycode = $params->{categorycode};
260
    my $itemtype     = $params->{itemtype};
261
    my $branchcode   = $params->{branchcode};
262
263
    my $memory_cache = Koha::Cache::Memory::Lite->get_instance;
264
    my $cache_key = sprintf "CircRules:%s:%s:%s:%s", $rule_name // q{},
265
      $categorycode // q{}, $branchcode // q{}, $itemtype // q{};
266
267
    my $cached       = $memory_cache->get_from_cache($cache_key);
268
    return $cached if $cached;
269
270
    my $rule = $self->get_effective_rule($params);
271
272
    my $value= $rule ? $rule->rule_value : undef;
273
    $memory_cache->set_in_cache( $cache_key, $value );
274
    return $value;
275
}
276
253
=head3 get_effective_rules
277
=head3 get_effective_rules
254
278
255
=cut
279
=cut
Lines 264-270 sub get_effective_rules { Link Here
264
288
265
    my $r;
289
    my $r;
266
    foreach my $rule (@$rules) {
290
    foreach my $rule (@$rules) {
267
        my $effective_rule = $self->get_effective_rule(
291
        my $effective_rule = $self->get_effective_rule_value(
268
            {
292
            {
269
                rule_name    => $rule,
293
                rule_name    => $rule,
270
                categorycode => $categorycode,
294
                categorycode => $categorycode,
Lines 273-279 sub get_effective_rules { Link Here
273
            }
297
            }
274
        );
298
        );
275
299
276
        $r->{$rule} = $effective_rule->rule_value if $effective_rule;
300
        $r->{$rule} = $effective_rule if defined $effective_rule;
277
    }
301
    }
278
302
279
    return $r;
303
    return $r;
Lines 352-357 sub set_rule { Link Here
352
        }
376
        }
353
    }
377
    }
354
378
379
    my $memory_cache = Koha::Cache::Memory::Lite->get_instance;
380
    my $cache_key = sprintf "CircRules:%s:%s:%s:%s", $rule_name // q{},
381
      $categorycode // q{}, $branchcode // q{}, $itemtype // q{};
382
383
    Koha::Cache::Memory::Lite->flush();
384
355
    return $rule;
385
    return $rule;
356
}
386
}
357
387
Lines 380-385 sub set_rules { Link Here
380
        push( @$rule_objects, $rule_object );
410
        push( @$rule_objects, $rule_object );
381
    }
411
    }
382
412
413
    Koha::Cache::Memory::Lite->flush();
383
    return $rule_objects;
414
    return $rule_objects;
384
}
415
}
385
416
(-)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 830-835 subtest "CanBookBeRenewed tests" => sub { Link Here
830
    is( $renewokay, 0, 'Still should not be able to renew' );
831
    is( $renewokay, 0, 'Still should not be able to renew' );
831
    is( $error, 'on_reserve', 'returned code is on_reserve, auto_too_soon limit is overridden' );
832
    is( $error, 'on_reserve', 'returned code is on_reserve, auto_too_soon limit is overridden' );
832
    $dbh->do('UPDATE circulation_rules SET rule_value = 0 where rule_name = "norenewalbefore"');
833
    $dbh->do('UPDATE circulation_rules SET rule_value = 0 where rule_name = "norenewalbefore"');
834
    Koha::Cache::Memory::Lite->flush();
833
    ( $renewokay, $error ) = CanBookBeRenewed( $renewing_borrowernumber, $item_4->itemnumber, 1 );
835
    ( $renewokay, $error ) = CanBookBeRenewed( $renewing_borrowernumber, $item_4->itemnumber, 1 );
834
    is( $renewokay, 0, 'Still should not be able to renew' );
836
    is( $renewokay, 0, 'Still should not be able to renew' );
835
    is( $error, 'on_reserve', 'returned code is on_reserve, auto_renew only happens if not on reserve' );
837
    is( $error, 'on_reserve', 'returned code is on_reserve, auto_renew only happens if not on reserve' );
Lines 880-885 subtest "CanBookBeRenewed tests" => sub { Link Here
880
    # Change policy so that loans can only be renewed exactly on due date (0 days prior to due date)
882
    # Change policy so that loans can only be renewed exactly on due date (0 days prior to due date)
881
    # and test automatic renewal again
883
    # and test automatic renewal again
882
    $dbh->do(q{UPDATE circulation_rules SET rule_value = '0' WHERE rule_name = 'norenewalbefore'});
884
    $dbh->do(q{UPDATE circulation_rules SET rule_value = '0' WHERE rule_name = 'norenewalbefore'});
885
    Koha::Cache::Memory::Lite->flush();
883
    ( $renewokay, $error, $info ) =
886
    ( $renewokay, $error, $info ) =
884
      CanBookBeRenewed( $renewing_borrowernumber, $item_4->itemnumber );
887
      CanBookBeRenewed( $renewing_borrowernumber, $item_4->itemnumber );
885
    is( $renewokay, 0, 'Bug 14101: Cannot renew, renewal is automatic and premature' );
888
    is( $renewokay, 0, 'Bug 14101: Cannot renew, renewal is automatic and premature' );
Lines 898-903 subtest "CanBookBeRenewed tests" => sub { Link Here
898
    # Change policy so that loans can be renewed 99 days prior to the due date
901
    # Change policy so that loans can be renewed 99 days prior to the due date
899
    # and test automatic renewal again
902
    # and test automatic renewal again
900
    $dbh->do(q{UPDATE circulation_rules SET rule_value = '99' WHERE rule_name = 'norenewalbefore'});
903
    $dbh->do(q{UPDATE circulation_rules SET rule_value = '99' WHERE rule_name = 'norenewalbefore'});
904
    Koha::Cache::Memory::Lite->flush();
901
    ( $renewokay, $error ) =
905
    ( $renewokay, $error ) =
902
      CanBookBeRenewed( $renewing_borrowernumber, $item_4->itemnumber );
906
      CanBookBeRenewed( $renewing_borrowernumber, $item_4->itemnumber );
903
    is( $renewokay, 0, 'Bug 14101: Cannot renew, renewal is automatic' );
907
    is( $renewokay, 0, 'Bug 14101: Cannot renew, renewal is automatic' );
Lines 1241-1246 subtest "CanBookBeRenewed tests" => sub { Link Here
1241
        $dbh->do(q{UPDATE circulation_rules SET rule_value = '10' WHERE rule_name = 'norenewalbefore'});
1245
        $dbh->do(q{UPDATE circulation_rules SET rule_value = '10' WHERE rule_name = 'norenewalbefore'});
1242
        $dbh->do(q{UPDATE circulation_rules SET rule_value = '15' WHERE rule_name = 'no_auto_renewal_after'});
1246
        $dbh->do(q{UPDATE circulation_rules SET rule_value = '15' WHERE rule_name = 'no_auto_renewal_after'});
1243
        $dbh->do(q{UPDATE circulation_rules SET rule_value = NULL WHERE rule_name = 'no_auto_renewal_after_hard_limit'});
1247
        $dbh->do(q{UPDATE circulation_rules SET rule_value = NULL WHERE rule_name = 'no_auto_renewal_after_hard_limit'});
1248
        Koha::Cache::Memory::Lite->flush();
1244
        Koha::CirculationRules->set_rules(
1249
        Koha::CirculationRules->set_rules(
1245
            {
1250
            {
1246
                categorycode => undef,
1251
                categorycode => undef,
1247
- 

Return to bug 29623