]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/src/extras/import/import_clean_marc.pl
EETS ALIVE!!!!!!!
[Evergreen.git] / Open-ILS / src / extras / import / import_clean_marc.pl
1 #!/usr/bin/perl -w
2 use strict;
3 use lib '../../perlmods/';
4 use lib '../../../../OpenSRF/src/perlmods/';
5 use OpenSRF::EX qw/:try/;
6 use OpenSRF::System;
7 use OpenSRF::Utils::SettingsClient;
8 use OpenILS::Utils::FlatXML;
9 use Time::HiRes;
10 use Getopt::Long;
11 use Data::Dumper;
12
13 my ($config, $userid, $sourceid, $wormize) = ('/pines/conf/bootstrap.conf', 1, 2);
14
15 GetOptions (    
16         "file=s"        => \$config,
17         "wormize"       => \$wormize,
18         "sourceid"      => \$sourceid,
19         "userid=i"      => \$userid,
20 );
21
22 OpenSRF::System->bootstrap_client( config_file => $config );
23 my $st_server = OpenSRF::AppSession->create( 'storage' );
24 my $worm_server = OpenSRF::AppSession->create( 'worm' ) if ($wormize);
25
26 try {
27
28         throw OpenSRF::EX::PANIC ("I can't connect to the storage server!")
29                 if (!$st_server->connect);
30
31         throw OpenSRF::EX::PANIC ("I can't connect to the worm server!")
32                 if ($wormize && !$worm_server->connect);
33
34 } catch Error with {
35         die shift;
36 };
37
38
39 while ( my $xml = <> ) {
40         chomp $xml;
41
42         my $ns = OpenILS::Utils::FlatXML->new( xml => $xml );
43
44         next unless ($ns->xml);
45
46         my $doc = $ns->xml_to_doc;
47         my $tcn = $doc->documentElement->findvalue( '/*/*[@tag="035"]' );
48
49         warn "Adding record for TCN $tcn\n";
50
51         $ns->xml_to_nodeset;
52         #next;
53
54         my $req = $st_server->request(
55                 'open-ils.storage.biblio.record_entry.create',
56                 {       creator         => $userid,
57                         editor          => $userid,
58                         source          => $sourceid,
59                         tcn_value       => $tcn,
60                 },
61         );
62
63         $req->wait_complete;
64
65         my $resp = $req->recv;
66         unless( $resp && $resp->can('content') ) {
67                 throw OpenSRF::EX::ERROR ("Failed to create record for TCN [$tcn]!! -- $resp");
68         }
69
70         my $new_id = $resp->content;
71
72         $req->finish;
73
74         if ($new_id) {
75                 my $nodeset = $ns->nodeset;
76                 
77                 $_->{owner_doc} = $new_id for (@$nodeset);
78                 
79                 $req = $st_server->request(
80                         'open-ils.storage.biblio.record_node.batch.create',
81                         @$nodeset,
82                 );
83
84                 $req->wait_complete;
85
86                 $resp = $req->recv;
87                 unless( $resp && $resp->can('content') ) {
88                         throw OpenSRF::EX::ERROR
89                                 ("Failed to create record_nodes for TCN [$tcn]!! -- $resp");
90                 }
91
92
93                 if ($wormize) {
94                         my $worm_req = $worm_server->request(
95                                 'open-ils.worm.record_data.digest',
96                                 $new_id,
97                         );
98                 }
99
100                 $req->finish;
101         } else {
102                 throw OpenSRF::EX::ERROR ("Failed to create record for TCN [$tcn]!! -- $resp");
103         }
104 }
105
106
107
108
109