@@ -, +, @@ C4::Context->yaml_preference $ ktd --shell k$ prove t/db_dependent/Circulation* --- C4/Circulation.pm | 60 +++++++++++++++++------------------------------ C4/Context.pm | 2 +- 2 files changed, 22 insertions(+), 40 deletions(-) --- a/C4/Circulation.pm +++ a/C4/Circulation.pm @@ -21,7 +21,6 @@ package C4::Circulation; use Modern::Perl; use DateTime; use POSIX qw( floor ); -use YAML::XS; use Encode; use C4::Context; @@ -1798,21 +1797,12 @@ sub AddIssue { } } - my $yaml = C4::Context->preference('UpdateNotForLoanStatusOnCheckout'); - if ($yaml) { - $yaml = "$yaml\n\n"; - - my $rules; - eval { $rules = YAML::XS::Load(Encode::encode_utf8($yaml)); }; - if ($@) { - warn "Unable to parse UpdateNotForLoanStatusOnCheckout syspref : $@"; - } - else { - foreach my $key ( keys %$rules ) { - if ( $item_object->notforloan eq $key ) { - $item_object->notforloan($rules->{$key})->store({ log_action => 0, skip_record_index => 1 }); - last; - } + my $rules = C4::Context->yaml_preference('UpdateNotForLoanStatusOnCheckout'); + if ($rules) { + foreach my $key ( keys %$rules ) { + if ( $item_object->notforloan eq $key ) { + $item_object->notforloan($rules->{$key})->store({ log_action => 0, skip_record_index => 1 }); + last; } } } @@ -2215,30 +2205,22 @@ sub AddReturn { $messages->{ $loc_msg_key } = $loc_messages->{ $loc_msg_key }; } - my $yaml = C4::Context->preference('UpdateNotForLoanStatusOnCheckin'); - if ($yaml) { - $yaml = "$yaml\n\n"; # YAML is anal on ending \n. Surplus does not hurt - my $rules; - eval { $rules = YAML::XS::Load(Encode::encode_utf8($yaml)); }; - if ($@) { - warn "Unable to parse UpdateNotForLoanStatusOnCheckin syspref : $@"; - } - else { - if ( defined $rules->{$item->itype} ) { - foreach my $notloan_rule_key (keys %{ $rules->{$item->itype}} ) { - if ( $item->notforloan eq $notloan_rule_key ) { - $messages->{'NotForLoanStatusUpdated'} = { from => $item->notforloan, to => $rules->{$item->itype}->{$notloan_rule_key} }; - $item->notforloan($rules->{$item->itype}->{$notloan_rule_key})->store({ log_action => 0, skip_record_index => 1, skip_holds_queue => 1 }); - last; - } + my $rules = C4::Context->yaml_preference('UpdateNotForLoanStatusOnCheckin'); + if ($rules) { + if ( defined $rules->{$item->itype} ) { + foreach my $notloan_rule_key (keys %{ $rules->{$item->itype}} ) { + if ( $item->notforloan eq $notloan_rule_key ) { + $messages->{'NotForLoanStatusUpdated'} = { from => $item->notforloan, to => $rules->{$item->itype}->{$notloan_rule_key} }; + $item->notforloan($rules->{$item->itype}->{$notloan_rule_key})->store({ log_action => 0, skip_record_index => 1, skip_holds_queue => 1 }); + last; } - } elsif ( defined $rules->{'_ALL_'} ) { - foreach my $notloan_rule_key (keys %{ $rules->{'_ALL_'}} ) { - if ( $item->notforloan eq $notloan_rule_key ) { - $messages->{'NotForLoanStatusUpdated'} = { from => $item->notforloan, to => $rules->{'_ALL_'}->{$notloan_rule_key} }; - $item->notforloan($rules->{'_ALL_'}->{$notloan_rule_key})->store({ log_action => 0, skip_record_index => 1, skip_holds_queue => 1 }); - last; - } + } + } elsif ( defined $rules->{'_ALL_'} ) { + foreach my $notloan_rule_key (keys %{ $rules->{'_ALL_'}} ) { + if ( $item->notforloan eq $notloan_rule_key ) { + $messages->{'NotForLoanStatusUpdated'} = { from => $item->notforloan, to => $rules->{'_ALL_'}->{$notloan_rule_key} }; + $item->notforloan($rules->{'_ALL_'}->{$notloan_rule_key})->store({ log_action => 0, skip_record_index => 1, skip_holds_queue => 1 }); + last; } } } --- a/C4/Context.pm +++ a/C4/Context.pm @@ -342,7 +342,7 @@ the value cannot be properly decoded as YAML. sub yaml_preference { my ( $self, $preference ) = @_; - my $yaml = eval { YAML::XS::Load( Encode::encode_utf8( $self->preference( $preference ) ) ); }; + my $yaml = eval { YAML::XS::Load( Encode::encode_utf8( $self->preference( $preference ) // '' ) ); }; if ($@) { warn "Unable to parse $preference syspref : $@"; return; --