From: Moritz Bunkus Date: Wed, 19 Jan 2011 15:55:34 +0000 (+0100) Subject: config/lx_office.conf.default einlesen, wenn config/lx_office.conf nicht existiert X-Git-Tag: release-2.6.3~61^2~7^2~1^2~9^2 X-Git-Url: http://wagnertech.de/git?a=commitdiff_plain;h=67b21d425476471298e0b2e3f5dcacc025ebaaaf;p=kivitendo-erp.git config/lx_office.conf.default einlesen, wenn config/lx_office.conf nicht existiert --- diff --git a/SL/BackgroundJob/CreatePeriodicInvoices.pm b/SL/BackgroundJob/CreatePeriodicInvoices.pm index dc89c3da4..c725a6fec 100644 --- a/SL/BackgroundJob/CreatePeriodicInvoices.pm +++ b/SL/BackgroundJob/CreatePeriodicInvoices.pm @@ -184,7 +184,7 @@ sub _calculate_dates { sub _send_email { my ($posted_invoices, $printed_invoices) = @_; - read_config 'config/lx_office.conf' => my %config; + my %config = %::lx_office_conf; return if !$config{periodic_invoices} || !$config{periodic_invoices}->{send_email_to} || !scalar @{ $posted_invoices }; diff --git a/SL/Dispatcher.pm b/SL/Dispatcher.pm index 3913125be..d31fa9b56 100644 --- a/SL/Dispatcher.pm +++ b/SL/Dispatcher.pm @@ -15,6 +15,7 @@ use Encode; use English qw(-no_match_vars); use SL::Auth; use SL::LXDebug; +use SL::LxOfficeConf; use SL::Locale; use SL::Common; use SL::Helper::DateTime; @@ -66,8 +67,7 @@ sub show_error { } sub pre_startup_setup { - read_config 'config/lx_office.conf' => %::lx_office_conf; - _decode_recursively(\%::lx_office_conf); + SL::LxOfficeConf->read; _init_environment(); eval { @@ -312,18 +312,6 @@ sub get_standard_filehandles { return $self->{interface} =~ m/f(?:ast)cgi/i ? $self->{request}->GetHandles() : (\*STDIN, \*STDOUT, \*STDERR); } -sub _decode_recursively { - my ($obj) = @_; - - while (my ($key, $value) = each %{ $obj }) { - if (ref($value) eq 'HASH') { - _decode_recursively($value); - } else { - $obj->{$key} = decode('UTF-8', $value); - } - } -} - sub _init_environment { my %key_map = ( lib => { name => 'PERL5LIB', append_path => 1 }, path => { name => 'PATH', append_path => 1 }, diff --git a/SL/LxOfficeConf.pm b/SL/LxOfficeConf.pm new file mode 100644 index 000000000..b0d801024 --- /dev/null +++ b/SL/LxOfficeConf.pm @@ -0,0 +1,26 @@ +package SL::LxOfficeConf; + +use strict; + +use Config::Std; +use Encode; + +sub read { + my $file = -f 'config/lx_office.conf' ? 'config/lx_office.conf' : 'config/lx_office.conf.default'; + read_config $file => %::lx_office_conf; + _decode_recursively(\%::lx_office_conf); +} + +sub _decode_recursively { + my ($obj) = @_; + + while (my ($key, $value) = each %{ $obj }) { + if (ref($value) eq 'HASH') { + _decode_recursively($value); + } else { + $obj->{$key} = decode('UTF-8', $value); + } + } +} + +1; diff --git a/config/lx_office.conf.default b/config/lx_office.conf.default index 9fd502b02..dfaf17c0f 100644 --- a/config/lx_office.conf.default +++ b/config/lx_office.conf.default @@ -99,7 +99,7 @@ email_subject = Benachrichtigung: automatisch erstellte Rechnungen # The template file used for the email's body. email_template = templates/webpages/oe/periodic_invoices_email.txt -[Console] +[console] # autologin to use if none is given login = mb diff --git a/scripts/console b/scripts/console index 97da56248..78b730559 100755 --- a/scripts/console +++ b/scripts/console @@ -9,16 +9,16 @@ BEGIN { push @INC, "modules/fallback"; # Only use our own versions of modules if there's no system version. } -use Config::Std; use Data::Dumper; use Devel::REPL 1.002001; use Term::ReadLine::Perl::Bind; # use sane key binding for rxvt users -read_config 'config/lx_office.conf' => my %config; +use SL::LxOfficeConf; +SL::LxOfficeConf->read; -my $login = shift || $config{Console}{login} || 'demo'; -my $history_file = $config{Console}{history_file} || '/tmp/lxoffice_console_history.log'; # fallback if users is not writable -my $autorun = $config{Console}{autorun}; +my $login = shift || $::lx_office_conf{console}{login} || 'demo'; +my $history_file = $::lx_office_conf{console}{history_file} || '/tmp/lxoffice_console_history.log'; # fallback if users is not writable +my $autorun = $::lx_office_conf{console}{autorun}; # will be configed eventually my @plugins = qw(History LexEnv Colors MultiLine::PPI FancyPrompt PermanentHistory AutoloadModules); @@ -41,7 +41,6 @@ use utf8; use CGI qw( -no_xhtml); use DateTime; use SL::Auth; -use SL::Dispatcher; use SL::Form; use SL::Helper::DateTime; use SL::Locale; @@ -59,9 +58,6 @@ sub lxinit { package main; - read_config 'config/lx_office.conf' => %::lx_office_conf; - SL::Dispatcher::_decode_recursively(\%::lx_office_conf); - $::lxdebug = LXDebug->new; $::locale = Locale->new($::lx_office_conf{system}->{language}); $::cgi = CGI->new qw(); diff --git a/scripts/dbupgrade2_tool.pl b/scripts/dbupgrade2_tool.pl index 311f4b053..a9054aaff 100755 --- a/scripts/dbupgrade2_tool.pl +++ b/scripts/dbupgrade2_tool.pl @@ -23,8 +23,9 @@ use Getopt::Long; use Text::Iconv; use SL::LXDebug; +use SL::LxOfficeConf; -read_config "config/lx_office.conf" => our %lx_office_conf; +SL::LxOfficeConf->read; our $lxdebug = LXDebug->new(); use SL::Auth; diff --git a/scripts/rose_auto_create_model.pl b/scripts/rose_auto_create_model.pl index 49a25d9d7..bfb3e3d6a 100755 --- a/scripts/rose_auto_create_model.pl +++ b/scripts/rose_auto_create_model.pl @@ -19,6 +19,7 @@ use SL::DB; use SL::Form; use SL::Locale; use SL::LXDebug; +use SL::LxOfficeConf; use SL::DB::Helper::ALL; use SL::DB::Helper::Mappings; @@ -42,7 +43,7 @@ sub setup { exit 1; } - read_config "config/lx_office.conf" => %lx_office_conf; + SL::LxOfficeConf->read; my $login = shift @ARGV; diff --git a/scripts/task_server.pl b/scripts/task_server.pl index c30905d66..c2061b76d 100755 --- a/scripts/task_server.pl +++ b/scripts/task_server.pl @@ -16,7 +16,6 @@ BEGIN { } use CGI qw( -no_xhtml); -use Config::Std; use Cwd; use Daemon::Generic; use Data::Dumper; @@ -29,6 +28,7 @@ use SL::BackgroundJob::ALL; use SL::Form; use SL::Helper::DateTime; use SL::LXDebug; +use SL::LxOfficeConf; use SL::Locale; our %lx_office_conf; @@ -89,7 +89,7 @@ sub drop_privileges { sub gd_preconfig { my $self = shift; - read_config $self->{configfile} => %lx_office_conf; + SL::LxOfficeConf->read; die "Missing section [task_server] in config file" unless $lx_office_conf{task_server}; die "Missing key 'login' in section [task_server] in config file" unless $lx_office_conf{task_server}->{login}; @@ -136,7 +136,8 @@ my $pidbase = "${cwd}/users/pid"; mkdir($pidbase) if !-d $pidbase; -newdaemon(configfile => "${cwd}/config/lx_office.conf", +my $file = -f "${cwd}/config/lx_office.conf" ? "${cwd}/config/lx_office.conf" : "${cwd}/config/lx_office.conf.default"; +newdaemon(configfile => $file, progname => 'lx-office-task-server', pidbase => "${pidbase}/", );