3 use lib '../../perlmods/';
4 use lib '../../../../OpenSRF/src/perlmods/';
5 use OpenSRF::EX qw/:try/;
7 use OpenSRF::Utils::SettingsClient;
8 use OpenILS::Utils::FlatXML;
9 use OpenILS::Utils::Fieldmapper;
14 my ($config, $userid, $sourceid, $wormize) = ('/pines/conf/bootstrap.conf', 1, 2);
18 "wormize" => \$wormize,
19 "sourceid" => \$sourceid,
20 "userid=i" => \$userid,
23 OpenSRF::System->bootstrap_client( config_file => $config );
24 my $st_server = OpenSRF::AppSession->create( 'open-ils.storage' );
25 my $worm_server = OpenSRF::AppSession->create( 'open-ils.worm' ) if ($wormize);
29 throw OpenSRF::EX::PANIC ("I can't connect to the storage server!")
30 if (!$st_server->connect);
32 throw OpenSRF::EX::PANIC ("I can't connect to the worm server!")
33 if ($wormize && !$worm_server->connect);
40 while ( my $xml = <> ) {
43 my $ns = OpenILS::Utils::FlatXML->new( xml => $xml );
45 next unless ($ns->xml);
47 my $doc = $ns->xml_to_doc;
48 my $tcn = $doc->documentElement->findvalue( '/*/*[@tag="035"]' );
50 $tcn =~ s/^.*?(\w+)$/$1/go;
52 warn "Adding record for TCN $tcn\n";
57 warn " ==> Starting transaction...\n";
59 my $xact = $st_server->request( 'open-ils.storage.transaction.begin' );
63 die $r unless (UNIVERSAL::can($r, 'content'));
64 die "Couldn't start transaction!" unless ($r);
66 warn " ==> Transaction ".$xact->session->session_id." started\n";
69 my $fe = new Fieldmapper::biblio::record_entry;
70 $fe->editor( $userid );
71 $fe->creator( $userid );
72 $fe->source( $sourceid );
73 $fe->tcn_value( $tcn );
75 my $req = $st_server->request( 'open-ils.storage.biblio.record_entry.create' => $fe );
79 my $resp = $req->recv;
80 unless( $resp && $resp->can('content') ) {
81 throw OpenSRF::EX::ERROR ("Failed to create record for TCN [$tcn]. Got an exception!! -- ".$resp->toString);
84 my $new_id = $resp->content;
91 #my $nodeset = $ns->nodeset;
92 #$_->owner_doc( $new_id ) for (@$nodeset);
94 my $rec = new Fieldmapper::biblio::record_marc;
96 $rec->marc( $ns->xml );
98 $req = $st_server->request(
99 'open-ils.storage.biblio.record_marc.create',
106 unless( $resp && $resp->can('content') ) {
107 throw OpenSRF::EX::ERROR ("Failed to create record_nodes for TCN [$tcn]. Got an exception!! -- $resp");
112 my $worm_req = $worm_server->request(
113 'open-ils.worm.record_data.digest',
120 throw OpenSRF::EX::ERROR ("Failed to create record for TCN [$tcn]. Got no new ID !! -- ".$resp->toString);
123 warn " !!> Rolling back transaction\n".shift();
124 $xact = $st_server->request( 'open-ils.storage.transaction.rollback' );
125 $xact->wait_complete;
127 die $r unless (UNIVERSAL::can($r, 'content'));
128 die "Couldn't rollback transaction!" unless ($r->content);
134 warn " ==>Commiting addition of $tcn\n";
135 $xact = $st_server->request( 'open-ils.storage.transaction.commit' );
136 $xact->wait_complete;
139 die $r unless (UNIVERSAL::can($r, 'content'));
140 die "Couldn't commit transaction!" unless ($r->content);