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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 949 - (show annotations)
Thu Nov 1 00:16:48 2007 UTC (16 years, 6 months ago) by dpavlin
File size: 3318 byte(s)
 r1433@llin:  dpavlin | 2007-10-31 22:48:02 +0100
 HUGE swiping changes to implement new testing architecture
 based on all new WebPAC::Test module which makes
 test writing a joy

1 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 input
11 ));
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 use File::Slurp;
19
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 my $items = $fields->{$field} || confess "no field?";
139 $log->debug("adding search field: $field [$items]");
140 $o->load_by_cols(
141 name => $field,
142 ) ||
143 $o->create(
144 name => $field,
145 items => $items,
146 ); # || $log->logdie("can't add $field");
147 $count++;
148 }
149
150 $log->info("synced $count search fields with Webpacus");
151
152 my $glue_path = "$path/lib/Webpacus/Webpac.pm";
153
154 $log->info("creating clue class Webpacus::Webpac at $glue_path");
155
156 my $glue = <<"_END_OF_GLUE_";
157 package Webpacus::Webpac;
158
159 =head1 NAME
160
161 Webpacus::Webpac - configuration exported from WebPAC
162
163 =cut
164
165 use strict;
166 use warnings;
167
168 sub index_path { '/data/webpac2/var/kinosearch/webpacus' };
169
170 1;
171 _END_OF_GLUE_
172
173 $log->debug("glue source:\n$glue");
174
175 write_file( $glue_path, $glue ) || $log->logdie("can't create $glue_path: $!");
176
177 return $count;
178
179 }
180
181
182 =head1 AUTHOR
183
184 Dobrica Pavlinusic, C<< <dpavlin@rot13.org> >>
185
186 =head1 COPYRIGHT & LICENSE
187
188 Copyright 2007 Dobrica Pavlinusic, All Rights Reserved.
189
190 This program is free software; you can redistribute it and/or modify it
191 under the same terms as Perl itself.
192
193 =cut
194
195 1;

  ViewVC Help
Powered by ViewVC 1.1.26