From 91116d70d0e2a79849cbc2e2f96d5d7f834c5ef5 Mon Sep 17 00:00:00 2001 From: Jared Camins-Esakov Date: Thu, 29 Nov 2012 15:11:00 -0500 Subject: [PATCH] Bug 9149: Add missing GetAuthorizedHeading On 3.8.x, it was possible for multiple automatically generated authorities to be linked to a single heading. This patch deletes previous links from headings prior to linking them to automatically-generated headings. This patch also corrects a potential problem wherein multiple authorities might be generated if a record is edited repeatedly in quick succession. The latter problem exists on Master and 3.6.x as well, and the code that corrects the multiple linkages is equally applicable if seemingly unnecessary. This patch adds a missing routine to C4::AuthoritiesMarc that should have been in the 3.8.x version of the patch for bug 8823. To test: 1) Turn on BiblioAddsAuthorities and AutoCreateAuthorities. 2) Create a new record or edit an existing one, and add an authority-controlled heading (for example, MARC21 1xx or 6xx or UNIMARC 6xx or 7xx) which does not currently exist in your authority file. 3) If you don't get a software error, it worked. Signed-off-by: Katrin Fischer For 2) you can also download a record over Z39.50. Passes all tests. Signed-off-by: Chris Cormack --- C4/AuthoritiesMarc.pm | 63 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) diff --git a/C4/AuthoritiesMarc.pm b/C4/AuthoritiesMarc.pm index 061546ea5b..47e39a45c5 100644 --- a/C4/AuthoritiesMarc.pm +++ b/C4/AuthoritiesMarc.pm @@ -1144,6 +1144,69 @@ sub BuildSummary { return \%summary; } +=head2 GetAuthorizedHeading + + $heading = &GetAuthorizedHeading({ record => $record, authid => $authid }) + +Takes a MARC::Record object describing an authority record or an authid, and +returns a string representation of the first authorized heading. This routine +should be considered a temporary shim to ease the future migration of authority +data from C4::AuthoritiesMarc to the object-oriented Koha::*::Authority. + +=cut + +sub GetAuthorizedHeading { + my $args = shift; + my $record; + unless ($record = $args->{record}) { + return unless $args->{authid}; + $record = GetAuthority($args->{authid}); + } + if (C4::Context->preference('marcflavour') eq 'UNIMARC') { +# construct UNIMARC summary, that is quite different from MARC21 one +# accepted form + foreach my $field ($record->field('2..')) { + return $field->as_string('abcdefghijlmnopqrstuvwxyz'); + } + } else { + foreach my $field ($record->field('1..')) { + my $tag = $field->tag(); + next if "152" eq $tag; +# FIXME - 152 is not a good tag to use +# in MARC21 -- purely local tags really ought to be +# 9XX + if ($tag eq '100') { + return $field->as_string('abcdefghjklmnopqrstvxyz68'); + } elsif ($tag eq '110') { + return $field->as_string('abcdefghklmnoprstvxyz68'); + } elsif ($tag eq '111') { + return $field->as_string('acdefghklnpqstvxyz68'); + } elsif ($tag eq '130') { + return $field->as_string('adfghklmnoprstvxyz68'); + } elsif ($tag eq '148') { + return $field->as_string('abvxyz68'); + } elsif ($tag eq '150') { + return $field->as_string('abvxyz68'); + } elsif ($tag eq '151') { + return $field->as_string('avxyz68'); + } elsif ($tag eq '155') { + return $field->as_string('abvxyz68'); + } elsif ($tag eq '180') { + return $field->as_string('vxyz68'); + } elsif ($tag eq '181') { + return $field->as_string('vxyz68'); + } elsif ($tag eq '182') { + return $field->as_string('vxyz68'); + } elsif ($tag eq '185') { + return $field->as_string('vxyz68'); + } else { + return $field->as_string(); + } + } + } + return; +} + =head2 BuildUnimarcHierarchies $text= &BuildUnimarcHierarchies( $authid, $force) -- 2.39.5