View | Details | Raw Unified | Return to bug 41891
Collapse All | Expand All

(-)a/C4/Context.pm (-21 / +2 lines)
Lines 46-53 use ZOOM; Link Here
46
use List::MoreUtils qw(any);
46
use List::MoreUtils qw(any);
47
47
48
use Koha::Caches;
48
use Koha::Caches;
49
use Koha::Config::SysPref;
50
use Koha::Config::SysPrefs;
49
use Koha::Config::SysPrefs;
50
use Koha::Context::Preferences;
51
use Koha::Config;
51
use Koha::Config;
52
use Koha;
52
use Koha;
53
53
Lines 266-291 sub preference { Link Here
266
    my $self = shift;
266
    my $self = shift;
267
    my $var  = shift;    # The system preference to return
267
    my $var  = shift;    # The system preference to return
268
268
269
    return Encode::decode_utf8( $ENV{"OVERRIDE_SYSPREF_$var"} )
269
    return Koha::Context::Preferences->get_value( $var, { use_cache => $use_syspref_cache } );
270
        if defined $ENV{"OVERRIDE_SYSPREF_$var"};
271
272
    $var = lc $var;
273
274
    if ($use_syspref_cache) {
275
        my $syspref_cache = Koha::Caches->get_instance('syspref');
276
        my $cached_var    = $syspref_cache->get_from_cache("syspref_$var");
277
        return $cached_var if defined $cached_var;
278
    }
279
280
    my $syspref;
281
    eval { $syspref = Koha::Config::SysPrefs->find( lc $var ) };
282
    my $value = $syspref ? $syspref->value() : undef;
283
284
    if ($use_syspref_cache) {
285
        my $syspref_cache = Koha::Caches->get_instance('syspref');
286
        $syspref_cache->set_in_cache( "syspref_$var", $value );
287
    }
288
    return $value;
289
}
270
}
290
271
291
=head2 yaml_preference
272
=head2 yaml_preference
(-)a/Koha/Context/Preferences.pm (-1 / +70 lines)
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;

Return to bug 41891