From c23b73f97f69e390b68c692003a0dab4fcf743b6 Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Mon, 7 Nov 2016 16:09:04 -0500 Subject: [PATCH] JBAS-1437 B2A link clean up bogus fast headings; leave OK ones Signed-off-by: Bill Erickson --- KCLS/linking/authority_control_fields.pl | 62 ++++++++++++++++++++------------ 1 file changed, 40 insertions(+), 22 deletions(-) diff --git a/KCLS/linking/authority_control_fields.pl b/KCLS/linking/authority_control_fields.pl index 5390bb855c..ec7a7710ff 100755 --- a/KCLS/linking/authority_control_fields.pl +++ b/KCLS/linking/authority_control_fields.pl @@ -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+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+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) { -- 2.11.0