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 $log->info("syncing search fields");
119 my $fields = $self->{fields} || confess "no fields?";
120 my $path = $self->path || confess "no path?";
122 $log->debug("fields = ", sub { dump $fields });
124 my $webpac_dir = getcwd();
126 chdir $path || $log->logdie("can't chdir($path) $!");
130 my $system_user = Webpacus::CurrentUser->superuser;
131 my $o = Webpacus::Model::Search->new(current_user => $system_user);
133 my ( $count, $new, $updated ) = ( 0, 0, 0 );
135 foreach my $field ( keys %$fields ) {
136 my $items = $fields->{$field} || confess "no field?";
138 my ( $id, $msg ) = $o->load_by_cols( name => $field );
141 $o->set_items( $items );
142 $log->debug("updated search field: $field [$items] ID: $id $msg");
145 $log->debug("adding search field: $field [$items] $msg");
156 $log->info("synced $count search fields with Webpacus ($new new/$updated updated) at $path");
158 my $glue_path = "$path/lib/Webpacus/Webpac.pm";
160 $log->debug("creating clue class Webpacus::Webpac at $glue_path");
162 my $glue = <<"_END_OF_GLUE_";
163 package Webpacus::Webpac;
167 Webpacus::Webpac - configuration exported from WebPAC
174 sub index_path { '/data/webpac2/var/kinosearch/webpacus' };
179 $log->debug("glue source:\n$glue");
181 write_file( $glue_path, $glue ) || $log->logdie("can't create $glue_path: $!");
190 Dobrica Pavlinusic, C<< <dpavlin@rot13.org> >>
192 =head1 COPYRIGHT & LICENSE
194 Copyright 2007 Dobrica Pavlinusic, All Rights Reserved.
196 This program is free software; you can redistribute it and/or modify it
197 under the same terms as Perl itself.