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 = <> ) {
45 my $ns = OpenILS::Utils::FlatXML->new( xml => $xml );
47 next unless ($ns->xml);
49 my $doc = $ns->xml_to_doc;
50 my $tcn = $doc->documentElement->findvalue( '/*/*[@tag="035"]' );
52 $tcn =~ s/^.*?(\w+)$/$1/go;
54 warn "Adding record for TCN $tcn\n";
59 warn " ==> Starting transaction...\n";
61 my $xact = $st_server->request( 'open-ils.storage.transaction.begin' );
65 die $r unless (UNIVERSAL::can($r, 'content'));
66 die "Couldn't start transaction!" unless ($r);
68 warn " ==> Transaction ".$xact->session->session_id." started\n";
71 my $fe = new Fieldmapper::biblio::record_entry;
72 $fe->editor( $userid );
73 $fe->creator( $userid );
74 $fe->source( $sourceid );
75 $fe->tcn_value( $tcn );
77 my $req = $st_server->request( 'open-ils.storage.biblio.record_entry.create' => $fe );
81 my $resp = $req->recv;
82 unless( $resp && $resp->can('content') ) {
83 throw OpenSRF::EX::ERROR ("Failed to create record for TCN [$tcn]. Got an exception!! -- ".$resp->toString);
86 $new_id = $resp->content;
87 warn " (new record_entry id is $new_id)\n";
94 #my $nodeset = $ns->nodeset;
95 #$_->owner_doc( $new_id ) for (@$nodeset);
97 my $rec = new Fieldmapper::biblio::record_marc;
101 $req = $st_server->request( 'open-ils.storage.biblio.record_marc.create', $rec );
106 unless( $resp && $resp->can('content') ) {
107 throw OpenSRF::EX::ERROR ("Failed to create record_nodes for TCN [$tcn]. Got an exception!! -- $resp");
113 throw OpenSRF::EX::ERROR ("Failed to create record for TCN [$tcn]. Got no new ID !! -- ".$resp->toString);
116 warn " !!> Rolling back transaction\n".shift();
117 $xact = $st_server->request( 'open-ils.storage.transaction.rollback' );
118 $xact->wait_complete;
120 die $r unless (UNIVERSAL::can($r, 'content'));
121 die "Couldn't rollback transaction!" unless ($r->content);
127 warn " ==>Commiting addition of $tcn\n";
128 $xact = $st_server->request( 'open-ils.storage.transaction.commit' );
129 $xact->wait_complete;
132 die $r unless (UNIVERSAL::can($r, 'content'));
133 die "Couldn't commit transaction!" unless ($r->content);
136 $worm_server->request( 'open-ils.worm.wormize', $new_id,);