/[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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 936 - (hide annotations)
Wed Oct 31 12:14:03 2007 UTC (16 years, 6 months ago) by dpavlin
File size: 3280 byte(s)
 r1413@llin:  dpavlin | 2007-10-31 13:13:58 +0100
 Add input name to all output filters

1 dpavlin 932 package WebPAC::Output::Webpacus;
2    
3     use warnings;
4     use strict;
5    
6     use base qw/WebPAC::Common WebPAC::Output Class::Accessor/;
7     __PACKAGE__->mk_accessors(qw(
8     path
9     database
10 dpavlin 936 input
11 dpavlin 932 ));
12    
13     use File::Path;
14     use Data::Dump qw/dump/;
15     use WebPAC::Common qw/force_array/;
16     use Carp qw/confess/;
17     use Cwd;
18 dpavlin 933 use File::Slurp;
19 dpavlin 932
20     use Jifty;
21    
22     =head1 NAME
23    
24     WebPAC::Output::Webpacus - integrate WebPAC front-end with Jifty back-end
25    
26     =head1 VERSION
27    
28     Version 0.01
29    
30     =cut
31    
32     our $VERSION = '0.01';
33    
34     =head1 SYNOPSIS
35    
36     Does black magic to sync data between WebPAC and Webpacus, web front-end
37     implement in Jifty
38    
39     =head1 FUNCTIONS
40    
41     =head2 new
42    
43     my $output = new WebPAC::Output::Webpacus({
44     path => '/path/to/Webpacus',
45     database => 'demo',
46     });
47    
48     =head2 init
49    
50     $output->init;
51    
52     =cut
53    
54     sub init {
55     my $self = shift;
56    
57     my $log = $self->_get_logger;
58    
59     foreach my $p (qw/path database/) {
60     $log->logdie("need $p") unless ($self->$p);
61     }
62    
63     my $path = $self->path;
64    
65     $log->logdie("Webpacus path $path not found: $!") unless -d $path;
66    
67     my $config_path = "$path/etc/config.yml";
68    
69     $log->logdie("expected Webpacus config at $config_path: $!") unless -e $config_path;
70    
71     $self->{fields} = {};
72    
73     }
74    
75    
76     =head2 add
77    
78     Adds one entry
79    
80     $est->add( 42, $ds );
81    
82     =cut
83    
84     sub add {
85     my $self = shift;
86    
87     my ( $id, $ds ) = @_;
88    
89     my $log = $self->_get_logger;
90     $log->logdie("need id") unless defined $id;
91     $log->logdie("need ds") unless $ds;
92    
93     $log->debug("id: $id ds = ",sub { dump($ds) });
94    
95     my $hash = $self->ds_to_hash( $ds, 'sorted' ) || return;
96    
97     foreach my $f ( keys %$hash ) {
98     $self->{fields}->{$f}++;
99     }
100    
101     return 1;
102     }
103    
104     =head2 finish
105    
106     Close index
107    
108     $index->finish;
109    
110     =cut
111    
112     sub finish {
113     my $self = shift;
114    
115     my $log = $self->_get_logger();
116    
117     $log->info("syncing search fields");
118    
119     my $fields = $self->{fields} || confess "no fields?";
120     my $path = $self->path || confess "no path?";
121    
122     $log->debug("fields = ", sub { dump $fields });
123    
124     $log->info("using Webpacus installation: $path");
125    
126     my $webpac_dir = getcwd();
127    
128     chdir $path || $log->logdie("can't chdir($path) $!");
129    
130     # push @INC, $path;
131     Jifty->new();
132     my $system_user = Webpacus::CurrentUser->superuser;
133     my $o = Webpacus::Model::Search->new(current_user => $system_user);
134    
135     my $count = 0;
136    
137     foreach my $field ( keys %$fields ) {
138 dpavlin 933 my $items = $fields->{$field} || confess "no field?";
139     $log->debug("adding search field: $field [$items]");
140     $o->load_or_create(
141     name => $field,
142     items => $items,
143     ); # || $log->logdie("can't add $field");
144 dpavlin 932 $count++;
145     }
146    
147 dpavlin 933 $log->info("synced $count search fields with Webpacus");
148    
149     my $glue_path = "$path/lib/Webpacus/Webpac.pm";
150    
151     $log->info("creating clue class Webpacus::Webpac at $glue_path");
152    
153     my $glue = <<"_END_OF_GLUE_";
154     package Webpacus::Webpac;
155    
156     =head1 NAME
157    
158     Webpacus::Webpac - configuration exported from WebPAC
159    
160     =cut
161    
162     use strict;
163     use warnings;
164    
165     sub index_path { '/data/webpac2/var/kinosearch/webpacus' };
166    
167     1;
168     _END_OF_GLUE_
169    
170     $log->debug("glue source:\n$glue");
171    
172     write_file( $glue_path, $glue ) || $log->logdie("can't create $glue_path: $!");
173    
174 dpavlin 932 return $count;
175    
176     }
177    
178    
179     =head1 AUTHOR
180    
181     Dobrica Pavlinusic, C<< <dpavlin@rot13.org> >>
182    
183     =head1 COPYRIGHT & LICENSE
184    
185     Copyright 2007 Dobrica Pavlinusic, All Rights Reserved.
186    
187     This program is free software; you can redistribute it and/or modify it
188     under the same terms as Perl itself.
189    
190     =cut
191    
192     1;

  ViewVC Help
Powered by ViewVC 1.1.26