###########################################################################
#
# indexaction.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 indexaction;


use strict;

use cgiactions::baseaction;



@indexaction::ISA = ('baseaction');



my $action_table = { 
    "incremental-rebuild" => 
    { 'compulsory-args' => [ "un", "metaname" ],
      '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 incremental_rebuild
{
    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

    # don't user authenticate for now
    if ($baseaction::authentication_enabled) {
	# Ensure the user is allowed to edit this collection
	$self->authenticate_user($username, $collect);
    }

    # Make sure the collection isn't locked by someone else
    $self->lock_collection($username, $collect, $site);

    $self->run_script($collect,$site,"incremental-rebuild.pl");


    if ($baseaction::mail_enabled) {
	$self->send_mail("Remote Greenstone building event", "Build of collection '$collect' complete.");
    }

}


1;
