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