JBAS-1437 B2A link clean up bogus fast headings; leave OK ones
authorBill Erickson <berickxx@gmail.com>
Mon, 7 Nov 2016 21:09:04 +0000 (16:09 -0500)
committerBill Erickson <berickxx@gmail.com>
Thu, 21 Mar 2019 19:46:23 +0000 (15:46 -0400)
Signed-off-by: Bill Erickson <berickxx@gmail.com>
KCLS/linking/authority_control_fields.pl

index 5390bb8..ec7a771 100755 (executable)
@@ -696,6 +696,26 @@ sub is_fast_heading {
     return 0;
 }
 
+sub update_record {
+    my ($record, $marc) = @_;
+
+    my $xml = $marc->as_xml_record();
+    $xml =~ s/\n//sgo;
+    $xml =~ s/^<\?xml.+\?\s*>//go;
+    $xml =~ s/>\s+</></go;
+    $xml =~ s/\p{Cc}//go;
+    $xml = OpenILS::Application::AppUtils->entityize($xml);
+
+    $record->marc($xml);
+    
+    my $editor = OpenILS::Utils::CStoreEditor->new(xact=>1);
+    if ($editor->update_biblio_record_entry($record)) {
+        $editor->commit();
+    } else {
+        $editor->rollback();
+    }
+}
+
 foreach my $rec_id (@records) {
     announce("processing bib record $rec_id");
 
@@ -720,10 +740,12 @@ foreach my $rec_id (@records) {
             foreach my $bib_field (@bib_fields) {
 
                 my $sf0 = $bib_field->subfield('0') || '';
+                my $is_fast_heading = is_fast_heading($bib_field);
 
-                if (is_fast_heading($bib_field)) {
-                    # Ignore all 'fast' headings.
-                    announce("Skipping FAST on rec=$rec_id and tag=$c_tag \$0 $sf0");
+                if ($is_fast_heading && $sf0 =~ /\)fst/) {
+                    # fast heading looks OK.  ignore it.
+                    announce("Ignoring FAST heading field on ".
+                        "rec=$rec_id and tag=$c_tag \$0 $sf0");
                     next;
                 }
 
@@ -733,6 +755,18 @@ foreach my $rec_id (@records) {
                     $changed = 1;
                 }
 
+                if ($is_fast_heading) {
+                    # Update record after potentially removing a bogus
+                    # fast heading above.
+                    update_record($record, $marc) if $changed;
+
+                    # We don't control fast headings, so there's nothing 
+                    # left to do.  Move on to the next field...
+                    announce("No linking performed on FAST heading ".
+                        "field on rec=$rec_id and tag=$c_tag");
+                    next;
+                }
+
                 my %match_subfields;
                 my $match_tag;
                 my @searches;
@@ -830,31 +864,15 @@ foreach my $rec_id (@records) {
             }
         }
 
-        if ($changed) {
-            
-            # print $marc->as_formatted();
-            my $xml = $marc->as_xml_record();
-            $xml =~ s/\n//sgo;
-            $xml =~ s/^<\?xml.+\?\s*>//go;
-            $xml =~ s/>\s+</></go;
-            $xml =~ s/\p{Cc}//go;
-            $xml = OpenILS::Application::AppUtils->entityize($xml);
-
-            $record->marc($xml);
-            
-            my $editor = OpenILS::Utils::CStoreEditor->new(xact=>1);
-            if ($editor->update_biblio_record_entry($record)) {
-                               $editor->commit();
-                       } else {
-                               $editor->rollback();
-                       }
-        }
+        update_record($record, $marc) if $changed;
+
     } otherwise {
         my $err = shift;
         print STDERR "\nRecord # $rec_id : $err\n";
         import MARC::File::XML; # reset SAX parser so that one bad record doesn't kill the entire process
     }
 }
+
 my $end_time = localtime();
 
 if($input_file) {