Koha/C4/Linker/Default.pm
Janusz Kaczmarek 4458ac5764 Bug 11650: multiplicated authorities after link_bibs_to_authorities.pl
Under certain circumstances misc/link_bibs_to_authorities.pl creates
multiple authority with identical heading.

Test plan:
1. Have some (2-3) biblio records with some repeated headings
   Have BiblioAddsAuthorities = allow, AutoCreateAuthorities = generate
   Have no authority records
2. Run misc/link_bibs_to_authorities.pl script
3. You will get multiple authority records -- one for each occurence of a
   heading in biblio record.

4. Apply the patch.
5. Repeat 1-3 (remember to have "fresh" biblios, without $9, and no
   authorities).
6. The problem should be fixed.

Signed-off-by: Chris Cormack <chris@bigballofwax.co.nz>

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Signed-off-by: Tomas Cohen Arazi <tomascohen@gmail.com>
Works as described.
2014-07-07 12:40:25 -03:00

108 lines
3.3 KiB
Perl

package C4::Linker::Default;
# Copyright 2011 C & P Bibliography Services
#
# This file is part of Koha.
#
# Koha is free software; you can redistribute it and/or modify it under the
# terms of the GNU General Public License as published by the Free Software
# Foundation; either version 2 of the License, or (at your option) any later
# version.
#
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
# A PARTICULAR PURPOSE. See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with Koha; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
use strict;
use warnings;
use Carp;
use MARC::Field;
use C4::Heading;
use base qw(C4::Linker);
sub get_link {
my $self = shift;
my $heading = shift;
my $behavior = shift || 'default';
my $search_form = $heading->search_form();
my $authid;
my $fuzzy = 0;
if ( $self->{'cache'}->{$search_form}->{'cached'} ) {
$authid = $self->{'cache'}->{$search_form}->{'authid'};
$fuzzy = $self->{'cache'}->{$search_form}->{'fuzzy'};
}
else {
# look for matching authorities
my $authorities = $heading->authorities(1); # $skipmetadata = true
if ( $behavior eq 'default' && $#{$authorities} == 0 ) {
$authid = $authorities->[0]->{'authid'};
}
elsif ( $behavior eq 'first' && $#{$authorities} >= 0 ) {
$authid = $authorities->[0]->{'authid'};
$fuzzy = $#{$authorities} > 0;
}
elsif ( $behavior eq 'last' && $#{$authorities} >= 0 ) {
$authid = $authorities->[ $#{$authorities} ]->{'authid'};
$fuzzy = $#{$authorities} > 0;
}
if ( !defined $authid && $self->{'broader_headings'} ) {
my $field = $heading->field();
my @subfields = grep { $_->[0] ne '9' } $field->subfields();
if ( scalar @subfields > 1 ) {
pop @subfields;
$field =
MARC::Field->new(
$field->tag,
$field->indicator(1),
$field->indicator(2),
map { $_->[0] => $_->[1] } @subfields
);
( $authid, $fuzzy ) =
$self->get_link( C4::Heading->new_from_bib_field($field),
$behavior );
}
}
$self->{'cache'}->{$search_form}->{'cached'} = 1;
$self->{'cache'}->{$search_form}->{'authid'} = $authid;
$self->{'cache'}->{$search_form}->{'fuzzy'} = $fuzzy;
}
return $self->SUPER::_handle_auth_limit($authid), $fuzzy;
}
sub update_cache {
my $self = shift;
my $heading = shift;
my $authid = shift;
my $search_form = $heading->search_form();
my $fuzzy = 0;
$self->{'cache'}->{$search_form}->{'cached'} = 1;
$self->{'cache'}->{$search_form}->{'authid'} = $authid;
$self->{'cache'}->{$search_form}->{'fuzzy'} = $fuzzy;
}
sub flip_heading {
my $self = shift;
my $heading = shift;
# TODO: implement
}
1;
__END__
=head1 NAME
C4::Linker::Default - match only if there is a single matching auth
=cut