From 342d46e611ec294ad745b11d922560a0e66fe6d6 Mon Sep 17 00:00:00 2001 From: David Gustafsson Date: Thu, 29 Sep 2022 17:18:40 +0200 Subject: [PATCH] Bug 32478: Remove Koha::Config::SysPref->find since bypasses cache get_yaml_pref_hash also allows invalid YAML and only parses a limited subset so remove this method to avoid future issues. To test): Since tests already exists for C4::Context->yaml_preference and this is a trivial change, do we really need a test plan for this? Sponsored-by: Gothenburg University Library Signed-off-by: Nick Clemens Signed-off-by: Marcel de Rooy Signed-off-by: Tomas Cohen Arazi --- C4/Circulation.pm | 2 +- Koha/Config/SysPref.pm | 28 --------------------------- Koha/Item.pm | 3 +-- t/db_dependent/Koha/Config/SysPrefs.t | 23 +--------------------- 4 files changed, 3 insertions(+), 53 deletions(-) diff --git a/C4/Circulation.pm b/C4/Circulation.pm index ecd969235a..d2009981ae 100644 --- a/C4/Circulation.pm +++ b/C4/Circulation.pm @@ -2137,7 +2137,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 = Koha::Config::SysPrefs->find('UpdateItemLocationOnCheckin')->get_yaml_pref_hash(); + my $update_loc_rules = C4::Context->yaml_preference('UpdateItemLocationOnCheckin'); 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 dd743f8ef2..be04b3d504 100644 --- a/Koha/Config/SysPref.pm +++ b/Koha/Config/SysPref.pm @@ -36,34 +36,6 @@ Koha::Config::SysPref - Koha System Preference Object class =cut -=head3 get_yaml_pref_hash - -Turn a pref defined via YAML as a hash - -=cut - -sub get_yaml_pref_hash { - my ( $self ) = @_; - return if !defined( $self ); - - # 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; - 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; -} - =head3 store diff --git a/Koha/Item.pm b/Koha/Item.pm index fddc92bab9..06f8bcbdff 100644 --- a/Koha/Item.pm +++ b/Koha/Item.pm @@ -2064,8 +2064,7 @@ rules set in the ItemsDeniedRenewal system preference. sub is_denied_renewal { my ( $self ) = @_; - - my $denyingrules = Koha::Config::SysPrefs->find('ItemsDeniedRenewal')->get_yaml_pref_hash(); + my $denyingrules = C4::Context->yaml_preference('ItemsDeniedRenewal'); return 0 unless $denyingrules; foreach my $field (keys %$denyingrules) { my $val = $self->$field; diff --git a/t/db_dependent/Koha/Config/SysPrefs.t b/t/db_dependent/Koha/Config/SysPrefs.t index 7fe975b338..15ca9ff9db 100755 --- a/t/db_dependent/Koha/Config/SysPrefs.t +++ b/t/db_dependent/Koha/Config/SysPrefs.t @@ -16,7 +16,7 @@ # along with Koha; if not, see . use Modern::Perl; -use Test::More tests => 4; +use Test::More tests => 3; use t::lib::Mocks; use t::lib::TestBuilder; @@ -43,25 +43,4 @@ is( $retrieved_pref->value, $new_pref->value, 'Find a pref by variable should re $retrieved_pref->delete; is( Koha::Config::SysPrefs->search->count, $nb_of_prefs, 'Delete should have deleted the pref' ); -subtest 'get_yaml_pref_hash' => sub { - - plan tests => 1; - - my $the_pref = Koha::Config::SysPrefs->find({variable=>'ItemsDeniedRenewal'}); - t::lib::Mocks::mock_preference('ItemsDeniedRenewal', q{ - nulled: [NULL,''] - this: [just_that] - multi_this: [that,another] - }); - - my $expected_hash = { - nulled => [undef,""], - this => ['just_that'], - multi_this => ['that','another'], - }; - my $got_hash = $the_pref->get_yaml_pref_hash(); - is_deeply($got_hash,$expected_hash,"Pref fetched and converted correctly"); - -}; - $schema->storage->txn_rollback; -- 2.39.5