From 273731f2edbe08b7f7bb9b317a516731d927b5f5 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 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Signed-off-by: Joonas Kylmälä --- Koha/CirculationRules.pm | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/Koha/CirculationRules.pm b/Koha/CirculationRules.pm index 5042e6f55d..92a20e65c8 100644 --- a/Koha/CirculationRules.pm +++ b/Koha/CirculationRules.pm @@ -322,14 +322,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.11.0