Bug 16035: MARC default bibliographic framework Export fix
[koha.git] / Koha / Config.pm
blob117c404ead6a61e0d7eb9f5e43c837bd9043078f
1 package Koha::Config;
3 # This file is part of Koha.
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.
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.
15 # You should have received a copy of the GNU General Public License
16 # along with Koha; if not, see <http://www.gnu.org/licenses>.
18 use Modern::Perl;
20 use XML::Simple;
22 # Default config file, if none is specified
23 use constant CONFIG_FNAME => "/etc/koha/koha-conf.xml";
25 # path to config file set by installer
26 # __KOHA_CONF_DIR__ is set by rewrite-confg.PL
27 # when Koha is installed in 'standard' or 'single'
28 # mode. If Koha was installed in 'dev' mode,
29 # __KOHA_CONF_DIR__ is *not* rewritten; instead
30 # developers should set the KOHA_CONF environment variable
31 my $INSTALLED_CONFIG_FNAME = '__KOHA_CONF_DIR__/koha-conf.xml';
33 # Should not be called outside of C4::Context or Koha::Cache
34 # use C4::Context->config instead
35 sub read_from_file {
36 my ( $class, $file ) = @_;
37 return XMLin($file, keyattr => ['id'], forcearray => ['listen', 'server', 'serverinfo'], suppressempty => '');
40 # Koha's main configuration file koha-conf.xml
41 # is searched for according to this priority list:
43 # 1. Path supplied via use C4::Context '/path/to/koha-conf.xml'
44 # 2. Path supplied in KOHA_CONF environment variable.
45 # 3. Path supplied in INSTALLED_CONFIG_FNAME, as long
46 # as value has changed from its default of
47 # '__KOHA_CONF_DIR__/koha-conf.xml', as happens
48 # when Koha is installed in 'standard' or 'single'
49 # mode.
50 # 4. Path supplied in CONFIG_FNAME.
52 # The first entry that refers to a readable file is used.
54 sub guess_koha_conf {
56 # If the $KOHA_CONF environment variable is set, use
57 # that. Otherwise, use the built-in default.
58 my $conf_fname;
59 if ( exists $ENV{"KOHA_CONF"} and $ENV{'KOHA_CONF'} and -s $ENV{"KOHA_CONF"} ) {
60 $conf_fname = $ENV{"KOHA_CONF"};
61 } elsif ( $INSTALLED_CONFIG_FNAME !~ /__KOHA_CONF_DIR/ and -s $INSTALLED_CONFIG_FNAME ) {
62 # NOTE: be careful -- don't change __KOHA_CONF_DIR in the above
63 # regex to anything else -- don't want installer to rewrite it
64 $conf_fname = $INSTALLED_CONFIG_FNAME;
65 } elsif ( -s CONFIG_FNAME ) {
66 $conf_fname = CONFIG_FNAME;
68 return $conf_fname;