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/; |
20 |
|
|
21 |
=head2 new |
=head2 new |
22 |
|
|
23 |
my $strix = Strix->new({ site => 'os-test0604-zg' }); |
my $strix = Strix->new({ instance => 'os-test0604-zg' }); |
24 |
|
|
25 |
=head2 dbh |
=head2 dbh |
26 |
|
|
27 |
my $dbh = Strix->dbh( $site_name ); |
my $dbh = Strix->dbh( $strix_instance ); |
28 |
|
|
29 |
my $dbh = $strix->dbh; |
my $dbh = $strix->dbh; |
30 |
|
|
31 |
=cut |
=cut |
32 |
|
|
33 |
our $site_dbh; |
our $instance_dbh; |
34 |
|
|
35 |
sub dbh { |
sub dbh { |
36 |
my $self = shift; |
my $self = shift; |
37 |
|
|
38 |
my $site = shift || $self->site || confess "no site"; |
my $instance = shift || ref($self) && $self->instance || confess "no instance"; |
39 |
|
|
40 |
return $site_dbh->{$site} if $site_dbh->{$site}; |
return $instance_dbh->{$instance} if $instance_dbh->{$instance}; |
41 |
|
|
42 |
my $config = Jifty->config->app('strix') or die "need strix config"; |
my $config = Jifty->config->app('strix') or die "need strix config"; |
43 |
my $database = $config->{database} or die "no strix.database in config"; |
my $database = $config->{database} or die "no strix.database in config"; |
45 |
Jifty->log->debug("using config ", dump( $database )); |
Jifty->log->debug("using config ", dump( $database )); |
46 |
|
|
47 |
my $dsn = |
my $dsn = |
48 |
'DBI:Pg:dbname=' . $site . |
'DBI:Pg:dbname=' . $instance . |
49 |
';host=' . $database->{host} . |
';host=' . $database->{host} . |
50 |
';port=' . $database->{port}; |
';port=' . $database->{port}; |
51 |
|
|
52 |
Jifty->log->info("Connect to site $site with dsn $dsn"); |
Jifty->log->info("Connect to instance $instance with dsn $dsn"); |
53 |
|
|
54 |
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; |
55 |
|
|
56 |
$site_dbh->{$site} = $dbh; |
$instance_dbh->{$instance} = $dbh; |
57 |
|
|
58 |
warn "## site_dbh = ",dump( $site_dbh ); |
warn "## instance_dbh = ",dump( $instance_dbh ) if $debug; |
59 |
|
|
60 |
return $dbh; |
return $dbh; |
61 |
} |
} |
116 |
}); |
}); |
117 |
$sth->execute( $category->{template_id} ); |
$sth->execute( $category->{template_id} ); |
118 |
|
|
119 |
|
sub module_args { |
120 |
|
my $row = shift; |
121 |
|
return undef unless $row->{module_args}; |
122 |
|
my $args; |
123 |
|
foreach my $a ( split(/\&/, $row->{module_args} ) ) { |
124 |
|
$args->{$1} = $2 if $a =~ m/^(.+)=(.+)$/; |
125 |
|
} |
126 |
|
return $args; |
127 |
|
} |
128 |
|
|
129 |
while (my $row = $sth->fetchrow_hashref() ) { |
while (my $row = $sth->fetchrow_hashref() ) { |
130 |
warn dump( $row ) if $debug; |
warn dump( $row ) if $debug; |
131 |
push @{ $page->{free} }, { $row->{name} => $row->{module_args} }; |
push @{ $page->{free} }, { $row->{name} => module_args( $row ) }; |
132 |
} |
} |
133 |
|
|
134 |
warn "### pre layout...\n" if $debug; |
warn "### pre layout...\n" if $debug; |
148 |
|
|
149 |
while (my $row = $sth->fetchrow_hashref() ) { |
while (my $row = $sth->fetchrow_hashref() ) { |
150 |
warn dump( $row ) if $debug; |
warn dump( $row ) if $debug; |
151 |
push @{ $page->{pre}->{ $row->{pos} } }, { $row->{name} => $row->{module_args} }; |
push @{ $page->{pre}->{ $row->{pos} } }, { $row->{name} => module_args( $row ) }; |
152 |
} |
} |
153 |
|
|
154 |
warn "### post layout...\n" if $debug; |
warn "### post layout...\n" if $debug; |
163 |
|
|
164 |
while (my $row = $sth->fetchrow_hashref() ) { |
while (my $row = $sth->fetchrow_hashref() ) { |
165 |
warn dump( $row ) if $debug; |
warn dump( $row ) if $debug; |
166 |
push @{ $page->{post}->{ $row->{pozicija} } }, { $row->{name} => $row->{module_args} }; |
push @{ $page->{post}->{ $row->{pozicija} } }, { $row->{name} => module_args( $row ) }; |
167 |
} |
} |
168 |
|
|
169 |
return $page; |
return $page; |
238 |
@pos = splice( @pos, 0, $depth ); |
@pos = splice( @pos, 0, $depth ); |
239 |
$pos[ $depth - 1 ]++; |
$pos[ $depth - 1 ]++; |
240 |
|
|
241 |
warn "## category depth = $depth pos = ",dump( @pos ); |
warn "## category depth = $depth pos = ",dump( @pos ) if $debug; |
242 |
|
|
243 |
my $code = '$navigation'; |
my $code = '$navigation'; |
244 |
map { $code .= '->[' . ( $_ - 1 ) . ']->{children}' } @pos; |
map { $code .= '->[' . ( $_ - 1 ) . ']->{children}' } @pos; |
245 |
$code =~ s/->{children}$//; |
$code =~ s/->{children}$//; |
246 |
warn "## category code: $code\n"; |
warn "## category code: $code\n" if $debug; |
247 |
eval $code . '= $node'; |
eval $code . '= $node'; |
248 |
if ( $@ ) { |
if ( $@ ) { |
249 |
warn "SKIPPED CATEGORY: $@ ",dump( $kat ); |
warn "SKIPPED CATEGORY: $@ ",dump( $kat ); |
277 |
|
|
278 |
my $ms_depth = $ms->{depth} + $depth; |
my $ms_depth = $ms->{depth} + $depth; |
279 |
my $p = $pos[ $ms_depth - 1 ]++; |
my $p = $pos[ $ms_depth - 1 ]++; |
280 |
warn "## multistatic depth = $ms_depth pos = ",dump( @pos ); |
warn "## multistatic depth = $ms_depth pos = ",dump( @pos ) if $debug; |
281 |
|
|
282 |
my $ms_code = $code . '->{children}->[ ' . $p . '] = $node'; |
my $ms_code = $code . '->{children}->[ ' . $p . '] = $node'; |
283 |
warn "## multistatic code: $ms_code\n"; |
warn "## multistatic code: $ms_code\n" if $debug; |
284 |
eval $ms_code; |
eval $ms_code; |
285 |
if ( $@ ) { |
if ( $@ ) { |
286 |
warn "SKIPPED MULTISTATIC: $@ ",dump( $ms ); |
warn "SKIPPED MULTISTATIC: $@ ",dump( $ms ); |