From 5dbf79681f9f8485e47a2a325442ca0c9247f9db Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Fri, 5 Feb 2021 12:01:38 +0100 Subject: [PATCH] Bug 27154: Remove Koha::Util::SystemPreferences On bug 15494, the same method "get_yaml_pref_hash" has been added to two modules, Koha/Config/SysPref.pm and Koha/Util/SystemPreferences.pm We only need the one from Koha::Config::SysPref and remove the whole Koha::Util::SystemPreferences module. Test plan: prove t/db_dependent/Circulation/issue.t must return green Signed-off-by: Kyle M Hall Signed-off-by: Katrin Fischer Signed-off-by: Jonathan Druart (cherry picked from commit ac11405321ae3e5fdd72701ddb41b62675e42c97) Signed-off-by: Fridolin Somers --- C4/Circulation.pm | 4 +- Koha/Config/SysPref.pm | 4 +- Koha/Util/SystemPreferences.pm | 69 ---------------------------------- 3 files changed, 5 insertions(+), 72 deletions(-) delete mode 100644 Koha/Util/SystemPreferences.pm diff --git a/C4/Circulation.pm b/C4/Circulation.pm index 5e73c388e2..37ae394725 100644 --- a/C4/Circulation.pm +++ b/C4/Circulation.pm @@ -56,7 +56,7 @@ use Koha::Account::Lines; use Koha::Account::Offsets; use Koha::Config::SysPrefs; use Koha::Charges::Fees; -use Koha::Util::SystemPreferences; +use Koha::Config::SysPref; use Koha::Checkouts::ReturnClaims; use Koha::SearchEngine::Indexer; use Carp; @@ -1986,7 +1986,7 @@ sub AddReturn { my $borrowernumber = $patron ? $patron->borrowernumber : undef; # we don't know if we had a borrower or not my $patron_unblessed = $patron ? $patron->unblessed : {}; - my $update_loc_rules = get_yaml_pref_hash('UpdateItemLocationOnCheckin'); + my $update_loc_rules = Koha::Config::SysPrefs->find('UpdateItemLocationOnCheckin')->get_yaml_pref_hash(); map { $update_loc_rules->{$_} = $update_loc_rules->{$_}[0] } keys %$update_loc_rules; #We can only move to one location so we flatten the arrays if ($update_loc_rules) { if (defined $update_loc_rules->{_ALL_}) { diff --git a/Koha/Config/SysPref.pm b/Koha/Config/SysPref.pm index 0793cb4547..1775160cb5 100644 --- a/Koha/Config/SysPref.pm +++ b/Koha/Config/SysPref.pm @@ -47,7 +47,9 @@ sub get_yaml_pref_hash { my ( $self ) = @_; return if !defined( $self ); - my @lines = split /\n/, $self->value//''; + # We want to use C4::Context->preference in any cases + # It's cached, and mock_preference still works from tests + my @lines = split /\n/, C4::Context->preference($self->variable) // ''; my $pref_as_hash; foreach my $line (@lines){ my ($field,$array) = split /:/, $line; diff --git a/Koha/Util/SystemPreferences.pm b/Koha/Util/SystemPreferences.pm deleted file mode 100644 index cb054cf9ff..0000000000 --- a/Koha/Util/SystemPreferences.pm +++ /dev/null @@ -1,69 +0,0 @@ -package Koha::Util::SystemPreferences; - -# Copyright 2018 Koha Development Team -# -# This file is part of Koha. -# -# Koha is free software; you can redistribute it and/or modify it -# under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 3 of the License, or -# (at your option) any later version. -# -# Koha is distributed in the hope that it will be useful, but -# WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with Koha; if not, see . - -use Modern::Perl; - -use parent qw( Exporter ); - -our @EXPORT = qw( - get_yaml_pref_hash -); - -=head1 NAME - -Koha::Util::SystemPreferences - utility class with System Preference routines - -=head1 METHODS - -=head2 get_yaml_pref_hash - -Turn a pref defined via YAML as a hash - -=cut - -sub get_yaml_pref_hash { - my ( $pref ) = @_; - return if !defined( $pref ); - - my @lines = split /\n/, C4::Context->preference($pref)//''; - my $pref_as_hash; - foreach my $line (@lines){ - my ($field,$array) = split /:/, $line; - next if !$array; - $field =~ s/^\s*|\s*$//g; - $array =~ s/[ [\]\r]//g; - my @array = split /,/, $array; - @array = map { $_ eq '""' || $_ eq "''" ? '' : $_ } @array; - @array = map { $_ eq 'NULL' ? undef : $_ } @array; - $pref_as_hash->{$field} = \@array; - } - - return $pref_as_hash; -} - -1; -__END__ - -=head1 AUTHOR - -Koha Development Team - -Nick Clemens - -=cut -- 2.39.5