Bug 21453: Copy data to the correct subfields when linking authorities with authorities

When using the authority finder plugin from within Koha's
Authorities module, you can pick an entry from the 'Special
relationship:' dropdown menu in order to set the relationship
between authorities.

The problem is that in UNIMARC setups, when you click on
'Choose' to select an authority, it does not populate
subfields $3 (Authority Record Number) and $5 (Tracing
Control), which are required for authority linking and
authority hierarchies to work properly.

In MARC21, all authority data is correctly copied over.

This is due to hardcoded subfield values which are
MARC21-specific in blinddetail-biblio-search{.pl,.tt}.

This patch fixes that by checking the value of the
'marcflavour' syspref, and then setting the correct
subfields to copy the authority data to.

Test plan (involves testing in both a MARC21 and a UNIMARC instance):

0) [PREREQUISITES in order for the authority finder plugin to come up
    when testing in a UNIMARC instance]
   a) You must have at least one authority type besides the 'Default'.
   b) View the MARC structure of the 'Default' auth type, then click
      on 'Actions->Subfields' for tag 500; click on 'Edit subfields'.
      Select the subfield 'a' tab, then pick an auth type from the
      'Thesaurus:' dropdown menu; click 'Save changes' at the top.

1) In the Staff client, go to Authorities, then click 'New Authority'
   and pick the 'Default' authority type.

2) When the authority editor comes up, go to tag 500 and expand it.

3) Click on the Tag editor icon next to subfield $a.

4) When the authority finder comes up, search for an authority, pick
   a relator code from the 'Special relationship:' dropdown, and then
   click on the 'Choose' button for one of the authorities you found.

5) In MARC21: all subfields are populated correctly.
   In UNIMARC: notice how subfields $3 and $5 are *not* populated.

6) Apply the patch.

7) Repeat steps 3) and 4) above.
   In MARC21: all subfields are populated correctly, as before.
   In UNIMARC: both the relator code and the authority id are copied
               over along with any other subfields that may exist.

8) To ensure that authority linking in the Cataloging module works
   as before, launch the bibliographic record editor, find a MARC
   tag that allows you to search for an authority, and link it.
   In MARC21: all authority data is copied over (authid in $9).
   In UNIMARC: all authority data is copied over (authid in $9).

   NOTE: after linking, you may have to expand the MARC tag you
         chose so that subfield $9 becomes visible.

Signed-off-by: David Nind <david@davidnind.com>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
(cherry picked from commit d88274881e)
Signed-off-by: Jacob O'Mara <Jacob.omara@openfifth.co.uk>
This commit is contained in:
Andreas Roussos 2025-04-02 09:01:56 +00:00 committed by Jacob O'Mara
parent d0f0ec542f
commit e172de3d7a
No known key found for this signature in database
3 changed files with 41 additions and 10 deletions

View File

@ -55,6 +55,8 @@ my $authid = $query->param('authid');
my $index = $query->param('index');
my $tagid = $query->param('tagid');
my $relationship = $query->param('relationship');
my $source = $query->param('source');
my $marcflavour = C4::Context->preference("marcflavour");
# open template
my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
@ -85,7 +87,10 @@ if ($authid) {
# Get all values for each distinct subfield and add to subfield loop
my %done_subfields;
for ( $field->subfields ) {
next if $_->[0] eq '9'; # $9 will be set with authid value
if ( $marcflavour eq 'UNIMARC' ) {
next if $_->[0] eq '3'; # $3 will be set with authid value (in UNIMARC authority records)
}
next if $_->[0] eq '9'; # $9 will be set with authid value
my $letter = $_->[0];
$letter ||= '@';
next if defined $done_subfields{$letter};
@ -94,7 +99,17 @@ if ($authid) {
$done_subfields{$letter} = 1;
}
push( @subfield_loop, { marc_subfield => 'w', marc_values => $relationship } ) if ($relationship);
# If a relationship code has been selected, add it to the appropriate
# subfield of @subfield_loop, depending on the MARC flavour being used.
if ($relationship) {
my $relationship_subfield;
if ( $marcflavour eq 'UNIMARC' ) {
$relationship_subfield = '5';
} elsif ( $marcflavour eq 'MARC21' ) {
$relationship_subfield = 'w';
}
push @subfield_loop, { marc_subfield => $relationship_subfield, marc_values => $relationship };
}
# Copy the ISNI number over (should one exist) to subfield $o when linking
# authorities with authorities in UNIMARC instances. This only applies to
@ -142,7 +157,8 @@ $template->param(
indicator2 => $indicator2,
SUBFIELD_LOOP => \@subfield_loop,
tag_number => $tag_number,
rancor => $index =~ /rancor$/,
rancor => ( $index =~ /rancor$/ ) ? 1 : 0,
source => $source,
);
output_html_with_http_headers $query, $cookie, $template->output;

View File

@ -1,6 +1,8 @@
[% USE To %]
[% USE Koha %]
[% PROCESS 'i18n.inc' %]
[% SET footerjs = 1 %]
[% SET marcflavour = Koha.Preference('marcflavour') %]
[% INCLUDE 'doc-head-open.inc' %]
<title
>[% FILTER collapse %]
@ -38,7 +40,10 @@
[%- FOREACH marc_value IN SUBFIELD_LOO.marc_values -%]
[%- To.json( marc_value ) | html -%]
[%- END -%]
[%- END -%]‡9[% authid | html %]";
[%- END -%]
[% IF ( marcflavour == 'UNIMARC' ) %]‡3[% authid | html %]";
[% ELSIF ( marcflavour == 'MARC21' ) %]‡9[% authid | html %]";
[% END %]
[% END %]
RancorReplaceField( new_line, "[% indicator1 | html %]", "[% indicator2 | html %]" );
[% ELSE %]
@ -167,7 +172,16 @@
[% IF ( clear ) %]
if (subfield){subfield.value="" ;}
[% ELSE %]
if(code.value=='9'){
[% IF ( marcflavour == 'UNIMARC' ) %]
[% IF ( source == 'auth' ) %]
var authid_subfield = "3";
[% ELSIF ( source == 'biblio' ) %]
var authid_subfield = "9";
[% END %]
[% ELSIF ( marcflavour == 'MARC21' ) %]
var authid_subfield = "9";
[% END %]
if(code.value==authid_subfield){
subfield.value = "[% To.json(authid) | $raw %]";
subfield.className = subfield.className.replace("no_matching_authority_field", "matching_authority_field");
break;

View File

@ -156,14 +156,15 @@
}
function doauth(authid, index, repet){
[% IF source == 'auth' %]
var source = "[% source | uri %]";
if ( source == 'auth' ) {
var elem = document.getElementById("special_relationship");
var relationship = elem.options[elem.selectedIndex].value;
jumpfull('blinddetail-biblio-search.pl?authid=' + authid + '&index=' + index + '&repet=' + repet + '&relationship=' + relationship);
[% ELSE %]
jumpfull('blinddetail-biblio-search.pl?authid=' + authid + '&index=' + index + '&repet=' + repet);
[% END %]
jumpfull('blinddetail-biblio-search.pl?authid=' + authid + '&index=' + index + '&repet=' + repet + '&source=' + source + '&relationship=' + relationship);
} else {
jumpfull('blinddetail-biblio-search.pl?authid=' + authid + '&index=' + index + '&repet=' + repet + '&source=' + source);
}
}
</script>
[% END %]