Browse Source

Bug 25189: Don't create authority if results found

Automatic authority creation assumes that if we don't match we need a new authority.

Using the Default linker, however, we don't match if there exists more than one match.
This leads to repeatedly generating authorities once there is a duplicate in the system

We shoudl instead only create a new authority if there are no results

To test:
1 - Set Linker Module to 'Default'
2 - Enable  AutoCreateAuthorities  and  BiblioAddsAuthorities and  CatalogModuleRelink and LinkerRelink
3 - Add two copies of a single authority via Z39
4 - Add a heading for that authority to a bib record
5 - Save the record and note a new authority is generated
6 - Repeat and see another is generated
7 - Apply patch
8 - Restart all the things
9 - Save the record again, no new authority created

Signed-off-by: Andrew Fuerste-Henry <andrew@bywatersolutions.com>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
20.11.x
Nick Clemens 4 years ago
committed by Jonathan Druart
parent
commit
980419ed15
  1. 4
      C4/Biblio.pm
  2. 4
      C4/Linker/Default.pm

4
C4/Biblio.pm

@ -506,7 +506,7 @@ sub LinkBibHeadingsToAuthorities {
next; next;
} }
my ( $authid, $fuzzy ) = $linker->get_link($heading); my ( $authid, $fuzzy, $match_count ) = $linker->get_link($heading);
if ($authid) { if ($authid) {
$results{ $fuzzy ? 'fuzzy' : 'linked' } $results{ $fuzzy ? 'fuzzy' : 'linked' }
->{ $heading->display_form() }++; ->{ $heading->display_form() }++;
@ -526,7 +526,7 @@ sub LinkBibHeadingsToAuthorities {
if ( _check_valid_auth_link( $current_link, $field ) ) { if ( _check_valid_auth_link( $current_link, $field ) ) {
$results{'linked'}->{ $heading->display_form() }++; $results{'linked'}->{ $heading->display_form() }++;
} }
else { elsif ( !$match_count ) {
my $authority_type = Koha::Authority::Types->find( $heading->auth_type() ); my $authority_type = Koha::Authority::Types->find( $heading->auth_type() );
my $marcrecordauth = MARC::Record->new(); my $marcrecordauth = MARC::Record->new();
if ( C4::Context->preference('marcflavour') eq 'MARC21' ) { if ( C4::Context->preference('marcflavour') eq 'MARC21' ) {

4
C4/Linker/Default.pm

@ -33,6 +33,7 @@ sub get_link {
my $auth_type = $heading->auth_type(); my $auth_type = $heading->auth_type();
my $authid; my $authid;
my $fuzzy = 0; my $fuzzy = 0;
my $match_count;
if ( $self->{'cache'}->{$search_form.$auth_type}->{'cached'} ) { if ( $self->{'cache'}->{$search_form.$auth_type}->{'cached'} ) {
$authid = $self->{'cache'}->{$search_form.$auth_type}->{'authid'}; $authid = $self->{'cache'}->{$search_form.$auth_type}->{'authid'};
@ -42,6 +43,7 @@ sub get_link {
# look for matching authorities # look for matching authorities
my $authorities = $heading->authorities(1); # $skipmetadata = true my $authorities = $heading->authorities(1); # $skipmetadata = true
$match_count = scalar @$authorities;
if ( $behavior eq 'default' && $#{$authorities} == 0 ) { if ( $behavior eq 'default' && $#{$authorities} == 0 ) {
$authid = $authorities->[0]->{'authid'}; $authid = $authorities->[0]->{'authid'};
@ -77,7 +79,7 @@ sub get_link {
$self->{'cache'}->{$search_form.$auth_type}->{'authid'} = $authid; $self->{'cache'}->{$search_form.$auth_type}->{'authid'} = $authid;
$self->{'cache'}->{$search_form.$auth_type}->{'fuzzy'} = $fuzzy; $self->{'cache'}->{$search_form.$auth_type}->{'fuzzy'} = $fuzzy;
} }
return $self->SUPER::_handle_auth_limit($authid), $fuzzy; return $self->SUPER::_handle_auth_limit($authid), $fuzzy, $match_count;
} }
sub update_cache { sub update_cache {

Loading…
Cancel
Save