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