--- lib/Strix.pm 2008/06/16 14:43:07 173 +++ lib/Strix.pm 2008/06/16 22:17:06 185 @@ -4,11 +4,12 @@ use warnings; use base qw(Jifty::Object Class::Accessor::Fast); -__PACKAGE__->mk_accessors( qw(site uid) ); +__PACKAGE__->mk_accessors( qw(instance uid) ); use DBI; use Data::Dump qw/dump/; use Carp qw/confess/; +use Jifty; our $debug = 0; @@ -20,24 +21,24 @@ =head2 new - my $strix = Strix->new({ site => 'os-test0604-zg' }); + my $strix = Strix->new({ instance => 'os-test0604-zg' }); =head2 dbh - my $dbh = Strix->dbh( $site_name ); + my $dbh = Strix->dbh( $strix_instance ); my $dbh = $strix->dbh; =cut -our $site_dbh; +our $instance_dbh; sub dbh { my $self = shift; - my $site = shift || $self->site || confess "no site"; + my $instance = shift || ref($self) && $self->instance || confess "no instance"; - return $site_dbh->{$site} if $site_dbh->{$site}; + return $instance_dbh->{$instance} if $instance_dbh->{$instance}; my $config = Jifty->config->app('strix') or die "need strix config"; my $database = $config->{database} or die "no strix.database in config"; @@ -45,17 +46,17 @@ Jifty->log->debug("using config ", dump( $database )); my $dsn = - 'DBI:Pg:dbname=' . $site . + 'DBI:Pg:dbname=' . $instance . ';host=' . $database->{host} . ';port=' . $database->{port}; - Jifty->log->info("Connect to site $site with dsn $dsn"); + Jifty->log->info("Connect to instance $instance with dsn $dsn"); - 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\n"; - $site_dbh->{$site} = $dbh; + $instance_dbh->{$instance} = $dbh; - warn "## site_dbh = ",dump( $site_dbh ) if $debug; + warn "## instance_dbh = ",dump( $instance_dbh ) if $debug; return $dbh; } @@ -235,6 +236,11 @@ } my $depth = $kat->{depth}; + if ( ! defined $pos[ $depth - 2 ] ) { + warn "FIXING CATEGORY: ",dump( $kat ); + $node->{class} = "error"; + $depth--; + } @pos = splice( @pos, 0, $depth ); $pos[ $depth - 1 ]++;