1 | ###########################################################################
|
---|
2 | #
|
---|
3 | # indexaction.pm --
|
---|
4 | # A component of the Greenstone digital library software
|
---|
5 | # from the New Zealand Digital Library Project at the
|
---|
6 | # University of Waikato, New Zealand.
|
---|
7 | #
|
---|
8 | # Copyright (C) 2009 New Zealand Digital Library Project
|
---|
9 | #
|
---|
10 | # This program is free software; you can redistr te it and/or modify
|
---|
11 | # it under the terms of the GNU General Public License as published by
|
---|
12 | # the Free Software Foundation; either version 2 of the License, or
|
---|
13 | # (at your option) any later version.
|
---|
14 | #
|
---|
15 | # This program is distributed in the hope that it will be useful,
|
---|
16 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
17 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
18 | # GNU General Public License for more details.
|
---|
19 | #
|
---|
20 | # You should have received a copy of the GNU General Public License
|
---|
21 | # along with this program; if not, write to the Free Software
|
---|
22 | # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
---|
23 | #
|
---|
24 | ###########################################################################
|
---|
25 |
|
---|
26 |
|
---|
27 | package indexaction;
|
---|
28 |
|
---|
29 |
|
---|
30 | use strict;
|
---|
31 | use util;
|
---|
32 | use cgiactions::baseaction;
|
---|
33 |
|
---|
34 |
|
---|
35 | @indexaction::ISA = ('baseaction');
|
---|
36 |
|
---|
37 | # 'a' for action, and 'c' for collection are also compulsorary, and
|
---|
38 | # added in automatically by baseaction
|
---|
39 |
|
---|
40 | my $action_table =
|
---|
41 | {
|
---|
42 | "full-import" => { 'compulsory-args' => [],
|
---|
43 | 'optional-args' => [] },
|
---|
44 |
|
---|
45 | "full-buildcol" => { 'compulsory-args' => [],
|
---|
46 | 'optional-args' => [] },
|
---|
47 |
|
---|
48 | "full-rebuild" => { 'compulsory-args' => [],
|
---|
49 | 'optional-args' => [] },
|
---|
50 |
|
---|
51 |
|
---|
52 | "incremental-import" => { 'compulsory-args' => [],
|
---|
53 | 'optional-args' => [] },
|
---|
54 |
|
---|
55 | "incremental-buildcol" => { 'compulsory-args' => [],
|
---|
56 | 'optional-args' => [] },
|
---|
57 |
|
---|
58 | "incremental-rebuild" => { 'compulsory-args' => [],
|
---|
59 | 'optional-args' => [] }
|
---|
60 | };
|
---|
61 |
|
---|
62 |
|
---|
63 | sub new
|
---|
64 | {
|
---|
65 | my $class = shift (@_);
|
---|
66 | my ($gsdl_cgi,$iis6_mode) = @_;
|
---|
67 |
|
---|
68 | my $self = new baseaction($action_table,$gsdl_cgi,$iis6_mode);
|
---|
69 |
|
---|
70 | return bless $self, $class;
|
---|
71 | }
|
---|
72 |
|
---|
73 |
|
---|
74 |
|
---|
75 |
|
---|
76 |
|
---|
77 | sub run_build_cmd
|
---|
78 | {
|
---|
79 | my $self = shift @_;
|
---|
80 | my ($cmd) = @_;
|
---|
81 |
|
---|
82 | my $collect = $self->{'collect'};
|
---|
83 | my $gsdl_cgi = $self->{'gsdl_cgi'};
|
---|
84 | my $gsdl_home = $self->{'gsdlhome'};
|
---|
85 |
|
---|
86 | my $output = `$cmd 2>&1`;
|
---|
87 | my $status = $?;
|
---|
88 | my $report = undef;
|
---|
89 |
|
---|
90 | if ($status == 0) {
|
---|
91 | $report = "Perl build successful: $cmd\n--\n";
|
---|
92 | $report .= "$output\n";
|
---|
93 | }
|
---|
94 | else {
|
---|
95 | $report = "Perl rebuild failed: $cmd\n--\n";
|
---|
96 | $report .= "$output\n";
|
---|
97 | $report .= "Exit status: " . ($status / 256) . "\n";
|
---|
98 | ## $report .= $gsdl_cgi->check_perl_home();
|
---|
99 |
|
---|
100 | # $report .= "PATH = ". $ENV{'PATH'}. "\n";
|
---|
101 | }
|
---|
102 |
|
---|
103 | return($status,$report);
|
---|
104 | }
|
---|
105 |
|
---|
106 | sub full_import
|
---|
107 | {
|
---|
108 | my $self = shift @_;
|
---|
109 |
|
---|
110 | my $username = $self->{'username'};
|
---|
111 | my $collect = $self->{'collect'};
|
---|
112 | my $gsdl_cgi = $self->{'gsdl_cgi'};
|
---|
113 | my $gsdl_home = $self->{'gsdlhome'};
|
---|
114 |
|
---|
115 | # Authenticate user if it is enabled
|
---|
116 | if ($baseaction::authentication_enabled) {
|
---|
117 | # Ensure the user is allowed to edit this collection
|
---|
118 | &authenticate_user($gsdl_cgi, $username, $collect);
|
---|
119 | }
|
---|
120 |
|
---|
121 | # Obtain the collect dir
|
---|
122 | my $collect_dir = &util::filename_cat($gsdl_home, "collect");
|
---|
123 |
|
---|
124 | # Make sure the collection isn't locked by someone else
|
---|
125 | $self->lock_collection($username, $collect);
|
---|
126 |
|
---|
127 | my $bin_script = &util::filename_cat($gsdl_home,"bin","script");
|
---|
128 | my $cmd = "\"".&util::get_perl_exec()."\" -S full-import.pl \"$collect\"";
|
---|
129 |
|
---|
130 | my ($status,$report) = $self->run_build_cmd($cmd);
|
---|
131 |
|
---|
132 | # Release the lock once it is done
|
---|
133 | $self->unlock_collection($username, $collect);
|
---|
134 |
|
---|
135 | if ($status==0) {
|
---|
136 | $gsdl_cgi->generate_ok_message($report);
|
---|
137 | }
|
---|
138 | else {
|
---|
139 | $gsdl_cgi->generate_error($report);
|
---|
140 | }
|
---|
141 |
|
---|
142 | }
|
---|
143 |
|
---|
144 |
|
---|
145 | sub full_buildcol
|
---|
146 | {
|
---|
147 | my $self = shift @_;
|
---|
148 |
|
---|
149 | my $username = $self->{'username'};
|
---|
150 | my $collect = $self->{'collect'};
|
---|
151 | my $gsdl_cgi = $self->{'gsdl_cgi'};
|
---|
152 | my $gsdl_home = $self->{'gsdlhome'};
|
---|
153 |
|
---|
154 | # Authenticate user if it is enabled
|
---|
155 | if ($baseaction::authentication_enabled) {
|
---|
156 | # Ensure the user is allowed to edit this collection
|
---|
157 | &authenticate_user($gsdl_cgi, $username, $collect);
|
---|
158 | }
|
---|
159 |
|
---|
160 | # Obtain the collect dir
|
---|
161 | my $collect_dir = &util::filename_cat($gsdl_home, "collect");
|
---|
162 |
|
---|
163 | # Make sure the collection isn't locked by someone else
|
---|
164 | $self->lock_collection($username, $collect);
|
---|
165 |
|
---|
166 | my $bin_script = &util::filename_cat($gsdl_home,"bin","script");
|
---|
167 | my $cmd = "\"".&util::get_perl_exec()."\" -S full-buildcol.pl \"$collect\"";
|
---|
168 |
|
---|
169 | my ($status,$report) = $self->run_build_cmd($cmd);
|
---|
170 |
|
---|
171 | # Release the lock once it is done
|
---|
172 | $self->unlock_collection($username, $collect);
|
---|
173 |
|
---|
174 | if ($status==0) {
|
---|
175 | $gsdl_cgi->generate_ok_message($report);
|
---|
176 | }
|
---|
177 | else {
|
---|
178 | $gsdl_cgi->generate_error($report);
|
---|
179 | }
|
---|
180 | }
|
---|
181 |
|
---|
182 |
|
---|
183 | sub full_rebuild
|
---|
184 | {
|
---|
185 | my $self = shift @_;
|
---|
186 |
|
---|
187 | my $username = $self->{'username'};
|
---|
188 | my $collect = $self->{'collect'};
|
---|
189 | my $gsdl_cgi = $self->{'gsdl_cgi'};
|
---|
190 | my $gsdl_home = $self->{'gsdlhome'};
|
---|
191 |
|
---|
192 | # Authenticate user if it is enabled
|
---|
193 | if ($baseaction::authentication_enabled) {
|
---|
194 | # Ensure the user is allowed to edit this collection
|
---|
195 | &authenticate_user($gsdl_cgi, $username, $collect);
|
---|
196 | }
|
---|
197 |
|
---|
198 | # Obtain the collect dir
|
---|
199 | my $collect_dir = &util::filename_cat($gsdl_home, "collect");
|
---|
200 |
|
---|
201 | # Make sure the collection isn't locked by someone else
|
---|
202 | $self->lock_collection($username, $collect);
|
---|
203 |
|
---|
204 |
|
---|
205 | my $bin_script = &util::filename_cat($gsdl_home,"bin","script");
|
---|
206 | my $cmd = "\"".&util::get_perl_exec()."\" -S full-rebuild.pl \"$collect\"";
|
---|
207 |
|
---|
208 | my ($status,$report) = $self->run_build_cmd($cmd);
|
---|
209 |
|
---|
210 | # Release the lock once it is done
|
---|
211 | $self->unlock_collection($username, $collect);
|
---|
212 |
|
---|
213 | if ($status==0) {
|
---|
214 | $gsdl_cgi->generate_ok_message($report);
|
---|
215 | }
|
---|
216 | else {
|
---|
217 | $gsdl_cgi->generate_error($report);
|
---|
218 | }
|
---|
219 | }
|
---|
220 |
|
---|
221 |
|
---|
222 |
|
---|
223 | sub incremental_import
|
---|
224 | {
|
---|
225 | my $self = shift @_;
|
---|
226 |
|
---|
227 | my $username = $self->{'username'};
|
---|
228 | my $collect = $self->{'collect'};
|
---|
229 | my $gsdl_cgi = $self->{'gsdl_cgi'};
|
---|
230 | my $gsdl_home = $self->{'gsdlhome'};
|
---|
231 |
|
---|
232 | # Authenticate user if it is enabled
|
---|
233 | if ($baseaction::authentication_enabled) {
|
---|
234 | # Ensure the user is allowed to edit this collection
|
---|
235 | &authenticate_user($gsdl_cgi, $username, $collect);
|
---|
236 | }
|
---|
237 |
|
---|
238 | # Obtain the collect dir
|
---|
239 | my $collect_dir = &util::filename_cat($gsdl_home, "collect");
|
---|
240 |
|
---|
241 | # Make sure the collection isn't locked by someone else
|
---|
242 | $self->lock_collection($username, $collect);
|
---|
243 |
|
---|
244 |
|
---|
245 | my $bin_script = &util::filename_cat($gsdl_home,"bin","script");
|
---|
246 | my $cmd = "\"".&util::get_perl_exec()."\" -S incremental-import.pl \"$collect\"";
|
---|
247 |
|
---|
248 | my ($status,$report) = $self->run_build_cmd($cmd);
|
---|
249 |
|
---|
250 | # Release the lock once it is done
|
---|
251 | $self->unlock_collection($username, $collect);
|
---|
252 |
|
---|
253 | if ($status==0) {
|
---|
254 | $gsdl_cgi->generate_ok_message($report);
|
---|
255 | }
|
---|
256 | else {
|
---|
257 | $gsdl_cgi->generate_error($report);
|
---|
258 | }
|
---|
259 | }
|
---|
260 |
|
---|
261 |
|
---|
262 | sub incremental_buildcol
|
---|
263 | {
|
---|
264 | my $self = shift @_;
|
---|
265 |
|
---|
266 | my $username = $self->{'username'};
|
---|
267 | my $collect = $self->{'collect'};
|
---|
268 | my $gsdl_cgi = $self->{'gsdl_cgi'};
|
---|
269 | my $gsdl_home = $self->{'gsdlhome'};
|
---|
270 |
|
---|
271 | # timestamp could turn out to be useful, but not used just now
|
---|
272 |
|
---|
273 | # Authenticate user if it is enabled
|
---|
274 | if ($baseaction::authentication_enabled) {
|
---|
275 | # Ensure the user is allowed to edit this collection
|
---|
276 | &authenticate_user($gsdl_cgi, $username, $collect);
|
---|
277 | }
|
---|
278 |
|
---|
279 | # Obtain the collect dir
|
---|
280 | my $collect_dir = &util::filename_cat($gsdl_home, "collect");
|
---|
281 |
|
---|
282 | # Make sure the collection isn't locked by someone else
|
---|
283 | $self->lock_collection($username, $collect);
|
---|
284 |
|
---|
285 |
|
---|
286 | my $bin_script = &util::filename_cat($gsdl_home,"bin","script");
|
---|
287 | my $cmd = "\"".&util::get_perl_exec()."\" -S incremental-buildcol.pl \"$collect\"";
|
---|
288 |
|
---|
289 | my ($status,$report) = $self->run_build_cmd($cmd);
|
---|
290 |
|
---|
291 | # Release the lock once it is done
|
---|
292 | $self->unlock_collection($username, $collect);
|
---|
293 |
|
---|
294 | if ($status==0) {
|
---|
295 | $gsdl_cgi->generate_ok_message($report);
|
---|
296 | }
|
---|
297 | else {
|
---|
298 | $gsdl_cgi->generate_error($report);
|
---|
299 | }
|
---|
300 | }
|
---|
301 |
|
---|
302 |
|
---|
303 | sub incremental_rebuild
|
---|
304 | {
|
---|
305 | my $self = shift @_;
|
---|
306 |
|
---|
307 | my $username = $self->{'username'};
|
---|
308 | my $collect = $self->{'collect'};
|
---|
309 | my $timestamp = $self->{'timestamp'};
|
---|
310 | my $site = $self->{'site'};
|
---|
311 |
|
---|
312 | my $gsdl_cgi = $self->{'gsdl_cgi'};
|
---|
313 | my $gsdl_home = $self->{'gsdlhome'};
|
---|
314 |
|
---|
315 | # Authenticate user if it is enabled
|
---|
316 | if ($baseaction::authentication_enabled) {
|
---|
317 | # Ensure the user is allowed to edit this collection
|
---|
318 | &authenticate_user($gsdl_cgi, $username, $collect);
|
---|
319 | }
|
---|
320 |
|
---|
321 | # Make sure the collection isn't locked by someone else
|
---|
322 | $self->lock_collection($username, $collect);
|
---|
323 |
|
---|
324 | my $cmd = "\"".&util::get_perl_exec()."\" -S incremental-rebuild.pl \"$collect\"";
|
---|
325 |
|
---|
326 | my ($status,$report) = $self->run_build_cmd($cmd);
|
---|
327 |
|
---|
328 | # Release the lock once it is done
|
---|
329 | $self->unlock_collection($username, $collect);
|
---|
330 |
|
---|
331 | if ($baseaction::mail_enabled) {
|
---|
332 | $self->send_mail("Remote Greenstone building event", "Incremental building of collection '$collect' complete.");
|
---|
333 | }
|
---|
334 |
|
---|
335 | if ($status==0) {
|
---|
336 | $gsdl_cgi->generate_ok_message($report);
|
---|
337 | }
|
---|
338 | else {
|
---|
339 | $gsdl_cgi->generate_error($report);
|
---|
340 | }
|
---|
341 | }
|
---|
342 |
|
---|
343 |
|
---|
344 |
|
---|
345 |
|
---|
346 | sub incremental_rebuild_orig
|
---|
347 | {
|
---|
348 | my $self = shift @_;
|
---|
349 |
|
---|
350 | my $username = $self->{'username'};
|
---|
351 | my $collect = $self->{'collect'};
|
---|
352 | my $timestamp = $self->{'timestamp'};
|
---|
353 | my $site = $self->{'site'};
|
---|
354 |
|
---|
355 | my $gsdl_cgi = $self->{'gsdl_cgi'};
|
---|
356 |
|
---|
357 | # timestamp could turn out to be useful, but not used just now
|
---|
358 |
|
---|
359 | # don't user authenticate for now
|
---|
360 | if ($baseaction::authentication_enabled) {
|
---|
361 | # Ensure the user is allowed to edit this collection
|
---|
362 | $self->authenticate_user($username, $collect);
|
---|
363 | }
|
---|
364 |
|
---|
365 | # Make sure the collection isn't locked by someone else
|
---|
366 | $self->lock_collection($username, $collect, $site);
|
---|
367 |
|
---|
368 | $self->run_script($collect,$site,"incremental-rebuild.pl");
|
---|
369 |
|
---|
370 | if ($baseaction::mail_enabled) {
|
---|
371 | $self->send_mail("Remote Greenstone building event", "Build of collection '$collect' complete.");
|
---|
372 | }
|
---|
373 |
|
---|
374 | }
|
---|
375 |
|
---|
376 |
|
---|
377 |
|
---|
378 |
|
---|
379 |
|
---|
380 | 1;
|
---|