6 use OpenSRF::Application;
7 use OpenSRF::EX qw/:try/;
8 use OpenSRF::AppSession;
9 use OpenSRF::MultiSession;
10 use OpenSRF::Utils::SettingsClient;
11 use OpenILS::Application::AppUtils;
12 use OpenILS::Utils::Fieldmapper;
13 use Digest::MD5 qw/md5_hex/;
14 use OpenSRF::Utils::JSON;
16 use Unicode::Normalize;
18 use Time::HiRes qw/time/;
21 use MARC::File::XML ( BinaryEncoding => 'utf-8' );
24 MARC::Charset->ignore_errors(1);
26 my ($count, $user, $password, $config, $marctype, $keyfile, @files, $quiet) =
27 (1, 'admin', 'open-ils', '/openils/conf/opensrf_core.xml', 'USMARC');
30 'startid=i' => \$count,
32 'marctype=s' => \$marctype,
33 'password=s' => \$password,
34 'config=s' => \$config,
39 @files = @ARGV if (!@files);
45 OpenSRF::System->bootstrap_client( config_file => $config );
46 Fieldmapper->import(IDL => OpenSRF::Utils::SettingsClient->new->config_value("IDL"));
48 $user = OpenILS::Application::AppUtils->check_user_session( login($user,$password) )->id;
50 select STDERR; $| = 1;
51 select STDOUT; $| = 1;
53 my $batch = new MARC::Batch ( $marctype, @files );
55 $batch->warnings_off();
59 while ( try { $rec = $batch->next } otherwise { $rec = -1 } ) {
63 (my $xml = $rec->as_xml_record()) =~ s/\n//sog;
64 $xml =~ s/^<\?xml.+\?\s*>//go;
65 $xml =~ s/>\s+</></go;
67 $xml = OpenILS::Application::AppUtils->entityize($xml);
68 $xml =~ s/[\x00-\x1f]//go;
70 my $bib = new Fieldmapper::authority::record_entry;
76 $bib->create_date('now');
78 $bib->edit_date('now');
79 $bib->last_xact_id('IMPORT-'.$starttime);
81 print OpenSRF::Utils::JSON->perl2JSON($bib)."\n";
85 if (!$quiet && !($count % 20)) {
86 print STDERR "\r$count\t". $count / (time - $starttime);
91 my( $username, $password, $type ) = @_;
95 my $seed = OpenILS::Application::AppUtils->simplereq(
97 'open-ils.auth.authenticate.init',
101 die("No auth seed. Couldn't talk to the auth server") unless $seed;
103 my $response = OpenILS::Application::AppUtils->simplereq(
105 'open-ils.auth.authenticate.complete',
106 { username => $username,
107 password => md5_hex($seed . md5_hex($password)),
110 die("No auth response returned on login.") unless $response;
112 my $authtime = $response->{payload}->{authtime};
113 my $authtoken = $response->{payload}->{authtoken};
115 die("Login failed for user $username!") unless $authtoken;