From: Moritz Bunkus Date: Thu, 30 Dec 2010 13:19:00 +0000 (+0100) Subject: Für Auth*-Models eigene Datenbankverbindung nutzen X-Git-Tag: release-2.6.2beta1~30^2 X-Git-Url: http://wagnertech.de/git?a=commitdiff_plain;h=a97d97a009197f5b5b72897e0b09fb5889e2eb90;p=kivitendo-erp.git Für Auth*-Models eigene Datenbankverbindung nutzen --- diff --git a/SL/DB.pm b/SL/DB.pm index 18f8696b9..bcbf2e146 100644 --- a/SL/DB.pm +++ b/SL/DB.pm @@ -17,12 +17,7 @@ sub create { my $domain = shift || SL::DB->default_domain; my $type = shift || SL::DB->default_type; - if ($type eq 'LXOFFICE') { - $domain = 'LXEMPTY' unless %::myconfig && $::myconfig{dbname}; - $type = join $SUBSCRIPT_SEPARATOR, map { $::myconfig{$_} } qw(dbdriver dbname dbhost dbport dbuser dbpasswd) if %::myconfig; - } - - _register_db($domain, $type); + my ($domain, $type) = _register_db($domain, $type); my $db = __PACKAGE__->new_or_cached(domain => $domain, type => $type); @@ -33,22 +28,46 @@ sub _register_db { my $domain = shift; my $type = shift; - my $idx = "${domain}::${type}"; - return if $_db_registered{$idx}; - - $_db_registered{$idx} = 1; - - __PACKAGE__->register_db(domain => $domain, - type => $type, - driver => $::myconfig{dbdriver} || 'Pg', - database => $::myconfig{dbname}, - host => $::myconfig{dbhost}, - port => $::myconfig{dbport} || 5432, - username => $::myconfig{dbuser}, - password => $::myconfig{dbpasswd}, - connect_options => { pg_enable_utf8 => $::locale && $::locale->is_utf8, - }, - ); + my %connect_settings; + + if (!%::myconfig) { + $type = 'LXOFFICE_EMPTY'; + %connect_settings = ( driver => 'Pg' ); + + } elsif ($type eq 'LXOFFICE_AUTH') { + %connect_settings = ( driver => $::myconfig{dbdriver} || 'Pg', + database => $::auth->{DB_config}->{db}, + host => $::auth->{DB_config}->{host}, + port => $::auth->{DB_config}->{port} || 5432, + username => $::auth->{DB_config}->{user}, + password => $::auth->{DB_config}->{password}, + connect_options => { pg_enable_utf8 => $::locale && $::locale->is_utf8, + }); + } else { + %connect_settings = ( driver => $::myconfig{dbdriver} || 'Pg', + database => $::myconfig{dbname}, + host => $::myconfig{dbhost}, + port => $::myconfig{dbport} || 5432, + username => $::myconfig{dbuser}, + password => $::myconfig{dbpasswd}, + connect_options => { pg_enable_utf8 => $::locale && $::locale->is_utf8, + }); + } + + $domain = 'LXOFFICE' if $type =~ m/^LXOFFICE/; + $type .= join($SUBSCRIPT_SEPARATOR, map { $::connect_setings{$_} } sort keys %connect_settings); + my $idx = "${domain}::${type}"; + + if (!$_db_registered{$idx}) { + $_db_registered{$idx} = 1; + + __PACKAGE__->register_db(domain => $domain, + type => $type, + %connect_settings, + ); + } + + return ($domain, $type); } 1; diff --git a/SL/DB/Object.pm b/SL/DB/Object.pm index f13851800..52b9300a9 100644 --- a/SL/DB/Object.pm +++ b/SL/DB/Object.pm @@ -25,7 +25,7 @@ sub new { sub init_db { my $class_or_self = shift; my $class = ref($class_or_self) || $class_or_self; - my $type = 'LXOFFICE'; + my $type = $class =~ m/::Auth/ ? 'LXOFFICE_AUTH' : 'LXOFFICE'; return SL::DB::create(undef, $type); }