source: main/trunk/greenstone2/perllib/cgiactions/buildaction.pm@ 23469

Last change on this file since 23469 was 23469, checked in by davidb, 13 years ago

Initial cut at code to support collection building thrugh AJAX calls to Perl CGI scripts

  • Property svn:executable set to *
File size: 8.8 KB
Line 
1###########################################################################
2#
3# buildaction.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
26package buildaction;
27
28use strict;
29
30use cgiactions::baseaction;
31
32use dbutil;
33use ghtml;
34
35
36BEGIN {
37# unshift (@INC, "$ENV{'GSDLHOME'}/perllib/cpan/perl-5.8");
38 require XML::Rules;
39}
40
41
42@buildaction::ISA = ('baseaction');
43
44
45# 'a' for action, and 'c' for collection are also compulsorary, and
46# added in automatically by baseaction
47
48my $action_table =
49{
50 "full-import" => { 'compulsory-args' => [],
51 'optional-args' => [] },
52
53 "full-buildcol" => { 'compulsory-args' => [],
54 'optional-args' => [] },
55
56 "full-rebuild" => { 'compulsory-args' => [],
57 'optional-args' => [] },
58
59
60 "incremental-import" => { 'compulsory-args' => [],
61 'optional-args' => [] },
62
63 "incremental-buildcol" => { 'compulsory-args' => [],
64 'optional-args' => [] },
65
66 "incremental-rebuild" => { 'compulsory-args' => [],
67 'optional-args' => [] }
68};
69
70
71sub new
72{
73 my $class = shift (@_);
74 my ($gsdl_cgi,$iis6_mode) = @_;
75
76 my $self = new baseaction($action_table,$gsdl_cgi,$iis6_mode);
77
78 return bless $self, $class;
79}
80
81
82sub run_build_cmd
83{
84 my $self = shift @_;
85 my ($cmd) = @_;
86
87 my $collect = $self->{'collect'};
88 my $gsdl_cgi = $self->{'gsdl_cgi'};
89 my $gsdl_home = $self->{'gsdlhome'};
90
91 my $output = `$cmd 2>&1`;
92 my $status = $?;
93 my $report = undef;
94
95 if ($status == 0) {
96 $report = "Perl build successful: $cmd\n--\n";
97 $report .= "$output\n";
98 }
99 else {
100 $report = "Perl rebuild failed: $cmd\n--\n";
101 $report .= "$output\n";
102 $report .= "Exit status: " . ($status / 256) . "\n";
103## $report .= $gsdl_cgi->check_perl_home();
104
105# $report .= "PATH = ". $ENV{'PATH'}. "\n";
106 }
107
108 return($status,$report);
109}
110
111sub full_import
112{
113 my $self = shift @_;
114
115 my $username = $self->{'username'};
116 my $collect = $self->{'collect'};
117 my $gsdl_cgi = $self->{'gsdl_cgi'};
118 my $gsdl_home = $self->{'gsdlhome'};
119
120 # Authenticate user if it is enabled
121 if ($baseaction::authentication_enabled) {
122 # Ensure the user is allowed to edit this collection
123 &authenticate_user($gsdl_cgi, $username, $collect);
124 }
125
126 # Obtain the collect dir
127 my $collect_dir = &util::filename_cat($gsdl_home, "collect");
128
129 # Make sure the collection isn't locked by someone else
130 $self->lock_collection($username, $collect);
131
132 my $bin_script = &util::filename_cat($gsdl_home,"bin","script");
133 my $cmd = "perl -S full-import.pl \"$collect\"";
134
135 my ($status,$report) = $self->run_build_cmd($cmd);
136
137 # Release the lock once it is done
138 $self->unlock_collection($username, $collect);
139
140 if ($status==0) {
141 $gsdl_cgi->generate_ok_message($report);
142 }
143 else {
144 $gsdl_cgi->generate_error($report);
145 }
146
147}
148
149
150sub full_buildcol
151{
152 my $self = shift @_;
153
154 my $username = $self->{'username'};
155 my $collect = $self->{'collect'};
156 my $gsdl_cgi = $self->{'gsdl_cgi'};
157 my $gsdl_home = $self->{'gsdlhome'};
158
159 # Authenticate user if it is enabled
160 if ($baseaction::authentication_enabled) {
161 # Ensure the user is allowed to edit this collection
162 &authenticate_user($gsdl_cgi, $username, $collect);
163 }
164
165 # Obtain the collect dir
166 my $collect_dir = &util::filename_cat($gsdl_home, "collect");
167
168 # Make sure the collection isn't locked by someone else
169 $self->lock_collection($username, $collect);
170
171 my $bin_script = &util::filename_cat($gsdl_home,"bin","script");
172 my $cmd = "perl -S full-buildcol.pl \"$collect\"";
173
174 my ($status,$report) = $self->run_build_cmd($cmd);
175
176 # Release the lock once it is done
177 $self->unlock_collection($username, $collect);
178
179 if ($status==0) {
180 $gsdl_cgi->generate_ok_message($report);
181 }
182 else {
183 $gsdl_cgi->generate_error($report);
184 }
185}
186
187
188sub full_rebuild
189{
190 my $self = shift @_;
191
192 my $username = $self->{'username'};
193 my $collect = $self->{'collect'};
194 my $gsdl_cgi = $self->{'gsdl_cgi'};
195 my $gsdl_home = $self->{'gsdlhome'};
196
197 # Authenticate user if it is enabled
198 if ($baseaction::authentication_enabled) {
199 # Ensure the user is allowed to edit this collection
200 &authenticate_user($gsdl_cgi, $username, $collect);
201 }
202
203 # Obtain the collect dir
204 my $collect_dir = &util::filename_cat($gsdl_home, "collect");
205
206 # Make sure the collection isn't locked by someone else
207 $self->lock_collection($username, $collect);
208
209
210 my $bin_script = &util::filename_cat($gsdl_home,"bin","script");
211 my $cmd = "perl -S full-rebuild.pl \"$collect\"";
212
213 my ($status,$report) = $self->run_build_cmd($cmd);
214
215 # Release the lock once it is done
216 $self->unlock_collection($username, $collect);
217
218 if ($status==0) {
219 $gsdl_cgi->generate_ok_message($report);
220 }
221 else {
222 $gsdl_cgi->generate_error($report);
223 }
224}
225
226
227
228sub incremental_import
229{
230 my $self = shift @_;
231
232 my $username = $self->{'username'};
233 my $collect = $self->{'collect'};
234 my $gsdl_cgi = $self->{'gsdl_cgi'};
235 my $gsdl_home = $self->{'gsdlhome'};
236
237 # Authenticate user if it is enabled
238 if ($baseaction::authentication_enabled) {
239 # Ensure the user is allowed to edit this collection
240 &authenticate_user($gsdl_cgi, $username, $collect);
241 }
242
243 # Obtain the collect dir
244 my $collect_dir = &util::filename_cat($gsdl_home, "collect");
245
246 # Make sure the collection isn't locked by someone else
247 $self->lock_collection($username, $collect);
248
249
250 my $bin_script = &util::filename_cat($gsdl_home,"bin","script");
251 my $cmd = "perl -S incremental-import.pl \"$collect\"";
252
253 my ($status,$report) = $self->run_build_cmd($cmd);
254
255 # Release the lock once it is done
256 $self->unlock_collection($username, $collect);
257
258 if ($status==0) {
259 $gsdl_cgi->generate_ok_message($report);
260 }
261 else {
262 $gsdl_cgi->generate_error($report);
263 }
264}
265
266
267sub incremental_buildcol
268{
269 my $self = shift @_;
270
271 my $username = $self->{'username'};
272 my $collect = $self->{'collect'};
273 my $gsdl_cgi = $self->{'gsdl_cgi'};
274 my $gsdl_home = $self->{'gsdlhome'};
275
276 # Authenticate user if it is enabled
277 if ($baseaction::authentication_enabled) {
278 # Ensure the user is allowed to edit this collection
279 &authenticate_user($gsdl_cgi, $username, $collect);
280 }
281
282 # Obtain the collect dir
283 my $collect_dir = &util::filename_cat($gsdl_home, "collect");
284
285 # Make sure the collection isn't locked by someone else
286 $self->lock_collection($username, $collect);
287
288
289 my $bin_script = &util::filename_cat($gsdl_home,"bin","script");
290 my $cmd = "perl -S incremental-buildcol.pl \"$collect\"";
291
292 my ($status,$report) = $self->run_build_cmd($cmd);
293
294 # Release the lock once it is done
295 $self->unlock_collection($username, $collect);
296
297 if ($status==0) {
298 $gsdl_cgi->generate_ok_message($report);
299 }
300 else {
301 $gsdl_cgi->generate_error($report);
302 }
303}
304
305
306sub incremental_rebuild
307{
308 my $self = shift @_;
309
310 my $username = $self->{'username'};
311 my $collect = $self->{'collect'};
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 # Obtain the collect dir
322 my $collect_dir = &util::filename_cat($gsdl_home, "collect");
323
324 # Make sure the collection isn't locked by someone else
325 $self->lock_collection($username, $collect);
326
327
328 my $bin_script = &util::filename_cat($gsdl_home,"bin","script");
329 my $cmd = "perl -S incremental-rebuild.pl \"$collect\"";
330
331 my ($status,$report) = $self->run_build_cmd($cmd);
332
333 # Release the lock once it is done
334 $self->unlock_collection($username, $collect);
335
336 if ($status==0) {
337 $gsdl_cgi->generate_ok_message($report);
338 }
339 else {
340 $gsdl_cgi->generate_error($report);
341 }
342}
343
344
345
346
347
3481;
Note: See TracBrowser for help on using the repository browser.