Bugzilla – Attachment 141606 Details for
Bug 31735
Avoid re-fetching objects from database by passing them down instead of object ids
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 31735: Remove Koha::Config::SysPref->find since bypasses cache
Bug-31735-Remove-KohaConfigSysPref-find-since-bypa.patch (text/plain), 4.07 KB, created by
David Gustafsson
on 2022-10-11 13:34:46 UTC
(
hide
)
Description:
Bug 31735: Remove Koha::Config::SysPref->find since bypasses cache
Filename:
MIME Type:
Creator:
David Gustafsson
Created:
2022-10-11 13:34:46 UTC
Size:
4.07 KB
patch
obsolete
>From f5fa72de140b93e57240bd2aad0ec16f6aae03c1 Mon Sep 17 00:00:00 2001 >From: David Gustafsson <david.gustafsson@ub.gu.se> >Date: Thu, 29 Sep 2022 17:18:40 +0200 >Subject: [PATCH] Bug 31735: 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. >--- > C4/Circulation.pm | 4 ++-- > Koha/Config/SysPref.pm | 28 --------------------------- > t/db_dependent/Koha/Config/SysPrefs.t | 23 +--------------------- > 3 files changed, 3 insertions(+), 52 deletions(-) > >diff --git a/C4/Circulation.pm b/C4/Circulation.pm >index c7863db6ac..b6c1af0e8d 100644 >--- a/C4/Circulation.pm >+++ b/C4/Circulation.pm >@@ -2090,7 +2090,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_}) { >@@ -4421,7 +4421,7 @@ sub _item_denied_renewal { > my $item = $params->{item}; > return unless $item; > >- my $denyingrules = Koha::Config::SysPrefs->find('ItemsDeniedRenewal')->get_yaml_pref_hash(); >+ my $denyingrules = C4::Context->yaml_preference('ItemsDeniedRenewal'); > return unless $denyingrules; > foreach my $field (keys %$denyingrules) { > my $val = $item->$field; >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/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 <http://www.gnu.org/licenses>. > > 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.35.1
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 31735
:
141603
|
141604
|
141605
|
141606
|
141607
|
141608
|
141609
|
141610
|
141795
|
141796
|
141797
|
141798
|
141799
|
141800
|
141819
|
141820
|
141821
|
142865
|
142866
|
142867
|
142868
|
142869
|
142870
|
144628
|
144629
|
144630
|
144631
|
144632
|
144635
|
144721
|
144724
|
144784
|
144790
|
144791
|
144792
|
144798
|
144799
|
144800
|
144801
|
144802
|
144803
|
145028
|
145029
|
145030
|
145032
|
145033
|
145034
|
145035
|
146735
|
146736
|
146737
|
147124
|
147125
|
147126
|
147127
|
147128
|
147164
|
147165
|
147166
|
150611
|
150612
|
150613
|
150676
|
150677
|
150678
|
150699
|
150700
|
150701