Index: /main/trunk/greenstone2/cgi-bin/build-server.pl
===================================================================
--- /main/trunk/greenstone2/cgi-bin/build-server.pl	(revision 23469)
+++ /main/trunk/greenstone2/cgi-bin/build-server.pl	(revision 23469)
@@ -0,0 +1,61 @@
+#!/usr/bin/perl -w
+##!C:\\Perl\\bin\\perl -w 
+# If not explicitly associating .pl filename ending with Perl in the
+# web server's configuration file, then need to specify the full path of
+# Perl above
+
+use strict;
+
+BEGIN {
+    # Line to stop annoying child DOS CMD windows from appearing
+    Win32::SetChildShowWindow(0)
+	if defined &Win32::SetChildShowWindow;
+}
+
+# Set this to 1 to work around IIS 6 craziness
+my $iis6_mode = 0;
+
+
+# IIS 6: for some reason, IIS runs this script with the working
+#   directory set to the Greenstone directory rather than the cgi-bin
+#   directory, causing lots of stuff to fail
+if ($iis6_mode)
+{
+    # Change into cgi-bin directory
+    chdir("cgi-bin");
+}
+
+
+# We use require and an eval here (instead of "use") to catch any
+# errors loading the module (for IIS)
+eval('require "./gsdlCGI.pm"');
+if ($@)
+{
+    print STDOUT "Content-type:text/plain\n\n";
+    print STDOUT "ERROR: $@\n";
+    exit 0;
+}
+
+sub main
+{
+    my $gsdl_cgi = new gsdlCGI();
+
+    # Load the Greenstone modules that we need to use
+    $gsdl_cgi->setup_gsdl();
+	
+    my $gsdlhome = $ENV{'GSDLHOME'};
+    $gsdl_cgi->checked_chdir($gsdlhome);
+
+    require cgiactions::buildaction;
+    
+    $gsdl_cgi->parse_cgi_args();
+
+    # We don't want the gsdlCGI module to return errors and warnings in XML
+    $gsdl_cgi->{'xml'} = 0;
+
+    my $action = new buildaction($gsdl_cgi,$iis6_mode);
+
+    $action->do_action();
+}
+
+&main();
Index: /main/trunk/greenstone2/perllib/cgiactions/buildaction.pm
===================================================================
--- /main/trunk/greenstone2/perllib/cgiactions/buildaction.pm	(revision 23469)
+++ /main/trunk/greenstone2/perllib/cgiactions/buildaction.pm	(revision 23469)
@@ -0,0 +1,348 @@
+###########################################################################
+#
+# buildaction.pm -- 
+# A component of the Greenstone digital library software
+# from the New Zealand Digital Library Project at the 
+# University of Waikato, New Zealand.
+#
+# Copyright (C) 2009 New Zealand Digital Library Project
+#
+# This program is free software; you can redistr   te it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+#
+###########################################################################
+
+package buildaction;
+
+use strict;
+
+use cgiactions::baseaction;
+
+use dbutil;
+use ghtml;
+
+
+BEGIN {
+#    unshift (@INC, "$ENV{'GSDLHOME'}/perllib/cpan/perl-5.8");
+    require XML::Rules;
+}
+
+
+@buildaction::ISA = ('baseaction');
+
+
+# 'a' for action, and 'c' for collection are also compulsorary, and
+# added in automatically by baseaction
+
+my $action_table =
+{ 
+    "full-import"          => { 'compulsory-args' => [],
+				'optional-args'   => [] }, 
+    
+    "full-buildcol"        => { 'compulsory-args' => [],
+				'optional-args'   => [] },
+    
+    "full-rebuild"         => { 'compulsory-args' => [],
+				'optional-args'   => [] },
+    
+    
+    "incremental-import"   => { 'compulsory-args' => [],
+				'optional-args'   => [] }, 
+
+    "incremental-buildcol" => { 'compulsory-args' => [],
+				'optional-args'   => [] },
+    
+    "incremental-rebuild" => { 'compulsory-args' => [],
+			       'optional-args'   => [] }
+};
+
+
+sub new 
+{
+    my $class = shift (@_);
+    my ($gsdl_cgi,$iis6_mode) = @_;
+
+    my $self = new baseaction($action_table,$gsdl_cgi,$iis6_mode);
+
+    return bless $self, $class;
+}
+
+
+sub run_build_cmd
+{
+    my $self = shift @_;
+    my ($cmd) = @_;
+
+    my $collect   = $self->{'collect'};
+    my $gsdl_cgi  = $self->{'gsdl_cgi'};
+    my $gsdl_home  = $self->{'gsdlhome'};
+
+    my $output = `$cmd 2>&1`;
+    my $status = $?;
+    my $report = undef;
+
+    if ($status == 0) {
+	$report = "Perl build successful: $cmd\n--\n";
+	$report .= "$output\n";
+    }
+    else {
+	$report = "Perl rebuild failed: $cmd\n--\n";
+	$report .= "$output\n";
+	$report .= "Exit status: " . ($status / 256) . "\n";
+##	$report .= $gsdl_cgi->check_perl_home();
+
+#	$report .= "PATH = ". $ENV{'PATH'}. "\n";
+    }
+
+    return($status,$report);
+}
+
+sub full_import
+{
+    my $self = shift @_;
+
+    my $username  = $self->{'username'};
+    my $collect   = $self->{'collect'};
+    my $gsdl_cgi  = $self->{'gsdl_cgi'};
+    my $gsdl_home  = $self->{'gsdlhome'};
+
+    # Authenticate user if it is enabled
+    if ($baseaction::authentication_enabled) {
+	# Ensure the user is allowed to edit this collection
+	&authenticate_user($gsdl_cgi, $username, $collect);
+    }
+	
+    # Obtain the collect dir
+    my $collect_dir = &util::filename_cat($gsdl_home, "collect");
+
+    # Make sure the collection isn't locked by someone else
+    $self->lock_collection($username, $collect);
+
+    my $bin_script = &util::filename_cat($gsdl_home,"bin","script");
+    my $cmd = "perl -S full-import.pl \"$collect\"";
+
+    my ($status,$report) = $self->run_build_cmd($cmd);
+   
+    # Release the lock once it is done
+    $self->unlock_collection($username, $collect);
+
+    if ($status==0) {
+	$gsdl_cgi->generate_ok_message($report);
+    }
+    else {
+	$gsdl_cgi->generate_error($report);
+    }
+
+}
+
+
+sub full_buildcol
+{
+    my $self = shift @_;
+
+    my $username  = $self->{'username'};
+    my $collect   = $self->{'collect'};
+    my $gsdl_cgi  = $self->{'gsdl_cgi'};
+    my $gsdl_home  = $self->{'gsdlhome'};
+
+    # Authenticate user if it is enabled
+    if ($baseaction::authentication_enabled) {
+	# Ensure the user is allowed to edit this collection
+	&authenticate_user($gsdl_cgi, $username, $collect);
+    }
+    
+    # Obtain the collect dir
+    my $collect_dir = &util::filename_cat($gsdl_home, "collect");
+
+    # Make sure the collection isn't locked by someone else
+    $self->lock_collection($username, $collect);
+
+    my $bin_script = &util::filename_cat($gsdl_home,"bin","script");
+    my $cmd = "perl -S full-buildcol.pl \"$collect\"";
+
+    my ($status,$report) = $self->run_build_cmd($cmd);
+   
+    # Release the lock once it is done
+    $self->unlock_collection($username, $collect);
+
+    if ($status==0) {
+	$gsdl_cgi->generate_ok_message($report);
+    }
+    else {
+	$gsdl_cgi->generate_error($report);
+    }
+}
+
+
+sub full_rebuild
+{
+    my $self = shift @_;
+
+    my $username  = $self->{'username'};
+    my $collect   = $self->{'collect'};
+    my $gsdl_cgi  = $self->{'gsdl_cgi'};
+    my $gsdl_home  = $self->{'gsdlhome'};
+
+    # Authenticate user if it is enabled
+    if ($baseaction::authentication_enabled) {
+	# Ensure the user is allowed to edit this collection
+	&authenticate_user($gsdl_cgi, $username, $collect);
+    }
+	
+    # Obtain the collect dir
+    my $collect_dir = &util::filename_cat($gsdl_home, "collect");
+
+    # Make sure the collection isn't locked by someone else
+    $self->lock_collection($username, $collect);
+
+
+    my $bin_script = &util::filename_cat($gsdl_home,"bin","script");
+    my $cmd = "perl -S full-rebuild.pl \"$collect\"";
+
+    my ($status,$report) = $self->run_build_cmd($cmd);
+   
+    # Release the lock once it is done
+    $self->unlock_collection($username, $collect);
+
+    if ($status==0) {
+	$gsdl_cgi->generate_ok_message($report);
+    }
+    else {
+	$gsdl_cgi->generate_error($report);
+    }
+}
+
+
+
+sub incremental_import
+{
+    my $self = shift @_;
+
+    my $username  = $self->{'username'};
+    my $collect   = $self->{'collect'};
+    my $gsdl_cgi  = $self->{'gsdl_cgi'};
+    my $gsdl_home  = $self->{'gsdlhome'};
+
+    # Authenticate user if it is enabled
+    if ($baseaction::authentication_enabled) {
+	# Ensure the user is allowed to edit this collection
+	&authenticate_user($gsdl_cgi, $username, $collect);
+    }
+	
+    # Obtain the collect dir
+    my $collect_dir = &util::filename_cat($gsdl_home, "collect");
+
+    # Make sure the collection isn't locked by someone else
+    $self->lock_collection($username, $collect);
+
+
+    my $bin_script = &util::filename_cat($gsdl_home,"bin","script");
+    my $cmd = "perl -S incremental-import.pl \"$collect\"";
+
+    my ($status,$report) = $self->run_build_cmd($cmd);
+   
+    # Release the lock once it is done
+    $self->unlock_collection($username, $collect);
+
+    if ($status==0) {
+	$gsdl_cgi->generate_ok_message($report);
+    }
+    else {
+	$gsdl_cgi->generate_error($report);
+    }
+}
+
+
+sub incremental_buildcol
+{
+    my $self = shift @_;
+
+    my $username  = $self->{'username'};
+    my $collect   = $self->{'collect'};
+    my $gsdl_cgi  = $self->{'gsdl_cgi'};
+    my $gsdl_home  = $self->{'gsdlhome'};
+
+    # Authenticate user if it is enabled
+    if ($baseaction::authentication_enabled) {
+	# Ensure the user is allowed to edit this collection
+	&authenticate_user($gsdl_cgi, $username, $collect);
+    }
+    
+    # Obtain the collect dir
+    my $collect_dir = &util::filename_cat($gsdl_home, "collect");
+
+    # Make sure the collection isn't locked by someone else
+    $self->lock_collection($username, $collect);
+
+
+    my $bin_script = &util::filename_cat($gsdl_home,"bin","script");
+    my $cmd = "perl -S incremental-buildcol.pl \"$collect\"";
+
+    my ($status,$report) = $self->run_build_cmd($cmd);
+   
+    # Release the lock once it is done
+    $self->unlock_collection($username, $collect);
+
+    if ($status==0) {
+	$gsdl_cgi->generate_ok_message($report);
+    }
+    else {
+	$gsdl_cgi->generate_error($report);
+    }
+}
+
+
+sub incremental_rebuild
+{
+    my $self = shift @_;
+
+    my $username  = $self->{'username'};
+    my $collect   = $self->{'collect'};
+    my $gsdl_cgi  = $self->{'gsdl_cgi'};
+    my $gsdl_home  = $self->{'gsdlhome'};
+
+    # Authenticate user if it is enabled
+    if ($baseaction::authentication_enabled) {
+	# Ensure the user is allowed to edit this collection
+	&authenticate_user($gsdl_cgi, $username, $collect);
+    }
+	
+    # Obtain the collect dir
+    my $collect_dir = &util::filename_cat($gsdl_home, "collect");
+
+    # Make sure the collection isn't locked by someone else
+    $self->lock_collection($username, $collect);
+
+
+    my $bin_script = &util::filename_cat($gsdl_home,"bin","script");
+    my $cmd = "perl -S incremental-rebuild.pl \"$collect\"";
+
+    my ($status,$report) = $self->run_build_cmd($cmd);
+   
+    # Release the lock once it is done
+    $self->unlock_collection($username, $collect);
+
+    if ($status==0) {
+	$gsdl_cgi->generate_ok_message($report);
+    }
+    else {
+	$gsdl_cgi->generate_error($report);
+    }
+}
+
+
+
+
+
+1;
