Improve error handling in marc2sre.pl when bib ID is not found
authordbs <dbs@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Wed, 6 Apr 2011 21:03:32 +0000 (21:03 +0000)
committerdbs <dbs@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Wed, 6 Apr 2011 21:03:32 +0000 (21:03 +0000)
If we can't find a bibliographic record ID to use in our load, then
skip that MFHD record and move on to the next one. Using the counter
gives sites a chance to identify which record caused the problem.

Aside: bitmap index scans for leading '%' LIKE searches make the
--bibfield / --bibsubfield extremely slow in large datasets. If
at all possible, avoid this path!

git-svn-id: svn://svn.open-ils.org/ILS/trunk@20006 dcc99617-32d9-48b4-a31d-7c20da2025e4

Open-ILS/src/extras/import/marc2sre.pl

index 21df735..2ac5516 100755 (executable)
@@ -87,18 +87,28 @@ while ( try { $rec = $batch->next } otherwise { $rec = -1 } ) {
     } else {
         $record_field = $rec->field($idfield);
     }
+
+    # Start by just using the counter as the record ID
     my $record = $count;
 
+    # If we have identified a location for the bib record ID, grab that value
     if ($record_field) {
         $record = $record_field->data;
     }
 
+    # If we didn't get a bib record ID, skip and move on to the next MFHD record
+    if (!$record) {
+        print STDERR "Could not find a bibliographic record ID link for record $count\n";
+        next;
+    }
+
     # If we have been given bibfield / bibsubfield values, use those to find
     # a matching bib record for $record and use _that_ as our record instead
     if ($bibfield) {
         my ($result, $evt) = map_id_to_bib($record);
-        if ($evt || !$result->record) {
-            print("Could not find matching bibliographic record for $record\n");
+        if ($evt || !$result || !$result->record) {
+            print STDERR "Could not find matching bibliographic record for record $count\n";
+            next;
         }
         $record = $result->record;
     } else {