1 package WebPAC::Output::Webpacus;
6 use base qw/WebPAC::Common WebPAC::Output Class::Accessor/;
7 __PACKAGE__->mk_accessors(qw(
14 use Data::Dump qw/dump/;
15 use WebPAC::Common qw/force_array/;
24 WebPAC::Output::Webpacus - integrate WebPAC front-end with Jifty back-end
28 our $VERSION = '0.02';
32 Does black magic to sync data between WebPAC and Webpacus, web front-end
39 my $output = new WebPAC::Output::Webpacus({
40 path => '/path/to/Webpacus',
53 my $log = $self->_get_logger;
55 foreach my $p (qw/path database/) {
56 $log->logdie("need $p") unless ($self->$p);
59 my $path = $self->path;
61 $log->logdie("Webpacus path $path not found: $!") unless -d $path;
63 my $config_path = "$path/etc/config.yml";
65 $log->logdie("expected Webpacus config at $config_path: $!") unless -e $config_path;
85 my $log = $self->_get_logger;
86 $log->logdie("need id") unless defined $id;
87 $log->logdie("need ds") unless $ds;
89 $log->debug("id: $id ds = ",sub { dump($ds) });
93 foreach my $type ( $self->consume_outputs ) {
95 my $hash = $self->ds_to_hash( $ds, $type ) || next;
97 $log->debug("$type has following data: ", sub { dump( $hash ) });
99 foreach my $f ( keys %$hash ) {
100 $self->{fields}->{$type}->{$f}++;
101 $stat->{$type}->{$f}++;
105 $log->debug("this record added following fields: ", sub { dump( $stat ) });
114 my $affected = $index->finish;
116 Returns of records saved in total
123 my $log = $self->_get_logger();
125 my $fields = $self->{fields} || confess "no fields?";
127 $log->debug("fields = ", sub { dump $fields });
129 my $path = $self->path || confess "no path?";
130 my $webpac_dir = getcwd();
131 chdir $path || $log->logdie("can't chdir($path) $!");
135 foreach my $type ( $self->consume_outputs ) {
136 next unless defined $fields->{$type};
137 $affected += $self->_sync_field( $fields->{$type} );
146 my $field_hash = shift || confess "no field?";
147 my $path = $self->path || confess "no path?";
149 my $log = $self->_get_logger();
151 $log->debug("field_hash = ",sub { dump($field_hash) });
153 my @field_names = keys %$field_hash;
155 if ( ! @field_names ) {
156 $log->warn("normalization rules don't produce any data for search!");
160 $log->info("syncing search fields: ", join(", ", @field_names));
164 my $system_user = Webpacus::CurrentUser->superuser;
165 my $o = Webpacus::Model::Search->new(current_user => $system_user);
167 my ( $count, $new, $updated ) = ( 0, 0, 0 );
169 foreach my $field ( @field_names ) {
170 my $items = $field_hash->{$field} || confess "no field?";
172 my ( $id, $msg ) = $o->load_by_cols( name => $field );
175 $o->set_items( $items );
176 $log->debug("updated search field: $field [$items] ID: $id $msg");
179 $log->debug("adding search field: $field [$items] $msg");
190 $log->info("synced $count search fields with Webpacus ($new new/$updated updated) at $path");
192 my $glue_path = "$path/lib/Webpacus/Webpac.pm";
194 $log->debug("creating clue class Webpacus::Webpac at $glue_path");
196 my $glue = <<"_END_OF_GLUE_";
197 package Webpacus::Webpac;
201 Webpacus::Webpac - configuration exported from WebPAC
208 sub index_path { '/data/webpac2/var/kinosearch/webpacus' };
213 $log->debug("glue source:\n$glue");
215 write_file( $glue_path, $glue ) || $log->logdie("can't create $glue_path: $!");
221 =head2 consume_outputs
223 Returns array with names of supported output types for this module
227 sub consume_outputs {
228 return qw/search sorted/;
233 Dobrica Pavlinusic, C<< <dpavlin@rot13.org> >>
235 =head1 COPYRIGHT & LICENSE
237 Copyright 2007 Dobrica Pavlinusic, All Rights Reserved.
239 This program is free software; you can redistribute it and/or modify it
240 under the same terms as Perl itself.