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
32 our $VERSION = '0.01';
36 Does black magic to sync data between WebPAC and Webpacus, web front-end
43 my $output = new WebPAC::Output::Webpacus({
44 path => '/path/to/Webpacus',
57 my $log = $self->_get_logger;
59 foreach my $p (qw/path database/) {
60 $log->logdie("need $p") unless ($self->$p);
63 my $path = $self->path;
65 $log->logdie("Webpacus path $path not found: $!") unless -d $path;
67 my $config_path = "$path/etc/config.yml";
69 $log->logdie("expected Webpacus config at $config_path: $!") unless -e $config_path;
89 my $log = $self->_get_logger;
90 $log->logdie("need id") unless defined $id;
91 $log->logdie("need ds") unless $ds;
93 $log->debug("id: $id ds = ",sub { dump($ds) });
95 my $hash = $self->ds_to_hash( $ds, 'sorted' ) || return;
97 foreach my $f ( keys %$hash ) {
98 $self->{fields}->{$f}++;
115 my $log = $self->_get_logger();
117 my $fields = $self->{fields} || confess "no fields?";
118 my $path = $self->path || confess "no path?";
120 my @field_names = %$fields;
122 if ( ! @field_names ) {
123 $log->warn("normalization rules don't produce any data for search!");
127 $log->info("syncing search fields: ", join(", ", @field_names));
129 $log->debug("fields = ", sub { dump $fields });
131 my $webpac_dir = getcwd();
133 chdir $path || $log->logdie("can't chdir($path) $!");
137 my $system_user = Webpacus::CurrentUser->superuser;
138 my $o = Webpacus::Model::Search->new(current_user => $system_user);
140 my ( $count, $new, $updated ) = ( 0, 0, 0 );
142 foreach my $field ( @field_names ) {
143 my $items = $fields->{$field} || confess "no field?";
145 my ( $id, $msg ) = $o->load_by_cols( name => $field );
148 $o->set_items( $items );
149 $log->debug("updated search field: $field [$items] ID: $id $msg");
152 $log->debug("adding search field: $field [$items] $msg");
163 $log->info("synced $count search fields with Webpacus ($new new/$updated updated) at $path");
165 my $glue_path = "$path/lib/Webpacus/Webpac.pm";
167 $log->debug("creating clue class Webpacus::Webpac at $glue_path");
169 my $glue = <<"_END_OF_GLUE_";
170 package Webpacus::Webpac;
174 Webpacus::Webpac - configuration exported from WebPAC
181 sub index_path { '/data/webpac2/var/kinosearch/webpacus' };
186 $log->debug("glue source:\n$glue");
188 write_file( $glue_path, $glue ) || $log->logdie("can't create $glue_path: $!");
197 Dobrica Pavlinusic, C<< <dpavlin@rot13.org> >>
199 =head1 COPYRIGHT & LICENSE
201 Copyright 2007 Dobrica Pavlinusic, All Rights Reserved.
203 This program is free software; you can redistribute it and/or modify it
204 under the same terms as Perl itself.