]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/src/extras/import/direct_loader.pl
LP 851915: Remove references to /openils/lib/perl5
[Evergreen.git] / Open-ILS / src / extras / import / direct_loader.pl
1 #!/usr/bin/perl
2 use strict;
3 use warnings;
4
5 use OpenSRF::System;
6 use OpenSRF::EX qw/:try/;
7 use OpenSRF::AppSession;
8 use OpenSRF::Application;
9 use OpenSRF::MultiSession;
10 use OpenSRF::Utils::SettingsClient;
11 use OpenILS::Application::Storage;
12 use OpenILS::Application::AppUtils;
13 use OpenILS::Utils::Fieldmapper;
14 use Digest::MD5 qw/md5_hex/;
15 use OpenSRF::Utils::JSON;
16 use Data::Dumper;
17 use FileHandle;
18
19 use Time::HiRes qw/time/;
20 use Getopt::Long;
21 use MARC::Batch;
22 use MARC::File::XML (BinaryEncoding => 'UTF-8');
23 use MARC::Charset;
24
25 MARC::Charset->ignore_errors(1);
26
27 my @files;
28 my ($type, $config, $autoprimary) =
29         ('biblio.record_entry', '/openils/conf/opensrf_core.xml', 0);
30
31 GetOptions(
32         'type=s'        => \$type,
33         'config=s'      => \$config,
34         'autoprimary'   => \$config,
35 );
36
37
38 OpenSRF::System->bootstrap_client( config_file => $config );
39 Fieldmapper->import(IDL => OpenSRF::Utils::SettingsClient->new->config_value("IDL"));
40
41 OpenILS::Application::Storage->use;
42 OpenILS::Application::Storage->initialize;
43 OpenILS::Application::Storage->child_init || die;
44
45 if ($autoprimary) {
46         OpenILS::Application::Storage->autoprimary(1);
47 }
48
49 my $base = "open-ils.storage.direct.$type.batch.create";
50
51 OpenSRF::Application->method_lookup( "$base.start" )->run; 
52
53 my $count = 0;
54 my $starttime = time;
55 while ( my $rec = <> ) {
56         next unless ($rec);
57
58         my $row = OpenSRF::Utils::JSON->JSON2perl($rec);
59
60         OpenSRF::Application->method_lookup( "$base.push" )->run($row); 
61
62
63         if (!($count % 20)) {
64                 print STDERR "\r$count\t". $count / (time - $starttime);
65         }
66
67         $count++;
68
69         last if ($count > 10000);
70 }
71
72 #OpenSRF::Application->method_lookup( "$base.finish" )->run; 
73
74