[19293] | 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 |
|
---|
| 32 | use cgiactions::baseaction;
|
---|
[24192] | 33 | use Config; # for getting the perlpath in the recommended way
|
---|
[19293] | 34 |
|
---|
| 35 |
|
---|
| 36 | @indexaction::ISA = ('baseaction');
|
---|
| 37 |
|
---|
| 38 |
|
---|
| 39 |
|
---|
| 40 |
|
---|
| 41 |
|
---|
[23479] | 42 |
|
---|
| 43 |
|
---|
| 44 | # 'a' for action, and 'c' for collection are also compulsorary, and
|
---|
| 45 | # added in automatically by baseaction
|
---|
| 46 |
|
---|
| 47 | my $action_table =
|
---|
| 48 | {
|
---|
| 49 | "full-import" => { 'compulsory-args' => [],
|
---|
| 50 | 'optional-args' => [] },
|
---|
| 51 |
|
---|
| 52 | "full-buildcol" => { 'compulsory-args' => [],
|
---|
| 53 | 'optional-args' => [] },
|
---|
| 54 |
|
---|
| 55 | "full-rebuild" => { 'compulsory-args' => [],
|
---|
| 56 | 'optional-args' => [] },
|
---|
| 57 |
|
---|
| 58 |
|
---|
| 59 | "incremental-import" => { 'compulsory-args' => [],
|
---|
| 60 | 'optional-args' => [] },
|
---|
| 61 |
|
---|
| 62 | "incremental-buildcol" => { 'compulsory-args' => [],
|
---|
| 63 | 'optional-args' => [] },
|
---|
| 64 |
|
---|
| 65 | "incremental-rebuild" => { 'compulsory-args' => [],
|
---|
| 66 | 'optional-args' => [] }
|
---|
| 67 | };
|
---|
| 68 |
|
---|
| 69 |
|
---|
[19293] | 70 | sub new
|
---|
| 71 | {
|
---|
| 72 | my $class = shift (@_);
|
---|
| 73 | my ($gsdl_cgi,$iis6_mode) = @_;
|
---|
| 74 |
|
---|
| 75 | my $self = new baseaction($action_table,$gsdl_cgi,$iis6_mode);
|
---|
| 76 |
|
---|
| 77 | return bless $self, $class;
|
---|
| 78 | }
|
---|
| 79 |
|
---|
| 80 |
|
---|
| 81 |
|
---|
| 82 |
|
---|
[23479] | 83 |
|
---|
| 84 | sub run_build_cmd
|
---|
| 85 | {
|
---|
| 86 | my $self = shift @_;
|
---|
| 87 | my ($cmd) = @_;
|
---|
| 88 |
|
---|
| 89 | my $collect = $self->{'collect'};
|
---|
| 90 | my $gsdl_cgi = $self->{'gsdl_cgi'};
|
---|
| 91 | my $gsdl_home = $self->{'gsdlhome'};
|
---|
| 92 |
|
---|
| 93 | my $output = `$cmd 2>&1`;
|
---|
| 94 | my $status = $?;
|
---|
| 95 | my $report = undef;
|
---|
| 96 |
|
---|
| 97 | if ($status == 0) {
|
---|
| 98 | $report = "Perl build successful: $cmd\n--\n";
|
---|
| 99 | $report .= "$output\n";
|
---|
| 100 | }
|
---|
| 101 | else {
|
---|
| 102 | $report = "Perl rebuild failed: $cmd\n--\n";
|
---|
| 103 | $report .= "$output\n";
|
---|
| 104 | $report .= "Exit status: " . ($status / 256) . "\n";
|
---|
| 105 | ## $report .= $gsdl_cgi->check_perl_home();
|
---|
| 106 |
|
---|
| 107 | # $report .= "PATH = ". $ENV{'PATH'}. "\n";
|
---|
| 108 | }
|
---|
| 109 |
|
---|
| 110 | return($status,$report);
|
---|
| 111 | }
|
---|
| 112 |
|
---|
| 113 | sub full_import
|
---|
| 114 | {
|
---|
| 115 | my $self = shift @_;
|
---|
| 116 |
|
---|
| 117 | my $username = $self->{'username'};
|
---|
| 118 | my $collect = $self->{'collect'};
|
---|
| 119 | my $gsdl_cgi = $self->{'gsdl_cgi'};
|
---|
| 120 | my $gsdl_home = $self->{'gsdlhome'};
|
---|
| 121 |
|
---|
| 122 | # Authenticate user if it is enabled
|
---|
| 123 | if ($baseaction::authentication_enabled) {
|
---|
| 124 | # Ensure the user is allowed to edit this collection
|
---|
| 125 | &authenticate_user($gsdl_cgi, $username, $collect);
|
---|
| 126 | }
|
---|
| 127 |
|
---|
| 128 | # Obtain the collect dir
|
---|
| 129 | my $collect_dir = &util::filename_cat($gsdl_home, "collect");
|
---|
| 130 |
|
---|
| 131 | # Make sure the collection isn't locked by someone else
|
---|
| 132 | $self->lock_collection($username, $collect);
|
---|
| 133 |
|
---|
| 134 | my $bin_script = &util::filename_cat($gsdl_home,"bin","script");
|
---|
[24192] | 135 | my $cmd = "\"$Config{perlpath}\" -S full-import.pl \"$collect\"";
|
---|
[23479] | 136 |
|
---|
| 137 | my ($status,$report) = $self->run_build_cmd($cmd);
|
---|
| 138 |
|
---|
| 139 | # Release the lock once it is done
|
---|
| 140 | $self->unlock_collection($username, $collect);
|
---|
| 141 |
|
---|
| 142 | if ($status==0) {
|
---|
| 143 | $gsdl_cgi->generate_ok_message($report);
|
---|
| 144 | }
|
---|
| 145 | else {
|
---|
| 146 | $gsdl_cgi->generate_error($report);
|
---|
| 147 | }
|
---|
| 148 |
|
---|
| 149 | }
|
---|
| 150 |
|
---|
| 151 |
|
---|
| 152 | sub full_buildcol
|
---|
| 153 | {
|
---|
| 154 | my $self = shift @_;
|
---|
| 155 |
|
---|
| 156 | my $username = $self->{'username'};
|
---|
| 157 | my $collect = $self->{'collect'};
|
---|
| 158 | my $gsdl_cgi = $self->{'gsdl_cgi'};
|
---|
| 159 | my $gsdl_home = $self->{'gsdlhome'};
|
---|
| 160 |
|
---|
| 161 | # Authenticate user if it is enabled
|
---|
| 162 | if ($baseaction::authentication_enabled) {
|
---|
| 163 | # Ensure the user is allowed to edit this collection
|
---|
| 164 | &authenticate_user($gsdl_cgi, $username, $collect);
|
---|
| 165 | }
|
---|
| 166 |
|
---|
| 167 | # Obtain the collect dir
|
---|
| 168 | my $collect_dir = &util::filename_cat($gsdl_home, "collect");
|
---|
| 169 |
|
---|
| 170 | # Make sure the collection isn't locked by someone else
|
---|
| 171 | $self->lock_collection($username, $collect);
|
---|
| 172 |
|
---|
| 173 | my $bin_script = &util::filename_cat($gsdl_home,"bin","script");
|
---|
[24192] | 174 | my $cmd = "\"$Config{perlpath}\" -S full-buildcol.pl \"$collect\"";
|
---|
[23479] | 175 |
|
---|
| 176 | my ($status,$report) = $self->run_build_cmd($cmd);
|
---|
| 177 |
|
---|
| 178 | # Release the lock once it is done
|
---|
| 179 | $self->unlock_collection($username, $collect);
|
---|
| 180 |
|
---|
| 181 | if ($status==0) {
|
---|
| 182 | $gsdl_cgi->generate_ok_message($report);
|
---|
| 183 | }
|
---|
| 184 | else {
|
---|
| 185 | $gsdl_cgi->generate_error($report);
|
---|
| 186 | }
|
---|
| 187 | }
|
---|
| 188 |
|
---|
| 189 |
|
---|
| 190 | sub full_rebuild
|
---|
| 191 | {
|
---|
| 192 | my $self = shift @_;
|
---|
| 193 |
|
---|
| 194 | my $username = $self->{'username'};
|
---|
| 195 | my $collect = $self->{'collect'};
|
---|
| 196 | my $gsdl_cgi = $self->{'gsdl_cgi'};
|
---|
| 197 | my $gsdl_home = $self->{'gsdlhome'};
|
---|
| 198 |
|
---|
| 199 | # Authenticate user if it is enabled
|
---|
| 200 | if ($baseaction::authentication_enabled) {
|
---|
| 201 | # Ensure the user is allowed to edit this collection
|
---|
| 202 | &authenticate_user($gsdl_cgi, $username, $collect);
|
---|
| 203 | }
|
---|
| 204 |
|
---|
| 205 | # Obtain the collect dir
|
---|
| 206 | my $collect_dir = &util::filename_cat($gsdl_home, "collect");
|
---|
| 207 |
|
---|
| 208 | # Make sure the collection isn't locked by someone else
|
---|
| 209 | $self->lock_collection($username, $collect);
|
---|
| 210 |
|
---|
| 211 |
|
---|
| 212 | my $bin_script = &util::filename_cat($gsdl_home,"bin","script");
|
---|
[24192] | 213 | my $cmd = "\"$Config{perlpath}\" -S full-rebuild.pl \"$collect\"";
|
---|
[23479] | 214 |
|
---|
| 215 | my ($status,$report) = $self->run_build_cmd($cmd);
|
---|
| 216 |
|
---|
| 217 | # Release the lock once it is done
|
---|
| 218 | $self->unlock_collection($username, $collect);
|
---|
| 219 |
|
---|
| 220 | if ($status==0) {
|
---|
| 221 | $gsdl_cgi->generate_ok_message($report);
|
---|
| 222 | }
|
---|
| 223 | else {
|
---|
| 224 | $gsdl_cgi->generate_error($report);
|
---|
| 225 | }
|
---|
| 226 | }
|
---|
| 227 |
|
---|
| 228 |
|
---|
| 229 |
|
---|
| 230 | sub incremental_import
|
---|
| 231 | {
|
---|
| 232 | my $self = shift @_;
|
---|
| 233 |
|
---|
| 234 | my $username = $self->{'username'};
|
---|
| 235 | my $collect = $self->{'collect'};
|
---|
| 236 | my $gsdl_cgi = $self->{'gsdl_cgi'};
|
---|
| 237 | my $gsdl_home = $self->{'gsdlhome'};
|
---|
| 238 |
|
---|
| 239 | # Authenticate user if it is enabled
|
---|
| 240 | if ($baseaction::authentication_enabled) {
|
---|
| 241 | # Ensure the user is allowed to edit this collection
|
---|
| 242 | &authenticate_user($gsdl_cgi, $username, $collect);
|
---|
| 243 | }
|
---|
| 244 |
|
---|
| 245 | # Obtain the collect dir
|
---|
| 246 | my $collect_dir = &util::filename_cat($gsdl_home, "collect");
|
---|
| 247 |
|
---|
| 248 | # Make sure the collection isn't locked by someone else
|
---|
| 249 | $self->lock_collection($username, $collect);
|
---|
| 250 |
|
---|
| 251 |
|
---|
| 252 | my $bin_script = &util::filename_cat($gsdl_home,"bin","script");
|
---|
[24192] | 253 | my $cmd = "\"$Config{perlpath}\" -S incremental-import.pl \"$collect\"";
|
---|
[23479] | 254 |
|
---|
| 255 | my ($status,$report) = $self->run_build_cmd($cmd);
|
---|
| 256 |
|
---|
| 257 | # Release the lock once it is done
|
---|
| 258 | $self->unlock_collection($username, $collect);
|
---|
| 259 |
|
---|
| 260 | if ($status==0) {
|
---|
| 261 | $gsdl_cgi->generate_ok_message($report);
|
---|
| 262 | }
|
---|
| 263 | else {
|
---|
| 264 | $gsdl_cgi->generate_error($report);
|
---|
| 265 | }
|
---|
| 266 | }
|
---|
| 267 |
|
---|
| 268 |
|
---|
| 269 | sub incremental_buildcol
|
---|
| 270 | {
|
---|
| 271 | my $self = shift @_;
|
---|
| 272 |
|
---|
| 273 | my $username = $self->{'username'};
|
---|
| 274 | my $collect = $self->{'collect'};
|
---|
| 275 | my $gsdl_cgi = $self->{'gsdl_cgi'};
|
---|
| 276 | my $gsdl_home = $self->{'gsdlhome'};
|
---|
| 277 |
|
---|
| 278 | # timestamp could turn out to be useful, but not used just now
|
---|
| 279 |
|
---|
| 280 | # Authenticate user if it is enabled
|
---|
| 281 | if ($baseaction::authentication_enabled) {
|
---|
| 282 | # Ensure the user is allowed to edit this collection
|
---|
| 283 | &authenticate_user($gsdl_cgi, $username, $collect);
|
---|
| 284 | }
|
---|
| 285 |
|
---|
| 286 | # Obtain the collect dir
|
---|
| 287 | my $collect_dir = &util::filename_cat($gsdl_home, "collect");
|
---|
| 288 |
|
---|
| 289 | # Make sure the collection isn't locked by someone else
|
---|
| 290 | $self->lock_collection($username, $collect);
|
---|
| 291 |
|
---|
| 292 |
|
---|
| 293 | my $bin_script = &util::filename_cat($gsdl_home,"bin","script");
|
---|
[24192] | 294 | my $cmd = "\"$Config{perlpath}\" -S incremental-buildcol.pl \"$collect\"";
|
---|
[23479] | 295 |
|
---|
| 296 | my ($status,$report) = $self->run_build_cmd($cmd);
|
---|
| 297 |
|
---|
| 298 | # Release the lock once it is done
|
---|
| 299 | $self->unlock_collection($username, $collect);
|
---|
| 300 |
|
---|
| 301 | if ($status==0) {
|
---|
| 302 | $gsdl_cgi->generate_ok_message($report);
|
---|
| 303 | }
|
---|
| 304 | else {
|
---|
| 305 | $gsdl_cgi->generate_error($report);
|
---|
| 306 | }
|
---|
| 307 | }
|
---|
| 308 |
|
---|
| 309 |
|
---|
[19293] | 310 | sub incremental_rebuild
|
---|
| 311 | {
|
---|
| 312 | my $self = shift @_;
|
---|
| 313 |
|
---|
| 314 | my $username = $self->{'username'};
|
---|
| 315 | my $collect = $self->{'collect'};
|
---|
| 316 | my $timestamp = $self->{'timestamp'};
|
---|
| 317 | my $site = $self->{'site'};
|
---|
| 318 |
|
---|
| 319 | my $gsdl_cgi = $self->{'gsdl_cgi'};
|
---|
[23479] | 320 | my $gsdl_home = $self->{'gsdlhome'};
|
---|
[19293] | 321 |
|
---|
[23479] | 322 | # Authenticate user if it is enabled
|
---|
| 323 | if ($baseaction::authentication_enabled) {
|
---|
| 324 | # Ensure the user is allowed to edit this collection
|
---|
| 325 | &authenticate_user($gsdl_cgi, $username, $collect);
|
---|
| 326 | }
|
---|
| 327 |
|
---|
| 328 | # Make sure the collection isn't locked by someone else
|
---|
| 329 | $self->lock_collection($username, $collect);
|
---|
| 330 |
|
---|
[24192] | 331 | my $cmd = "\"$Config{perlpath}\" -S incremental-rebuild.pl \"$collect\"";
|
---|
[23479] | 332 |
|
---|
| 333 | my ($status,$report) = $self->run_build_cmd($cmd);
|
---|
| 334 |
|
---|
| 335 | # Release the lock once it is done
|
---|
| 336 | $self->unlock_collection($username, $collect);
|
---|
| 337 |
|
---|
| 338 | if ($baseaction::mail_enabled) {
|
---|
| 339 | $self->send_mail("Remote Greenstone building event", "Incremental building of collection '$collect' complete.");
|
---|
| 340 | }
|
---|
| 341 |
|
---|
| 342 | if ($status==0) {
|
---|
| 343 | $gsdl_cgi->generate_ok_message($report);
|
---|
| 344 | }
|
---|
| 345 | else {
|
---|
| 346 | $gsdl_cgi->generate_error($report);
|
---|
| 347 | }
|
---|
| 348 | }
|
---|
| 349 |
|
---|
| 350 |
|
---|
| 351 |
|
---|
| 352 |
|
---|
| 353 | sub incremental_rebuild_orig
|
---|
| 354 | {
|
---|
| 355 | my $self = shift @_;
|
---|
| 356 |
|
---|
| 357 | my $username = $self->{'username'};
|
---|
| 358 | my $collect = $self->{'collect'};
|
---|
| 359 | my $timestamp = $self->{'timestamp'};
|
---|
| 360 | my $site = $self->{'site'};
|
---|
| 361 |
|
---|
| 362 | my $gsdl_cgi = $self->{'gsdl_cgi'};
|
---|
| 363 |
|
---|
[19293] | 364 | # timestamp could turn out to be useful, but not used just now
|
---|
| 365 |
|
---|
| 366 | # don't user authenticate for now
|
---|
| 367 | if ($baseaction::authentication_enabled) {
|
---|
| 368 | # Ensure the user is allowed to edit this collection
|
---|
| 369 | $self->authenticate_user($username, $collect);
|
---|
| 370 | }
|
---|
| 371 |
|
---|
| 372 | # Make sure the collection isn't locked by someone else
|
---|
| 373 | $self->lock_collection($username, $collect, $site);
|
---|
| 374 |
|
---|
| 375 | $self->run_script($collect,$site,"incremental-rebuild.pl");
|
---|
| 376 |
|
---|
| 377 | if ($baseaction::mail_enabled) {
|
---|
| 378 | $self->send_mail("Remote Greenstone building event", "Build of collection '$collect' complete.");
|
---|
| 379 | }
|
---|
| 380 |
|
---|
| 381 | }
|
---|
| 382 |
|
---|
| 383 |
|
---|
[23479] | 384 |
|
---|
| 385 |
|
---|
| 386 |
|
---|
[19293] | 387 | 1;
|
---|