-- 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;
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;
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