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

(-)a/C4/Context.pm (-77 / +14 lines)
Lines 90-96 BEGIN { Link Here
90
90
91
use Encode;
91
use Encode;
92
use ZOOM;
92
use ZOOM;
93
use XML::Simple;
94
use Koha::Caches;
93
use Koha::Caches;
95
use POSIX ();
94
use POSIX ();
96
use DateTime::TimeZone;
95
use DateTime::TimeZone;
Lines 100-105 use Carp; Link Here
100
use C4::Boolean;
99
use C4::Boolean;
101
use C4::Debug;
100
use C4::Debug;
102
use Koha;
101
use Koha;
102
use Koha::Config;
103
use Koha::Config::SysPref;
103
use Koha::Config::SysPref;
104
use Koha::Config::SysPrefs;
104
use Koha::Config::SysPrefs;
105
105
Lines 168-233 environment variable to the pathname of a configuration file to use. Link Here
168
# Zconn
168
# Zconn
169
#     A connection object for the Zebra server
169
#     A connection object for the Zebra server
170
170
171
# Koha's main configuration file koha-conf.xml
172
# is searched for according to this priority list:
173
#
174
# 1. Path supplied via use C4::Context '/path/to/koha-conf.xml'
175
# 2. Path supplied in KOHA_CONF environment variable.
176
# 3. Path supplied in INSTALLED_CONFIG_FNAME, as long
177
#    as value has changed from its default of 
178
#    '__KOHA_CONF_DIR__/koha-conf.xml', as happens
179
#    when Koha is installed in 'standard' or 'single'
180
#    mode.
181
# 4. Path supplied in CONFIG_FNAME.
182
#
183
# The first entry that refers to a readable file is used.
184
185
use constant CONFIG_FNAME => "/etc/koha/koha-conf.xml";
186
                # Default config file, if none is specified
187
                
188
my $INSTALLED_CONFIG_FNAME = '__KOHA_CONF_DIR__/koha-conf.xml';
189
                # path to config file set by installer
190
                # __KOHA_CONF_DIR__ is set by rewrite-confg.PL
191
                # when Koha is installed in 'standard' or 'single'
192
                # mode.  If Koha was installed in 'dev' mode, 
193
                # __KOHA_CONF_DIR__ is *not* rewritten; instead
194
                # developers should set the KOHA_CONF environment variable 
195
196
$context = undef;        # Initially, no context is set
171
$context = undef;        # Initially, no context is set
197
@context_stack = ();        # Initially, no saved contexts
172
@context_stack = ();        # Initially, no saved contexts
198
173
199
200
=head2 read_config_file
201
202
Reads the specified Koha config file. 
203
204
Returns an object containing the configuration variables. The object's
205
structure is a bit complex to the uninitiated ... take a look at the
206
koha-conf.xml file as well as the XML::Simple documentation for details. Or,
207
here are a few examples that may give you what you need:
208
209
The simple elements nested within the <config> element:
210
211
    my $pass = $koha->{'config'}->{'pass'};
212
213
The <listen> elements:
214
215
    my $listen = $koha->{'listen'}->{'biblioserver'}->{'content'};
216
217
The elements nested within the <server> element:
218
219
    my $ccl2rpn = $koha->{'server'}->{'biblioserver'}->{'cql2rpn'};
220
221
Returns undef in case of error.
222
223
=cut
224
225
sub read_config_file {		# Pass argument naming config file to read
226
    my $koha = XMLin(shift, keyattr => ['id'], forcearray => ['listen', 'server', 'serverinfo'], suppressempty => '');
227
228
    return $koha;			# Return value: ref-to-hash holding the configuration
229
}
230
231
=head2 db_scheme2dbi
174
=head2 db_scheme2dbi
232
175
233
    my $dbd_driver_name = C4::Context::db_schema2dbi($scheme);
176
    my $dbd_driver_name = C4::Context::db_schema2dbi($scheme);
Lines 292-329 sub new { Link Here
292
    undef $conf_fname unless 
235
    undef $conf_fname unless 
293
        (defined $conf_fname && -s $conf_fname);
236
        (defined $conf_fname && -s $conf_fname);
294
    # Figure out a good config file to load if none was specified.
237
    # Figure out a good config file to load if none was specified.
295
    if (!defined($conf_fname))
238
    unless ( defined $conf_fname ) {
296
    {
239
        $conf_fname = Koha::Config->guess_koha_conf;
297
        # If the $KOHA_CONF environment variable is set, use
240
        unless ( $conf_fname ) {
298
        # that. Otherwise, use the built-in default.
299
        if (exists $ENV{"KOHA_CONF"} and $ENV{'KOHA_CONF'} and -s  $ENV{"KOHA_CONF"}) {
300
            $conf_fname = $ENV{"KOHA_CONF"};
301
        } elsif ($INSTALLED_CONFIG_FNAME !~ /__KOHA_CONF_DIR/ and -s $INSTALLED_CONFIG_FNAME) {
302
            # NOTE: be careful -- don't change __KOHA_CONF_DIR in the above
303
            # regex to anything else -- don't want installer to rewrite it
304
            $conf_fname = $INSTALLED_CONFIG_FNAME;
305
        } elsif (-s CONFIG_FNAME) {
306
            $conf_fname = CONFIG_FNAME;
307
        } else {
308
            warn "unable to locate Koha configuration file koha-conf.xml";
241
            warn "unable to locate Koha configuration file koha-conf.xml";
309
            return;
242
            return;
310
        }
243
        }
311
    }
244
    }
312
245
313
    my $conf_cache = Koha::Caches->get_instance('config');
246
    my $conf_cache = Koha::Caches->get_instance('config');
314
    if ( $conf_cache ) {
247
    my $config_from_cache;
315
        $self = $conf_cache->get_from_cache('kohaconf');
248
    if ( $conf_cache->cache ) {
249
        $config_from_cache = $conf_cache->get_from_cache('koha_conf');
316
    }
250
    }
317
    unless ( %$self ) {
251
    unless ( %$self ) {
318
        $self = read_config_file($conf_fname);
252
        $self = Koha::Config->read_from_file($conf_fname);
319
    }
253
    }
320
    if ( $conf_cache ) {
254
255
    if ( $config_from_cache ) {
256
        $self = $config_from_cache;
257
    } elsif ( $conf_cache->memcached_cache ) {
321
        # FIXME it may be better to use the memcached servers from the config file
258
        # FIXME it may be better to use the memcached servers from the config file
322
        # to cache it
259
        # to cache it
323
        $conf_cache->set_in_cache('koha_conf', $self)
260
        $conf_cache->set_in_cache('koha_conf', $self)
324
    }
261
    }
325
    unless ( exists $self->{config} or defined $self->{config} ) {
262
    unless ( exists $self->{config} or defined $self->{config} ) {
326
        warn "read_config_file($conf_fname) returned undef";
263
        warn "The config file ($conf_fname) has not been parsed correctly";
327
        return;
264
        return;
328
    }
265
    }
329
266
Lines 466-472 with this method. Link Here
466
403
467
=cut
404
=cut
468
405
469
my $syspref_cache = Koha::Caches->get_instance();
406
my $syspref_cache = Koha::Caches->get_instance('syspref');
470
my $use_syspref_cache = 1;
407
my $use_syspref_cache = 1;
471
sub preference {
408
sub preference {
472
    my $self = shift;
409
    my $self = shift;
(-)a/Koha/Cache.pm (-7 / +18 lines)
Lines 39-48 use strict; Link Here
39
use warnings;
39
use warnings;
40
use Carp;
40
use Carp;
41
use Module::Load::Conditional qw(can_load);
41
use Module::Load::Conditional qw(can_load);
42
use Koha::Cache::Object;
43
use Sereal::Encoder;
42
use Sereal::Encoder;
44
use Sereal::Decoder;
43
use Sereal::Decoder;
45
44
45
use Koha::Cache::Object;
46
use Koha::Config;
47
46
use base qw(Class::Accessor);
48
use base qw(Class::Accessor);
47
49
48
__PACKAGE__->mk_ro_accessors(
50
__PACKAGE__->mk_ro_accessors(
Lines 69-89 Create a new Koha::Cache object. This is required for all cache-related function Link Here
69
=cut
71
=cut
70
72
71
sub new {
73
sub new {
72
    my ( $class, $self, $subnamespace ) = @_;
74
    my ( $class, $self, $params ) = @_;
73
    $self->{'default_type'} =
75
    $self->{'default_type'} =
74
         $self->{cache_type}
76
         $self->{cache_type}
75
      || $ENV{CACHING_SYSTEM}
77
      || $ENV{CACHING_SYSTEM} # DELME What about this?
76
      || 'memcached';
78
      || 'memcached';
77
79
80
    my $subnamespace = $params->{subnamespace} // '';
81
78
    $ENV{DEBUG} && carp "Default caching system: $self->{'default_type'}";
82
    $ENV{DEBUG} && carp "Default caching system: $self->{'default_type'}";
79
83
80
    $self->{'timeout'}   ||= 0;
84
    $self->{'timeout'}   ||= 0;
81
    $self->{'namespace'} ||= $ENV{MEMCACHED_NAMESPACE} || C4::Context->config('memcached_namespace') || 'koha';
85
    # Should we continue to support MEMCACHED ENV vars?
86
    $self->{'namespace'} ||= $ENV{MEMCACHED_NAMESPACE};
87
    my @servers = split /,/, $ENV{MEMCACHED_SERVERS} || '';
88
    unless ( $self->{namespace} and @servers ) {
89
        my $koha_config = Koha::Config->read_from_file( Koha::Config->guess_koha_conf() );
90
        $self->{namespace} ||= $koha_config->{config}{memcached_namespace} || 'koha';
91
        @servers ||= split /,/, $koha_config->{config}{memcached_servers};
92
    }
82
    $self->{namespace} .= ":$subnamespace:";
93
    $self->{namespace} .= ":$subnamespace:";
83
94
84
    if ( $self->{'default_type'} eq 'memcached'
95
    if ( $self->{'default_type'} eq 'memcached'
85
        && can_load( modules => { 'Cache::Memcached::Fast' => undef } )
96
        && can_load( modules => { 'Cache::Memcached::Fast' => undef } )
86
        && _initialize_memcached($self)
97
        && _initialize_memcached($self, @servers)
87
        && defined( $self->{'memcached_cache'} ) )
98
        && defined( $self->{'memcached_cache'} ) )
88
    {
99
    {
89
        $self->{'cache'} = $self->{'memcached_cache'};
100
        $self->{'cache'} = $self->{'memcached_cache'};
Lines 115-122 sub new { Link Here
115
}
126
}
116
127
117
sub _initialize_memcached {
128
sub _initialize_memcached {
118
    my ($self) = @_;
129
    my ($self, @servers) = @_;
119
    my @servers = split /,/, $ENV{MEMCACHED_SERVERS} || C4::Context->config('memcached_servers') || '';
130
120
    return unless @servers;
131
    return unless @servers;
121
132
122
    $ENV{DEBUG}
133
    $ENV{DEBUG}
(-)a/Koha/Caches.pm (-1 / +1 lines)
Lines 7-13 our $singleton_caches; Link Here
7
sub get_instance {
7
sub get_instance {
8
    my ($class, $subnamespace) = @_;
8
    my ($class, $subnamespace) = @_;
9
    $subnamespace //= '';
9
    $subnamespace //= '';
10
    $singleton_caches->{$subnamespace} = Koha::Cache->new({}, $subnamespace) unless $singleton_caches->{$subnamespace};
10
    $singleton_caches->{$subnamespace} = Koha::Cache->new({}, { subnamespace => $subnamespace } ) unless $singleton_caches->{$subnamespace};
11
    return $singleton_caches->{$subnamespace};
11
    return $singleton_caches->{$subnamespace};
12
}
12
}
13
13
(-)a/Koha/Config.pm (-1 / +55 lines)
Line 0 Link Here
0
- 
1
package Koha::Config;
2
3
use Modern::Perl;
4
use XML::Simple;
5
6
# Default config file, if none is specified
7
use constant CONFIG_FNAME => "/etc/koha/koha-conf.xml";
8
9
# path to config file set by installer
10
# __KOHA_CONF_DIR__ is set by rewrite-confg.PL
11
# when Koha is installed in 'standard' or 'single'
12
# mode.  If Koha was installed in 'dev' mode,
13
# __KOHA_CONF_DIR__ is *not* rewritten; instead
14
# developers should set the KOHA_CONF environment variable
15
my $INSTALLED_CONFIG_FNAME = '__KOHA_CONF_DIR__/koha-conf.xml';
16
17
# Should not be called outside of C4::Context or Koha::Cache
18
# use C4::Context->config instead
19
sub read_from_file {
20
    my ( $class, $file ) = @_;
21
    return XMLin($file, keyattr => ['id'], forcearray => ['listen', 'server', 'serverinfo'], suppressempty => '');
22
}
23
24
# Koha's main configuration file koha-conf.xml
25
# is searched for according to this priority list:
26
#
27
# 1. Path supplied via use C4::Context '/path/to/koha-conf.xml'
28
# 2. Path supplied in KOHA_CONF environment variable.
29
# 3. Path supplied in INSTALLED_CONFIG_FNAME, as long
30
#    as value has changed from its default of
31
#    '__KOHA_CONF_DIR__/koha-conf.xml', as happens
32
#    when Koha is installed in 'standard' or 'single'
33
#    mode.
34
# 4. Path supplied in CONFIG_FNAME.
35
#
36
# The first entry that refers to a readable file is used.
37
38
sub guess_koha_conf {
39
40
    # If the $KOHA_CONF environment variable is set, use
41
    # that. Otherwise, use the built-in default.
42
    my $conf_fname;
43
    if ( exists $ENV{"KOHA_CONF"} and $ENV{'KOHA_CONF'} and -s $ENV{"KOHA_CONF"} ) {
44
        $conf_fname = $ENV{"KOHA_CONF"};
45
    } elsif ( $INSTALLED_CONFIG_FNAME !~ /__KOHA_CONF_DIR/ and -s $INSTALLED_CONFIG_FNAME ) {
46
        # NOTE: be careful -- don't change __KOHA_CONF_DIR in the above
47
        # regex to anything else -- don't want installer to rewrite it
48
        $conf_fname = $INSTALLED_CONFIG_FNAME;
49
    } elsif ( -s CONFIG_FNAME ) {
50
        $conf_fname = CONFIG_FNAME;
51
    }
52
    return $conf_fname;
53
}
54
55
1;

Return to bug 11921