Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision a97d97a0

Von Moritz Bunkus vor fast 14 Jahren hinzugefügt

Für Auth*-Models eigene Datenbankverbindung nutzen

Unterschiede anzeigen:

SL/DB.pm
17 17
  my $domain = shift || SL::DB->default_domain;
18 18
  my $type   = shift || SL::DB->default_type;
19 19

  
20
  if ($type eq 'LXOFFICE') {
21
    $domain = 'LXEMPTY' unless %::myconfig && $::myconfig{dbname};
22
    $type   = join $SUBSCRIPT_SEPARATOR, map { $::myconfig{$_} } qw(dbdriver dbname dbhost dbport dbuser dbpasswd) if %::myconfig;
23
  }
24

  
25
  _register_db($domain, $type);
20
  my ($domain, $type) = _register_db($domain, $type);
26 21

  
27 22
  my $db = __PACKAGE__->new_or_cached(domain => $domain, type => $type);
28 23

  
......
33 28
  my $domain = shift;
34 29
  my $type   = shift;
35 30

  
36
  my $idx    = "${domain}::${type}";
37
  return if $_db_registered{$idx};
38

  
39
  $_db_registered{$idx} = 1;
40

  
41
  __PACKAGE__->register_db(domain          => $domain,
42
                           type            => $type,
43
                           driver          => $::myconfig{dbdriver} || 'Pg',
44
                           database        => $::myconfig{dbname},
45
                           host            => $::myconfig{dbhost},
46
                           port            => $::myconfig{dbport} || 5432,
47
                           username        => $::myconfig{dbuser},
48
                           password        => $::myconfig{dbpasswd},
49
                           connect_options => { pg_enable_utf8 => $::locale && $::locale->is_utf8,
50
                                              },
51
                          );
31
  my %connect_settings;
32

  
33
  if (!%::myconfig) {
34
    $type = 'LXOFFICE_EMPTY';
35
    %connect_settings = ( driver => 'Pg' );
36

  
37
  } elsif ($type eq 'LXOFFICE_AUTH') {
38
    %connect_settings = ( driver          => $::myconfig{dbdriver} || 'Pg',
39
                          database        => $::auth->{DB_config}->{db},
40
                          host            => $::auth->{DB_config}->{host},
41
                          port            => $::auth->{DB_config}->{port} || 5432,
42
                          username        => $::auth->{DB_config}->{user},
43
                          password        => $::auth->{DB_config}->{password},
44
                          connect_options => { pg_enable_utf8 => $::locale && $::locale->is_utf8,
45
                                             });
46
  } else {
47
    %connect_settings = ( driver          => $::myconfig{dbdriver} || 'Pg',
48
                          database        => $::myconfig{dbname},
49
                          host            => $::myconfig{dbhost},
50
                          port            => $::myconfig{dbport} || 5432,
51
                          username        => $::myconfig{dbuser},
52
                          password        => $::myconfig{dbpasswd},
53
                          connect_options => { pg_enable_utf8 => $::locale && $::locale->is_utf8,
54
                                             });
55
  }
56

  
57
  $domain = 'LXOFFICE' if $type =~ m/^LXOFFICE/;
58
  $type  .= join($SUBSCRIPT_SEPARATOR, map { $::connect_setings{$_} } sort keys %connect_settings);
59
  my $idx = "${domain}::${type}";
60

  
61
  if (!$_db_registered{$idx}) {
62
    $_db_registered{$idx} = 1;
63

  
64
    __PACKAGE__->register_db(domain => $domain,
65
                             type   => $type,
66
                             %connect_settings,
67
                            );
68
  }
69

  
70
  return ($domain, $type);
52 71
}
53 72

  
54 73
1;
SL/DB/Object.pm
25 25
sub init_db {
26 26
  my $class_or_self = shift;
27 27
  my $class         = ref($class_or_self) || $class_or_self;
28
  my $type          = 'LXOFFICE';
28
  my $type          = $class =~ m/::Auth/ ? 'LXOFFICE_AUTH' : 'LXOFFICE';
29 29

  
30 30
  return SL::DB::create(undef, $type);
31 31
}

Auch abrufbar als: Unified diff