/[webpac2]/trunk/lib/WebPAC/Output/Webpacus.pm
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /trunk/lib/WebPAC/Output/Webpacus.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 996 by dpavlin, Sun Nov 4 14:43:47 2007 UTC revision 997 by dpavlin, Sun Nov 4 16:20:55 2007 UTC
# Line 25  WebPAC::Output::Webpacus - integrate Web Line 25  WebPAC::Output::Webpacus - integrate Web
25    
26  =cut  =cut
27    
28  our $VERSION = '0.02';  our $VERSION = '0.03';
29    
30  =head1 SYNOPSIS  =head1 SYNOPSIS
31    
# Line 126  sub finish { Line 126  sub finish {
126    
127          $log->debug("fields = ", sub { dump $fields });          $log->debug("fields = ", sub { dump $fields });
128    
129            $log->info("init Jifty");
130          my $path = $self->path || confess "no path?";          my $path = $self->path || confess "no path?";
131          my $webpac_dir = getcwd();          my $webpac_dir = getcwd();
132          chdir $path || $log->logdie("can't chdir($path) $!");          chdir $path || $log->logdie("can't chdir($path) $!");
133            Jifty->new();
134    
135          my $affected = 0;          my $affected = 0;
136    
137          foreach my $type ( $self->consume_outputs ) {          foreach my $type ( $self->consume_outputs ) {
138                  next unless defined $fields->{$type};                  next unless defined $fields->{$type};
139                  $affected += $self->_sync_field( $fields->{$type} );                  $affected += $self->_sync_field(
140                            $self->database, $type, $fields->{$type}
141                    );
142          }          }
143    
144    
145    
146            my $glue_path = "$path/lib/Webpacus/Webpac.pm";
147    
148            $log->debug("creating clue class Webpacus::Webpac at $glue_path");
149    
150            my $glue = <<"_END_OF_GLUE_";
151    package Webpacus::Webpac;
152    
153    =head1 NAME
154    
155    Webpacus::Webpac - configuration exported from WebPAC
156    
157    =cut
158    
159    use strict;
160    use warnings;
161    
162    sub index_path { '/data/webpac2/var/kinosearch/' };
163    
164    1;
165    _END_OF_GLUE_
166    
167            $log->debug("glue source:\n$glue");
168    
169            write_file( $glue_path, $glue ) || $log->logdie("can't create $glue_path: $!");
170    
171          return $affected;          return $affected;
172  };  };
173    
174  sub _sync_field {  sub _sync_field {
175          my $self = shift;          my $self = shift;
176    
177          my $field_hash = shift || confess "no field?";          my ( $database, $type, $field_hash ) = @_;
178    
179          my $path = $self->path || confess "no path?";          my $path = $self->path || confess "no path?";
180    
181          my $log = $self->_get_logger();          my $log = $self->_get_logger();
182    
183            my $model = 'Webpacus::Model::' . ucfirst($type);
184            $log->info("sync $model");
185    
186          $log->debug("field_hash = ",sub { dump($field_hash) });          $log->debug("field_hash = ",sub { dump($field_hash) });
187    
188          my @field_names = keys %$field_hash;          my @field_names = keys %$field_hash;
# Line 157  sub _sync_field { Line 192  sub _sync_field {
192                  return;                  return;
193          }          }
194    
195          $log->info("syncing search fields: ", join(", ", @field_names));          $log->info("syncing $database $type fields: ", join(", ", @field_names));
196    
 #       push @INC, $path;  
         Jifty->new();  
197          my $system_user = Webpacus::CurrentUser->superuser;          my $system_user = Webpacus::CurrentUser->superuser;
198          my $o = Webpacus::Model::Search->new(current_user => $system_user);          my $o = $model->new(current_user => $system_user);
199    
200          my ( $count, $new, $updated ) = ( 0, 0, 0 );          my ( $count, $new, $updated ) = ( 0, 0, 0 );
201    
202          foreach my $field ( @field_names ) {          foreach my $field ( @field_names ) {
203                  my $items = $field_hash->{$field} || confess "no field?";                  my $items = $field_hash->{$field} || confess "no field?";
204    
205                  my ( $id, $msg ) = $o->load_by_cols( name => $field );                  my ( $id, $msg ) = $o->load_by_cols(
206                            name => $field,
207                            from_database => $database,
208                    );
209    
210                  if ( $id ) {                  if ( $id ) {
211                          $o->set_items( $items );                          $o->set_items( $items );
212                          $log->debug("updated search field: $field [$items] ID: $id $msg");                          $log->debug("updated $database $type field: $field [$items] ID: $id $msg");
213                          $updated++;                          $updated++;
214                  } else {                  } else {
215                          $log->debug("adding search field: $field [$items] $msg");                          $log->debug("adding $database $type field: $field [$items] $msg");
216                          $o->create(                          $o->create(
217                                  name => $field,                                  name => $field,
218                                    from_database => $database,
219                                  items => $items,                                  items => $items,
220                          );                          );
221                          $new++;                          $new++;
# Line 187  sub _sync_field { Line 224  sub _sync_field {
224                  $count++;                  $count++;
225          }          }
226    
227          $log->info("synced $count search fields with Webpacus ($new new/$updated updated) at $path");          $log->info("synced $count fields (",join(", ", @field_names),") from $database 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: $!");  
228    
229          return $count;          return $count;
230    

Legend:
Removed from v.996  
changed lines
  Added in v.997

  ViewVC Help
Powered by ViewVC 1.1.26