--- trunk/lib/WebPAC/Output/Webpacus.pm 2007/11/04 16:20:13 996 +++ trunk/lib/WebPAC/Output/Webpacus.pm 2007/11/04 16:20:55 997 @@ -25,7 +25,7 @@ =cut -our $VERSION = '0.02'; +our $VERSION = '0.03'; =head1 SYNOPSIS @@ -126,28 +126,63 @@ $log->debug("fields = ", sub { dump $fields }); + $log->info("init Jifty"); my $path = $self->path || confess "no path?"; my $webpac_dir = getcwd(); chdir $path || $log->logdie("can't chdir($path) $!"); + Jifty->new(); my $affected = 0; foreach my $type ( $self->consume_outputs ) { next unless defined $fields->{$type}; - $affected += $self->_sync_field( $fields->{$type} ); + $affected += $self->_sync_field( + $self->database, $type, $fields->{$type} + ); } + + + my $glue_path = "$path/lib/Webpacus/Webpac.pm"; + + $log->debug("creating clue class Webpacus::Webpac at $glue_path"); + + my $glue = <<"_END_OF_GLUE_"; +package Webpacus::Webpac; + +=head1 NAME + +Webpacus::Webpac - configuration exported from WebPAC + +=cut + +use strict; +use warnings; + +sub index_path { '/data/webpac2/var/kinosearch/' }; + +1; +_END_OF_GLUE_ + + $log->debug("glue source:\n$glue"); + + write_file( $glue_path, $glue ) || $log->logdie("can't create $glue_path: $!"); + return $affected; }; sub _sync_field { my $self = shift; - my $field_hash = shift || confess "no field?"; + my ( $database, $type, $field_hash ) = @_; + my $path = $self->path || confess "no path?"; my $log = $self->_get_logger(); + my $model = 'Webpacus::Model::' . ucfirst($type); + $log->info("sync $model"); + $log->debug("field_hash = ",sub { dump($field_hash) }); my @field_names = keys %$field_hash; @@ -157,28 +192,30 @@ return; } - $log->info("syncing search fields: ", join(", ", @field_names)); + $log->info("syncing $database $type fields: ", join(", ", @field_names)); -# push @INC, $path; - Jifty->new(); my $system_user = Webpacus::CurrentUser->superuser; - my $o = Webpacus::Model::Search->new(current_user => $system_user); + my $o = $model->new(current_user => $system_user); my ( $count, $new, $updated ) = ( 0, 0, 0 ); foreach my $field ( @field_names ) { my $items = $field_hash->{$field} || confess "no field?"; - my ( $id, $msg ) = $o->load_by_cols( name => $field ); + my ( $id, $msg ) = $o->load_by_cols( + name => $field, + from_database => $database, + ); if ( $id ) { $o->set_items( $items ); - $log->debug("updated search field: $field [$items] ID: $id $msg"); + $log->debug("updated $database $type field: $field [$items] ID: $id $msg"); $updated++; } else { - $log->debug("adding search field: $field [$items] $msg"); + $log->debug("adding $database $type field: $field [$items] $msg"); $o->create( name => $field, + from_database => $database, items => $items, ); $new++; @@ -187,32 +224,7 @@ $count++; } - $log->info("synced $count search fields with Webpacus ($new new/$updated updated) at $path"); - - my $glue_path = "$path/lib/Webpacus/Webpac.pm"; - - $log->debug("creating clue class Webpacus::Webpac at $glue_path"); - - my $glue = <<"_END_OF_GLUE_"; -package Webpacus::Webpac; - -=head1 NAME - -Webpacus::Webpac - configuration exported from WebPAC - -=cut - -use strict; -use warnings; - -sub index_path { '/data/webpac2/var/kinosearch/webpacus' }; - -1; -_END_OF_GLUE_ - - $log->debug("glue source:\n$glue"); - - write_file( $glue_path, $glue ) || $log->logdie("can't create $glue_path: $!"); + $log->info("synced $count fields (",join(", ", @field_names),") from $database with Webpacus ($new new/$updated updated) at $path"); return $count;