Bugzilla – Attachment 193508 Details for
Bug 41891
Move C4::Context->preferences to a separate package
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 41891: Move C4::Context->preference to Koha::Context::Preferences->get
8b559c5.patch (text/plain), 3.87 KB, created by
Jonathan Druart
on 2026-02-20 10:24:33 UTC
(
hide
)
Description:
Bug 41891: Move C4::Context->preference to Koha::Context::Preferences->get
Filename:
MIME Type:
Creator:
Jonathan Druart
Created:
2026-02-20 10:24:33 UTC
Size:
3.87 KB
patch
obsolete
>From 8b559c53aa7fcb4e273863614b2376de69621828 Mon Sep 17 00:00:00 2001 >From: Jonathan Druart <jonathan.druart@bugs.koha-community.org> >Date: Fri, 20 Feb 2026 11:12:57 +0100 >Subject: [PATCH] Bug 41891: Move C4::Context->preference to > Koha::Context::Preferences->get > >--- > C4/Context.pm | 23 ++---------- > Koha/Context/Preferences.pm | 70 +++++++++++++++++++++++++++++++++++++ > 2 files changed, 72 insertions(+), 21 deletions(-) > create mode 100644 Koha/Context/Preferences.pm > >diff --git a/C4/Context.pm b/C4/Context.pm >index 6c51b3b862c..03b4da86910 100644 >--- a/C4/Context.pm >+++ b/C4/Context.pm >@@ -46,8 +46,8 @@ use ZOOM; > use List::MoreUtils qw(any); > > use Koha::Caches; >-use Koha::Config::SysPref; > use Koha::Config::SysPrefs; >+use Koha::Context::Preferences; > use Koha::Config; > use Koha; > >@@ -266,26 +266,7 @@ sub preference { > my $self = shift; > my $var = shift; # The system preference to return > >- return Encode::decode_utf8( $ENV{"OVERRIDE_SYSPREF_$var"} ) >- if defined $ENV{"OVERRIDE_SYSPREF_$var"}; >- >- $var = lc $var; >- >- if ($use_syspref_cache) { >- my $syspref_cache = Koha::Caches->get_instance('syspref'); >- my $cached_var = $syspref_cache->get_from_cache("syspref_$var"); >- return $cached_var if defined $cached_var; >- } >- >- my $syspref; >- eval { $syspref = Koha::Config::SysPrefs->find( lc $var ) }; >- my $value = $syspref ? $syspref->value() : undef; >- >- if ($use_syspref_cache) { >- my $syspref_cache = Koha::Caches->get_instance('syspref'); >- $syspref_cache->set_in_cache( "syspref_$var", $value ); >- } >- return $value; >+ return Koha::Context::Preferences->get_value( $var, { use_cache => $use_syspref_cache } ); > } > > =head2 yaml_preference >diff --git a/Koha/Context/Preferences.pm b/Koha/Context/Preferences.pm >new file mode 100644 >index 00000000000..de669e66d71 >--- /dev/null >+++ b/Koha/Context/Preferences.pm >@@ -0,0 +1,70 @@ >+package Koha::Context::Preferences; >+ >+# 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 <https://www.gnu.org/licenses>. >+ >+use Modern::Perl; >+ >+use Encode; >+ >+use Koha::Caches; >+use Koha::Config::SysPrefs; >+ >+=head1 NAME >+ >+Koha::Context::Preferences - Get system preferences without any other unecessary module dependencies >+ >+=head1 SYNOPSIS >+ >+ Koha::Context::Preferences->get_value($variable); >+ >+=head1 METHODS >+ >+=cut >+ >+=head3 set >+ >+Koha::Context::Preferences->get_value($variable) will return the effective value of the system preference >+ >+=cut >+ >+sub get_value { >+ my ( $class, $var, $params ) = @_; >+ $params ||= {}; >+ my $use_syspref_cache = $params->{use_syspref_cache} || 0; >+ >+ return Encode::decode_utf8( $ENV{"OVERRIDE_SYSPREF_$var"} ) >+ if defined $ENV{"OVERRIDE_SYSPREF_$var"}; >+ >+ $var = lc $var; >+ >+ if ($use_syspref_cache) { >+ my $syspref_cache = Koha::Caches->get_instance('syspref'); >+ my $cached_var = $syspref_cache->get_from_cache("syspref_$var"); >+ return $cached_var if defined $cached_var; >+ } >+ >+ my $syspref; >+ eval { $syspref = Koha::Config::SysPrefs->find( lc $var ) }; >+ my $value = $syspref ? $syspref->value() : undef; >+ >+ if ($use_syspref_cache) { >+ my $syspref_cache = Koha::Caches->get_instance('syspref'); >+ $syspref_cache->set_in_cache( "syspref_$var", $value ); >+ } >+ return $value; >+} >+ >+1; >-- >2.43.0 >
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 41891
: 193508