4 |
use warnings; |
use warnings; |
5 |
|
|
6 |
use base qw(Jifty::Object Class::Accessor::Fast); |
use base qw(Jifty::Object Class::Accessor::Fast); |
7 |
__PACKAGE__->mk_accessors( qw(site uid) ); |
__PACKAGE__->mk_accessors( qw(instance uid) ); |
8 |
|
|
9 |
use DBI; |
use DBI; |
10 |
use Data::Dump qw/dump/; |
use Data::Dump qw/dump/; |
11 |
use Carp qw/confess/; |
use Carp qw/confess/; |
12 |
|
use Jifty; |
13 |
|
|
14 |
our $debug = 0; |
our $debug = 0; |
15 |
|
|
21 |
|
|
22 |
=head2 new |
=head2 new |
23 |
|
|
24 |
my $strix = Strix->new({ site => 'os-test0604-zg' }); |
my $strix = Strix->new({ instance => 'os-test0604-zg' }); |
25 |
|
|
26 |
=head2 dbh |
=head2 dbh |
27 |
|
|
28 |
my $dbh = Strix->dbh( $site_name ); |
my $dbh = Strix->dbh( $strix_instance ); |
29 |
|
|
30 |
my $dbh = $strix->dbh; |
my $dbh = $strix->dbh; |
31 |
|
|
32 |
=cut |
=cut |
33 |
|
|
34 |
our $site_dbh; |
our $instance_dbh; |
35 |
|
|
36 |
sub dbh { |
sub dbh { |
37 |
my $self = shift; |
my $self = shift; |
38 |
|
|
39 |
my $site = shift || $self->site || confess "no site"; |
my $instance = shift || ref($self) && $self->instance || confess "no instance"; |
40 |
|
|
41 |
return $site_dbh->{$site} if $site_dbh->{$site}; |
return $instance_dbh->{$instance} if $instance_dbh->{$instance}; |
42 |
|
|
43 |
my $config = Jifty->config->app('strix') or die "need strix config"; |
my $config = Jifty->config->app('strix') or die "need strix config"; |
44 |
my $database = $config->{database} or die "no strix.database in config"; |
my $database = $config->{database} or die "no strix.database in config"; |
46 |
Jifty->log->debug("using config ", dump( $database )); |
Jifty->log->debug("using config ", dump( $database )); |
47 |
|
|
48 |
my $dsn = |
my $dsn = |
49 |
'DBI:Pg:dbname=' . $site . |
'DBI:Pg:dbname=' . $instance . |
50 |
';host=' . $database->{host} . |
';host=' . $database->{host} . |
51 |
';port=' . $database->{port}; |
';port=' . $database->{port}; |
52 |
|
|
53 |
Jifty->log->info("Connect to site $site with dsn $dsn"); |
Jifty->log->info("Connect to instance $instance with dsn $dsn"); |
54 |
|
|
55 |
my $dbh = DBI->connect( $dsn, $database->{user}, $database->{passwd} ) or die $DBI::errstr; |
my $dbh = DBI->connect( $dsn, $database->{user}, $database->{passwd} ) or die $DBI::errstr; |
56 |
|
|
57 |
$site_dbh->{$site} = $dbh; |
$instance_dbh->{$instance} = $dbh; |
58 |
|
|
59 |
warn "## site_dbh = ",dump( $site_dbh ) if $debug; |
warn "## instance_dbh = ",dump( $instance_dbh ) if $debug; |
60 |
|
|
61 |
return $dbh; |
return $dbh; |
62 |
} |
} |
236 |
} |
} |
237 |
|
|
238 |
my $depth = $kat->{depth}; |
my $depth = $kat->{depth}; |
239 |
|
if ( ! defined $pos[ $depth - 2 ] ) { |
240 |
|
warn "FIXING CATEGORY: ",dump( $kat ); |
241 |
|
$node->{class} = "error"; |
242 |
|
$depth--; |
243 |
|
} |
244 |
@pos = splice( @pos, 0, $depth ); |
@pos = splice( @pos, 0, $depth ); |
245 |
$pos[ $depth - 1 ]++; |
$pos[ $depth - 1 ]++; |
246 |
|
|