From a97d97a009197f5b5b72897e0b09fb5889e2eb90 Mon Sep 17 00:00:00 2001 From: Moritz Bunkus Date: Thu, 30 Dec 2010 14:19:00 +0100 Subject: [PATCH] =?utf8?q?F=C3=BCr=20Auth*-Models=20eigene=20Datenbankverb?= =?utf8?q?indung=20nutzen?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- SL/DB.pm | 63 ++++++++++++++++++++++++++++++++----------------- SL/DB/Object.pm | 2 +- 2 files changed, 42 insertions(+), 23 deletions(-) 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); } -- 2.20.1