#!/usr/bin/perl -w

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

#-d:DProf

######################################################################
#
#
######################################################################

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;


=head1 COPYRIGHT

=for COPYRIGHT BEGIN

Copyright 2022 University of Southampton.
EPrints 3.4 is supplied by EPrints Services.

http://www.eprints.org/eprints-3.4/

=for COPYRIGHT END

=for LICENSE BEGIN

This file is part of EPrints 3.4 L<http://www.eprints.org/>.

EPrints 3.4 and this file are released under the terms of the
GNU Lesser General Public License version 3 as published by
the Free Software Foundation unless otherwise stated.

EPrints 3.4 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 Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public
License along with EPrints 3.4.
If not, see L<http://www.gnu.org/licenses/>.

=for LICENSE END

