#!/usr/bin/perl -w

use FindBin;
use lib "$FindBin::Bin/../../perl_lib";

#-d:DProf

######################################################################
#
#  __COPYRIGHT__
#
# Copyright 2000-2008 University of Southampton. All Rights Reserved.
# 
#  __LICENSE__
#
######################################################################

use EPrints;
use strict;


use strict;
use Getopt::Long;
use Pod::Usage;

my $version = 0;
my $verbose = 0;
my $quiet = 0;
my $help = 0;
my $man = 0;

Getopt::Long::Configure("permute");

GetOptions( 
	'help|?' => \$help,
	'man' => \$man,
	'version' => \$version,
	'verbose+' => \$verbose,
	'silent' => \$quiet,
	'quiet' => \$quiet
) || pod2usage( 2 );
EPrints::Utils::cmd_version( "import_test_data" ) if $version;
pod2usage( 1 ) if $help;
pod2usage( -exitstatus => 0, -verbose => 2 ) if $man;
#pod2usage( 2 ) if( scalar @ARGV != 1 ); 

my $noise = 1;
$noise = 0 if( $quiet );
$noise = 1+$verbose if( $verbose );





# nb. This syntax is subject to change in future versions.
my( $archiveid, $datasetid, $userid ) = @ARGV;

my $session = new EPrints::Session( 1 , $archiveid, $noise );
exit( 1 ) unless( defined $session );

# cache subjects
$session->cache_subjects;

my $db = $session->get_database;

$userid = 1 unless defined $userid;
$datasetid = "archive" unless defined $datasetid;

my $datapath = $EPrints::SystemSettings::conf->{base_path}."/testdata/data";

my $ds = $session->get_archive()->get_dataset( $datasetid );

my $pluginid = "Import::XML";
my $plugin = $session->plugin( $pluginid );

my $infile = $datapath."/data.xml.gz";


my $fh;
open( $fh, "gzip -d -c $infile |" ) || die "Can't gunzip file.";
my $list = $plugin->input_fh( dataset=>$ds, fh=>$fh, filename=>$infile );
close $fh; 

$session->terminate;

exit;

