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

(-)a/C4/Circulation.pm (-5 / +5 lines)
Lines 1427-1433 sub checkHighHolds { Link Here
1427
1427
1428
        my $orig_due = C4::Circulation::CalcDateDue( $issuedate, $itype, $branchcode, $patron->unblessed );
1428
        my $orig_due = C4::Circulation::CalcDateDue( $issuedate, $itype, $branchcode, $patron->unblessed );
1429
1429
1430
        my $rule = Koha::CirculationRules->get_effective_rule(
1430
        my $rule = Koha::CirculationRules->get_effective_rule_value(
1431
            {
1431
            {
1432
                categorycode => $patron->categorycode,
1432
                categorycode => $patron->categorycode,
1433
                itemtype     => $item->effective_itemtype,
1433
                itemtype     => $item->effective_itemtype,
Lines 1437-1445 sub checkHighHolds { Link Here
1437
        );
1437
        );
1438
1438
1439
        my $duration;
1439
        my $duration;
1440
        if ( defined($rule) && $rule->rule_value ne '' ){
1440
        if ( defined($rule) && $rule ne '' ){
1441
            # overrides decreaseLoanHighHoldsDuration syspref
1441
            # overrides decreaseLoanHighHoldsDuration syspref
1442
            $duration = $rule->rule_value;
1442
            $duration = $rule;
1443
        } else {
1443
        } else {
1444
            $duration = C4::Context->preference('decreaseLoanHighHoldsDuration');
1444
            $duration = C4::Context->preference('decreaseLoanHighHoldsDuration');
1445
        }
1445
        }
Lines 1615-1621 sub AddIssue { Link Here
1615
1615
1616
            # If automatic renewal wasn't selected while issuing, set the value according to the issuing rule.
1616
            # If automatic renewal wasn't selected while issuing, set the value according to the issuing rule.
1617
            unless ($auto_renew) {
1617
            unless ($auto_renew) {
1618
                my $rule = Koha::CirculationRules->get_effective_rule(
1618
                my $rule = Koha::CirculationRules->get_effective_rule_value(
1619
                    {
1619
                    {
1620
                        categorycode => $borrower->{categorycode},
1620
                        categorycode => $borrower->{categorycode},
1621
                        itemtype     => $item_object->effective_itemtype,
1621
                        itemtype     => $item_object->effective_itemtype,
Lines 1624-1630 sub AddIssue { Link Here
1624
                    }
1624
                    }
1625
                );
1625
                );
1626
1626
1627
                $auto_renew = $rule->rule_value if $rule;
1627
                $auto_renew = $rule if defined $rule && $rule ne '';
1628
            }
1628
            }
1629
1629
1630
            my $issue_attributes = {
1630
            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 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