|
Line 0
Link Here
|
| 0 |
- |
1 |
package Koha::Context::Preferences; |
|
|
2 |
|
| 3 |
# This file is part of Koha. |
| 4 |
# |
| 5 |
# Koha is free software; you can redistribute it and/or modify it |
| 6 |
# under the terms of the GNU General Public License as published by |
| 7 |
# the Free Software Foundation; either version 3 of the License, or |
| 8 |
# (at your option) any later version. |
| 9 |
# |
| 10 |
# Koha is distributed in the hope that it will be useful, but |
| 11 |
# WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 |
# GNU General Public License for more details. |
| 14 |
# |
| 15 |
# You should have received a copy of the GNU General Public License |
| 16 |
# along with Koha; if not, see <https://www.gnu.org/licenses>. |
| 17 |
|
| 18 |
use Modern::Perl; |
| 19 |
|
| 20 |
use Encode; |
| 21 |
|
| 22 |
use Koha::Caches; |
| 23 |
use Koha::Config::SysPrefs; |
| 24 |
|
| 25 |
=head1 NAME |
| 26 |
|
| 27 |
Koha::Context::Preferences - Get system preferences without any other unecessary module dependencies |
| 28 |
|
| 29 |
=head1 SYNOPSIS |
| 30 |
|
| 31 |
Koha::Context::Preferences->get_value($variable); |
| 32 |
|
| 33 |
=head1 METHODS |
| 34 |
|
| 35 |
=cut |
| 36 |
|
| 37 |
=head3 set |
| 38 |
|
| 39 |
Koha::Context::Preferences->get_value($variable) will return the effective value of the system preference |
| 40 |
|
| 41 |
=cut |
| 42 |
|
| 43 |
sub get_value { |
| 44 |
my ( $class, $var, $params ) = @_; |
| 45 |
$params ||= {}; |
| 46 |
my $use_syspref_cache = $params->{use_syspref_cache} || 0; |
| 47 |
|
| 48 |
return Encode::decode_utf8( $ENV{"OVERRIDE_SYSPREF_$var"} ) |
| 49 |
if defined $ENV{"OVERRIDE_SYSPREF_$var"}; |
| 50 |
|
| 51 |
$var = lc $var; |
| 52 |
|
| 53 |
if ($use_syspref_cache) { |
| 54 |
my $syspref_cache = Koha::Caches->get_instance('syspref'); |
| 55 |
my $cached_var = $syspref_cache->get_from_cache("syspref_$var"); |
| 56 |
return $cached_var if defined $cached_var; |
| 57 |
} |
| 58 |
|
| 59 |
my $syspref; |
| 60 |
eval { $syspref = Koha::Config::SysPrefs->find( lc $var ) }; |
| 61 |
my $value = $syspref ? $syspref->value() : undef; |
| 62 |
|
| 63 |
if ($use_syspref_cache) { |
| 64 |
my $syspref_cache = Koha::Caches->get_instance('syspref'); |
| 65 |
$syspref_cache->set_in_cache( "syspref_$var", $value ); |
| 66 |
} |
| 67 |
return $value; |
| 68 |
} |
| 69 |
|
| 70 |
1; |