5 use lib '/openils/lib/perl5/';
8 use OpenSRF::Application;
9 use OpenSRF::EX qw/:try/;
10 use OpenSRF::AppSession;
11 use OpenSRF::MultiSession;
12 use OpenSRF::Utils::SettingsClient;
13 use OpenILS::Application::AppUtils;
14 use OpenILS::Utils::Fieldmapper;
15 use Digest::MD5 qw/md5_hex/;
16 use OpenSRF::Utils::JSON;
18 use Unicode::Normalize;
20 use Time::HiRes qw/time/;
23 use MARC::File::XML ( BinaryEncoding => 'utf-8' );
26 MARC::Charset->ignore_errors(1);
28 my ($utf8, $id_field, $count, $user, $password, $config, $marctype, $keyfile, @files, @trash_fields, $quiet) =
29 (0, '998', 1, 'admin', 'open-ils', '/openils/conf/opensrf_core.xml', 'USMARC');
32 'startid=i' => \$count,
34 'marctype=s' => \$marctype,
35 'password=s' => \$password,
36 'config=s' => \$config,
41 @files = @ARGV if (!@files);
47 OpenSRF::System->bootstrap_client( config_file => $config );
48 Fieldmapper->import(IDL => OpenSRF::Utils::SettingsClient->new->config_value("IDL"));
50 $user = OpenILS::Application::AppUtils->check_user_session( login($user,$password) )->id;
52 select STDERR; $| = 1;
53 select STDOUT; $| = 1;
55 my $batch = new MARC::Batch ( $marctype, @files );
57 $batch->warnings_off();
61 while ( try { $rec = $batch->next } otherwise { $rec = -1 } ) {
64 my $_001 = $rec->field('001');
66 $arn = $_001->data if ($_001);
68 (my $xml = $rec->as_xml_record()) =~ s/\n//sog;
69 $xml =~ s/^<\?xml.+\?\s*>//go;
70 $xml =~ s/>\s+</></go;
72 $xml = entityize($xml);
73 $xml =~ s/[\x00-\x1f]//go;
75 my $bib = new Fieldmapper::authority::record_entry;
81 $bib->create_date('now');
83 $bib->edit_date('now');
84 $bib->arn_source('LEGACY');
85 $bib->arn_value($arn);
86 $bib->last_xact_id('IMPORT-'.$starttime);
88 print OpenSRF::Utils::JSON->perl2JSON($bib)."\n";
92 if (!$quiet && !($count % 20)) {
93 print STDERR "\r$count\t". $count / (time - $starttime);
98 my( $username, $password, $type ) = @_;
102 my $seed = OpenILS::Application::AppUtils->simplereq(
104 'open-ils.auth.authenticate.init',
108 die("No auth seed. Couldn't talk to the auth server") unless $seed;
110 my $response = OpenILS::Application::AppUtils->simplereq(
112 'open-ils.auth.authenticate.complete',
113 { username => $username,
114 password => md5_hex($seed . md5_hex($password)),
117 die("No auth response returned on login.") unless $response;
119 my $authtime = $response->{payload}->{authtime};
120 my $authtoken = $response->{payload}->{authtoken};
122 die("Login failed for user $username!") unless $authtoken;
131 if ($form and $form eq 'D') {
132 $stuff = NFD($stuff);
134 $stuff = NFC($stuff);
137 $stuff =~ s/([\x{0080}-\x{fffd}])/sprintf('&#x%X;',ord($1))/sgoe;