|
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; |