my $orig_due = C4::Circulation::CalcDateDue( $issuedate, $itype, $branchcode, $patron->unblessed );
- my $rule = Koha::CirculationRules->get_effective_rule(
+ my $rule = Koha::CirculationRules->get_effective_rule_value(
{
categorycode => $patron->categorycode,
itemtype => $item->effective_itemtype,
);
my $duration;
- if ( defined($rule) && $rule->rule_value ne '' ){
+ if ( defined($rule) && $rule ne '' ){
# overrides decreaseLoanHighHoldsDuration syspref
- $duration = $rule->rule_value;
+ $duration = $rule;
} else {
$duration = C4::Context->preference('decreaseLoanHighHoldsDuration');
}
# If automatic renewal wasn't selected while issuing, set the value according to the issuing rule.
unless ($auto_renew) {
- my $rule = Koha::CirculationRules->get_effective_rule(
+ my $rule = Koha::CirculationRules->get_effective_rule_value(
{
categorycode => $borrower->{categorycode},
itemtype => $item_object->effective_itemtype,
}
);
- $auto_renew = $rule->rule_value if $rule;
+ $auto_renew = $rule if defined $rule && $rule ne '';
}
my $issue_attributes = {
use Koha::Exceptions;
use Koha::CirculationRule;
+use Koha::Caches;
+use Koha::Cache::Memory::Lite;
use base qw(Koha::Objects);
return $rule;
}
+sub get_effective_rule_value {
+ my ( $self, $params ) = @_;
+
+ my $rule_name = $params->{rule_name};
+ my $categorycode = $params->{categorycode};
+ my $itemtype = $params->{itemtype};
+ my $branchcode = $params->{branchcode};
+
+ my $memory_cache = Koha::Cache::Memory::Lite->get_instance;
+ my $cache_key = sprintf "CircRules:%s:%s:%s:%s", $rule_name // q{},
+ $categorycode // q{}, $branchcode // q{}, $itemtype // q{};
+
+ my $cached = $memory_cache->get_from_cache($cache_key);
+ return $cached if $cached;
+
+ my $rule = $self->get_effective_rule($params);
+
+ my $value= $rule ? $rule->rule_value : undef;
+ $memory_cache->set_in_cache( $cache_key, $value );
+ return $value;
+}
+
=head3 get_effective_rules
=cut
my $r;
foreach my $rule (@$rules) {
- my $effective_rule = $self->get_effective_rule(
+ my $effective_rule = $self->get_effective_rule_value(
{
rule_name => $rule,
categorycode => $categorycode,
}
);
- $r->{$rule} = $effective_rule->rule_value if $effective_rule;
+ $r->{$rule} = $effective_rule if defined $effective_rule;
}
return $r;
}
}
+ my $memory_cache = Koha::Cache::Memory::Lite->get_instance;
+ my $cache_key = sprintf "CircRules:%s:%s:%s:%s", $rule_name // q{},
+ $categorycode // q{}, $branchcode // q{}, $itemtype // q{};
+
+ Koha::Cache::Memory::Lite->flush();
+
return $rule;
}
push( @$rule_objects, $rule_object );
}
+ Koha::Cache::Memory::Lite->flush();
return $rule_objects;
}
use Koha::Account::Offsets;
use Koha::ActionLogs;
use Koha::Notice::Messages;
+use Koha::Cache::Memory::Lite;
sub set_userenv {
my ( $library ) = @_;
is( $renewokay, 0, 'Still should not be able to renew' );
is( $error, 'on_reserve', 'returned code is on_reserve, auto_too_soon limit is overridden' );
$dbh->do('UPDATE circulation_rules SET rule_value = 0 where rule_name = "norenewalbefore"');
+ Koha::Cache::Memory::Lite->flush();
( $renewokay, $error ) = CanBookBeRenewed( $renewing_borrowernumber, $item_4->itemnumber, 1 );
is( $renewokay, 0, 'Still should not be able to renew' );
is( $error, 'on_reserve', 'returned code is on_reserve, auto_renew only happens if not on reserve' );
# Change policy so that loans can only be renewed exactly on due date (0 days prior to due date)
# and test automatic renewal again
$dbh->do(q{UPDATE circulation_rules SET rule_value = '0' WHERE rule_name = 'norenewalbefore'});
+ Koha::Cache::Memory::Lite->flush();
( $renewokay, $error, $info ) =
CanBookBeRenewed( $renewing_borrowernumber, $item_4->itemnumber );
is( $renewokay, 0, 'Bug 14101: Cannot renew, renewal is automatic and premature' );
# Change policy so that loans can be renewed 99 days prior to the due date
# and test automatic renewal again
$dbh->do(q{UPDATE circulation_rules SET rule_value = '99' WHERE rule_name = 'norenewalbefore'});
+ Koha::Cache::Memory::Lite->flush();
( $renewokay, $error ) =
CanBookBeRenewed( $renewing_borrowernumber, $item_4->itemnumber );
is( $renewokay, 0, 'Bug 14101: Cannot renew, renewal is automatic' );
$dbh->do(q{UPDATE circulation_rules SET rule_value = '10' WHERE rule_name = 'norenewalbefore'});
$dbh->do(q{UPDATE circulation_rules SET rule_value = '15' WHERE rule_name = 'no_auto_renewal_after'});
$dbh->do(q{UPDATE circulation_rules SET rule_value = NULL WHERE rule_name = 'no_auto_renewal_after_hard_limit'});
+ Koha::Cache::Memory::Lite->flush();
Koha::CirculationRules->set_rules(
{
categorycode => undef,