From bceeea6fa913385b7bbda4419ee36eee07740cc9 Mon Sep 17 00:00:00 2001 From: Nick Clemens Date: Tue, 28 Apr 2020 15:34:20 +0000 Subject: [PATCH] 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 Signed-off-by: Martin Renvoize Signed-off-by: Jonathan Druart (cherry picked from commit 980419ed15cd4e5ae8be552218f939f5faea18c4) Signed-off-by: Lucas Gass (cherry picked from commit e5baeac0fdbc5fc83256effeff304e736c7dc154) Signed-off-by: Victor Grousset/tuxayo --- C4/Biblio.pm | 4 ++-- C4/Linker/Default.pm | 4 +++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/C4/Biblio.pm b/C4/Biblio.pm index 96137dd3dd..cdffe66b34 100644 --- a/C4/Biblio.pm +++ b/C4/Biblio.pm @@ -578,7 +578,7 @@ sub LinkBibHeadingsToAuthorities { next; } - my ( $authid, $fuzzy ) = $linker->get_link($heading); + my ( $authid, $fuzzy, $match_count ) = $linker->get_link($heading); if ($authid) { $results{ $fuzzy ? 'fuzzy' : 'linked' } ->{ $heading->display_form() }++; @@ -598,7 +598,7 @@ sub LinkBibHeadingsToAuthorities { if ( _check_valid_auth_link( $current_link, $field ) ) { $results{'linked'}->{ $heading->display_form() }++; } - else { + elsif ( !$match_count ) { my $authority_type = Koha::Authority::Types->find( $heading->auth_type() ); my $marcrecordauth = MARC::Record->new(); if ( C4::Context->preference('marcflavour') eq 'MARC21' ) { diff --git a/C4/Linker/Default.pm b/C4/Linker/Default.pm index bfe1d72308..934e87536a 100644 --- a/C4/Linker/Default.pm +++ b/C4/Linker/Default.pm @@ -33,6 +33,7 @@ sub get_link { my $auth_type = $heading->auth_type(); my $authid; my $fuzzy = 0; + my $match_count; if ( $self->{'cache'}->{$search_form.$auth_type}->{'cached'} ) { $authid = $self->{'cache'}->{$search_form.$auth_type}->{'authid'}; @@ -42,6 +43,7 @@ sub get_link { # look for matching authorities my $authorities = $heading->authorities(1); # $skipmetadata = true + $match_count = scalar @$authorities; if ( $behavior eq 'default' && $#{$authorities} == 0 ) { $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}->{'fuzzy'} = $fuzzy; } - return $self->SUPER::_handle_auth_limit($authid), $fuzzy; + return $self->SUPER::_handle_auth_limit($authid), $fuzzy, $match_count; } sub update_cache { -- 2.39.5