#!/usr/local/bin/perl5.8.0 -w -I/opt/ep2stable/perl_lib 

use EPrints::EPrint;
use EPrints::Document;
use EPrints::Session;

use strict;

# the userid to make new eprints belong to
my $USERID = 4;
# the id of the archive to import to
my $ARCHIVEID = 'ep2stable';
# This is a list of files to import (full path please)
my @FILES = ( '/tmp/file1,pdf', '/tmp/file2,pdf' );


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

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


foreach my $file ( @FILES ) 
{
	add_eprint_from_file( $session, $ds, $USERID, $file );
}




$session->terminate();
exit;

sub add_eprint_from_file
{
	my( $session, $ds, $userid, $file ) = @_;

	if( !-f $file ) { die "file does not exist: $file"; }

	my $data = {
		userid => $userid,
		title => $file 
	};
	my $eprint = EPrints::EPrint::create( $session, $ds, $data );
	my $doc = EPrints::Document::create( $session, $eprint );
	$file =~ m!([^/]*)$!;
	$doc->add_file( $file, $1 );

	print "Added $file\n";
}
