From 3423a92f6d9a9f0eeb31682f121377a0216aa240 Mon Sep 17 00:00:00 2001 From: Jason Stephenson Date: Sat, 6 Aug 2016 17:10:12 -0400 Subject: [PATCH] Use eval in eg_staged_bib_overlay. Wrap the parsing of MARC from input files in eval blocks with an error handler to skip to the next record. I have encounterd bad records that have stopped the processing of the rest of the file. This occurred the very first time I used this script. Signed-off-by: Jason Stephenson Signed-off-by: Galen Charlton --- eg_staged_bib_overlay | 60 +++++++++++++++++++++++++++++------------------- 1 files changed, 36 insertions(+), 24 deletions(-) diff --git a/eg_staged_bib_overlay b/eg_staged_bib_overlay index 1755ada..a517a6a 100755 --- a/eg_staged_bib_overlay +++ b/eg_staged_bib_overlay @@ -281,14 +281,20 @@ sub handle_stage_bibs { $dbh->commit; $dbh->begin_work; } - my $marc = MARC::Record->new_from_usmarc($_); - my $bibid = $marc->subfield('901', 'c'); - if ($bibid !~ /^\d+$/) { - print STDERR "Record $i is suspect; skipping\n"; + eval { + my $marc = MARC::Record->new_from_usmarc($_); + my $bibid = $marc->subfield('901', 'c'); + if ($bibid !~ /^\d+$/) { + print STDERR "Record $i is suspect; skipping\n"; + next; + } + my $xml = OpenILS::Application::AppUtils->entityize($marc->as_xml_record()); + $ins->execute($xml, $bibid); + }; + if ($@) { + print STDERR "Record $i is bad; skipping\n"; next; } - my $xml = OpenILS::Application::AppUtils->entityize($marc->as_xml_record()); - $ins->execute($xml, $bibid); } $dbh->commit; report_progress("Records staged", $i) if 0 != $i % 100; @@ -445,25 +451,31 @@ sub handle_stage_auths { $dbh->commit; $dbh->begin_work; } - my $marc = MARC::Record->new_from_usmarc($_); - my $authid = $marc->subfield('901', 'c'); - if (defined($authid) && $authid !~ /^\d+$/) { - undef $authid; - } - my $lccn = $marc->subfield('010', 'a'); - if (defined $lccn) { - $lccn =~ s/^\s+//; - $lccn =~ s/\s+$//; - $lccn =~ s/\s+/ /g; - } - my $cancelled_lccn = $marc->subfield('010', 'z'); - if (defined $cancelled_lccn) { - $cancelled_lccn =~ s/^\s+//; - $cancelled_lccn =~ s/\s+$//; - $cancelled_lccn =~ s/\s+/ /g; + eval { + my $marc = MARC::Record->new_from_usmarc($_); + my $authid = $marc->subfield('901', 'c'); + if (defined($authid) && $authid !~ /^\d+$/) { + undef $authid; + } + my $lccn = $marc->subfield('010', 'a'); + if (defined $lccn) { + $lccn =~ s/^\s+//; + $lccn =~ s/\s+$//; + $lccn =~ s/\s+/ /g; + } + my $cancelled_lccn = $marc->subfield('010', 'z'); + if (defined $cancelled_lccn) { + $cancelled_lccn =~ s/^\s+//; + $cancelled_lccn =~ s/\s+$//; + $cancelled_lccn =~ s/\s+/ /g; + } + my $xml = OpenILS::Application::AppUtils->entityize($marc->as_xml_record()); + $ins->execute($xml, $authid, $lccn, $cancelled_lccn, $xml); + }; + if ($@) { + print STDERR "Record $i is bad; skipping\n"; + next; } - my $xml = OpenILS::Application::AppUtils->entityize($marc->as_xml_record()); - $ins->execute($xml, $authid, $lccn, $cancelled_lccn, $xml); } $dbh->commit; report_progress("Records staged", $i) if 0 != $i % 100; -- 1.7.2.5