From 0949d3ebcdc2e0e9e7538a67a7e1bd2c89813bc7 Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Mon, 4 Jan 2016 14:19:20 -0800 Subject: [PATCH] JBAS-980 auth-to-auth clear links once Only delete auth-to-auth links for a given subfield once per record. Otherwise, we could only create one link per tag. Signed-off-by: Bill Erickson --- KCLS/linking/authority_authority_linker.pl | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/KCLS/linking/authority_authority_linker.pl b/KCLS/linking/authority_authority_linker.pl index 0aecb2f791..a7f3ffcded 100755 --- a/KCLS/linking/authority_authority_linker.pl +++ b/KCLS/linking/authority_authority_linker.pl @@ -106,7 +106,8 @@ my $query = q{ -- Ignore authority.authority_linking rows since we want to -- rebuild all links, which may mean deleting bogus links. -- EXCEPT SELECT target, source, field FROM authority.authority_linking - ) x GROUP BY 1 + -- order by source for consistent testing + ) x GROUP BY 1 ORDER BY source }; my @bind_params; @@ -162,6 +163,7 @@ while (my ($src, $links) = $sth->fetchrow_array) { announce("Source record thesaurus value=$auth_src_thesaurus"); my $changed = 0; + my %tags_seen; for my $link (split ';', $links) { my ($target, $field_id) = split ',', $link; @@ -194,14 +196,19 @@ while (my ($src, $links) = $sth->fetchrow_array) { next; } - # start by removing all existing links for the current tag - for my $field ($src_marc->field($acsaf->tag)) { - if (my $val = $field->subfield('0')) { - announce("Removing existing subfield 0 : $val"); - $field->delete_subfield(code => '0'); - $changed = 1; - $links_removed++; + if (!$tags_seen{$acsaf->tag}) { + # the first time we process each tag for a given record, + # remove all existing auth-to-auth link subfields + # so they can be completely rebuilt. + for my $field ($src_marc->field($acsaf->tag)) { + if (my $val = $field->subfield('0')) { + announce("Removing existing subfield 0 : $val"); + $field->delete_subfield(code => '0'); + $changed = 1; + $links_removed++; + } } + $tags_seen{$acsaf->tag} = 1; } # rebuild the links for the current tag -- 2.11.0