#!/usr/bin/perl -w -I/opt1/perl_lib ###################################################################### # # This file is part of EPrints 2. # # Copyright (c) 2000,2001,2002 University of Southampton, UK. SO17 1BJ. # # EPrints 2 is free software; you can redistribute 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. # # EPrints 2 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 EPrints 2; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # ###################################################################### use EPrints::Session; use EPrints::ImportXML; use EPrints::EPrint; use strict; if( scalar @ARGV < 3 ) { print STDERR "import_xml user \n"; print STDERR "or\n"; print STDERR "import_xml archive \n"; exit( 1 ); } #cjg Nice Command Options #cjg man page # Set STDOUT to auto flush (without needing a \n) $|=1; my $session = new EPrints::Session( 1 , $ARGV[0] ); exit( 1 ) unless( defined $session ); my $ds = $session->get_archive()->get_dataset( $ARGV[1] ); if( !defined $ds ) { die "doh: bad dataset"; } # Using a local so it appears in subroutines. Normally I would # try and avoid doing this. my $info = { docs => {}, ds => $ds }; if( $ARGV[1] eq "user" ){ EPrints::ImportXML::import_file( $session , $ARGV[2] , \&deal_user, $ds, $info ); $session->terminate(); print STDERR "It works only if the users are in increasing order\n"; print STDERR "erases passwords for all users! ...\n\n"; exit; } ## collect info $ds = $session->get_archive()->get_dataset( "document" ); if( !defined $ds ) { die "doh: bad dataset"; } EPrints::ImportXML::import_file( $session, $ARGV[3], \&deal_doc,$ds,$info); sub deal_doc{ my($session,$ds,$doc,$info) = @_; my $docid=$doc->get_value("docid"); my $main=$doc->get_value("main"); ## print "$docid: $main\n"; %{$info->{docs}}->{$docid} = $main; } print "done\n"; $ds = $session->get_archive()->get_dataset( "buffer" ); if( !defined $ds ) { die "doh: bad dataset"; } EPrints::ImportXML::import_file( $session, $ARGV[4], \&deal,$ds,$info); #for my $key (keys %{$info->{docs}}){ # print $key," --> ",%{$info->{docs}}->{$key},"\n"; #} $session->terminate(); print STDERR "CORRECT ME: presently only one document (01) is restored\n\n"; exit; sub deal { my( $session , $ds , $eprint, $info ) = @_; my $oldid = $eprint->get_value("eprintid"); my $ne = EPrints::EPrint::create( $session, $ds, $eprint->get_data() ); print "copying $oldid --> ",$ne->get_value("eprintid"),"\n"; #only one doc is copied there my $main = %{$info->{docs}}->{$oldid."-01"}; my $doc = EPrints::Document::create($session,$ne); my $newdir=$doc->local_path(); my $from=sprintf "%08d", $oldid; $from =~ s/(\d\d)(\d\d)(\d\d)(\d\d)/$1\/$2\/$3\/$4\//; $from = $ARGV[2]."/".$from."01"; `cp -a $from/* $newdir/`; $doc->set_value("security",""); ## print "main= $main"; $doc->set_main($main); ### my $xxx=$doc->get_main(); print " getmain=$xxx\n"; $doc->set_format( $session->get_archive()->call( "get_document_type", $main ) ); $doc->commit; $ne->commit; $ne->move_to_archive(); ## $eprint->datestamp(); ## if( $session->get_db()->exists( $info->{ds} , $eprint->get_value("userid" ) ) ) ## { ## print "EXISTS!\n"; ## $eprint->commit; ## } ## else ## { ## print "NOT EXISTS!\n"; ## #cjg needs a userid ## } ## foreach( $eprint->get_all_related() ) ## { ## push @{$info->{update_abstracts}}, $_->get_value( "eprintid" ); ## } ## push @{$info->{update_abstracts}}, $eprint->get_value( "eprintid" ); } sub deal_user { my( $session, $ds, $user, $info ) = @_; my $id=$user->get_value("userid"); print $id; my $next=$session->get_db()->counter_next("userid"); $user->set_value("userid",$next); my $newuser = EPrints::EPrint::create( $session, $ds, $user->get_data() ); if(! defined $newuser ){ print "Not defined ???\n"; $user->set_value("password",EPrints::Utils::crypt_password( "123456", $session ) ); $user->commit; } else { $newuser->set_value("password",EPrints::Utils::crypt_password( "123456", $session ) ); $newuser->commit; $id = $newuser->get_value("userid"); } print " -> $id\n"; }