Index: /main/trunk/greenstone2/perllib/cgiactions/indexaction.pm
===================================================================
--- /main/trunk/greenstone2/perllib/cgiactions/indexaction.pm	(revision 23478)
+++ /main/trunk/greenstone2/perllib/cgiactions/indexaction.pm	(revision 23479)
@@ -38,10 +38,32 @@
 
 
-my $action_table = { 
-    "incremental-rebuild" => 
-    { 'compulsory-args' => [ "un", "metaname" ],
-      'optional-args'   => [] 
-      },
-  };
+
+
+
+
+# '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'   => [] }
+};
 
 
@@ -59,4 +81,231 @@
 
 
+
+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'};
+
+    # timestamp could turn out to be useful, but not used just now
+
+    # 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
 {
@@ -69,4 +318,47 @@
 
     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);
+    }
+	
+    # Make sure the collection isn't locked by someone else
+    $self->lock_collection($username, $collect);
+
+    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 ($baseaction::mail_enabled) {
+	$self->send_mail("Remote Greenstone building event", "Incremental building of collection '$collect' complete.");
+    }
+
+    if ($status==0) {
+	$gsdl_cgi->generate_ok_message($report);
+    }
+    else {
+	$gsdl_cgi->generate_error($report);
+    }
+}
+
+
+
+
+sub incremental_rebuild_orig
+{
+    my $self = shift @_;
+
+    my $username  = $self->{'username'};
+    my $collect   = $self->{'collect'};
+    my $timestamp = $self->{'timestamp'};
+    my $site      = $self->{'site'};
+
+    my $gsdl_cgi  = $self->{'gsdl_cgi'};
 
     # timestamp could turn out to be useful, but not used just now
@@ -82,5 +374,4 @@
 
     $self->run_script($collect,$site,"incremental-rebuild.pl");
-
 
     if ($baseaction::mail_enabled) {
@@ -91,3 +382,6 @@
 
 
+
+
+
 1;
