From 185016a1f0ce0cb197d88bcfe8d3876b167475c5 Mon Sep 17 00:00:00 2001 From: Lari Taskula Date: Sat, 11 Apr 2020 17:58:06 +0000 Subject: [PATCH] Bug 25112: Make set_rules() handle rule scopes Koha::CirculationRules->set_rules is currently too complicated to use. Right now, in order to specify multiple rules at once, they must all be rules that accept the same set of scopes. Otherwise we can get this type of errors: 1/9 set_rule cannot set 'holds_per_record' for a 'checkout_type'! at t/db_dependent/Circulation/GetHardDueDate.t line 215. Validating scopes at set_rule() is good, but set_rules() should examine each rule and pass the correct scope to set_rule() instead of passing all scopes to every rule like it is doing now. To test: 1. prove t/db_dependent/Koha/CirculationRules.t 2. Observe success Sponsored-by: The National Library of Finland --- Koha/CirculationRules.pm | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/Koha/CirculationRules.pm b/Koha/CirculationRules.pm index 790f30498d..5c75d8bce2 100644 --- a/Koha/CirculationRules.pm +++ b/Koha/CirculationRules.pm @@ -325,14 +325,16 @@ sub set_rule { sub set_rules { my ( $self, $params ) = @_; - my %set_params; - $set_params{branchcode} = $params->{branchcode} if exists $params->{branchcode}; - $set_params{categorycode} = $params->{categorycode} if exists $params->{categorycode}; - $set_params{itemtype} = $params->{itemtype} if exists $params->{itemtype}; my $rules = $params->{rules}; my $rule_objects = []; while ( my ( $rule_name, $rule_value ) = each %$rules ) { + my %set_params; + foreach my $set_param ( values @{$RULE_KINDS->{$rule_name}->{scope}} ) { + if ( exists $params->{$set_param} ) { + $set_params{$set_param} = $params->{$set_param}; + } + } my $rule_object = Koha::CirculationRules->set_rule( { %set_params, -- 2.17.1