From d9e9dfcf0d968558d6d8257f196029541b8c39ca Mon Sep 17 00:00:00 2001 From: Ere Maijala Date: Tue, 13 Nov 2018 16:43:50 +0000 Subject: [PATCH] Bug 21826: Use subfield map in LinkBibHeadingsToAuthorities Use only allowable subfields when creating authorities from bibliographic records. Signed-off-by: Brendan Gallagher Signed-off-by: Martin Renvoize --- C4/Biblio.pm | 7 +++++-- C4/Heading.pm | 18 ++++++++++++++++++ C4/Heading/MARC21.pm | 15 +++++++++++++++ 3 files changed, 38 insertions(+), 2 deletions(-) diff --git a/C4/Biblio.pm b/C4/Biblio.pm index 808ed8d067..0249983331 100644 --- a/C4/Biblio.pm +++ b/C4/Biblio.pm @@ -539,7 +539,10 @@ sub LinkBibHeadingsToAuthorities { '', '', "a" => "" . $field->subfield('a') ); map { $authfield->add_subfields( $_->[0] => $_->[1] ) - if ( $_->[0] =~ /[A-z]/ && $_->[0] ne "a" ) + if ( $_->[0] =~ /[A-z]/ && $_->[0] ne "a" + && C4::Heading::valid_bib_heading_subfield( + $authority_type->auth_tag_to_report, $_->[0] ) + ); } $field->subfields(); $marcrecordauth->insert_fields_ordered($authfield); @@ -2989,7 +2992,7 @@ sub _koha_modify_biblio { $sth->execute( $frameworkcode, $biblio->{'author'}, $biblio->{'title'}, $biblio->{'unititle'}, $biblio->{'notes'}, - $biblio->{'serial'}, $biblio->{'seriestitle'}, $biblio->{'copyrightdate'}, $biblio->{'abstract'}, $biblio->{'biblionumber'} + $biblio->{'serial'}, $biblio->{'seriestitle'}, $biblio->{'copyrightdate'} ? int($biblio->{'copyrightdate'}) : undef, $biblio->{'abstract'}, $biblio->{'biblionumber'} ) if $biblio->{'biblionumber'}; if ( $dbh->errstr || !$biblio->{'biblionumber'} ) { diff --git a/C4/Heading.pm b/C4/Heading.pm index e323b5bcd2..6e33d1cd1b 100644 --- a/C4/Heading.pm +++ b/C4/Heading.pm @@ -17,6 +17,8 @@ package C4::Heading; # You should have received a copy of the GNU General Public License # along with Koha; if not, see . +use Modern::Perl; + use strict; use warnings; use MARC::Record; @@ -170,6 +172,22 @@ sub preferred_authorities { return $results; } +=head2 valid_bib_heading_subfield + + if (C4::Heading::valid_bib_heading_subfield('100', 'e', '')) ... + +=cut + +sub valid_bib_heading_subfield { + my $tag = shift; + my $subfield = shift; + my $marcflavour = @_ ? shift : C4::Context->preference('marcflavour'); + + my $marc_handler = _marc_format_handler($marcflavour); + + return $marc_handler->valid_bib_heading_subfield( $tag, $subfield ); +} + =head1 INTERNAL METHODS =head2 _search diff --git a/C4/Heading/MARC21.pm b/C4/Heading/MARC21.pm index 9a50cf6c28..fc4d576a45 100644 --- a/C4/Heading/MARC21.pm +++ b/C4/Heading/MARC21.pm @@ -161,6 +161,21 @@ sub valid_bib_heading_tag { } +=head2 valid_bib_heading_subfield + +=cut + +sub valid_bib_heading_subfield { + my $self = shift; + my $tag = shift; + my $subfield = shift; + + if ( exists $bib_heading_fields->{$tag} ) { + return 1 if ($bib_heading_fields->{$tag}->{subfields} =~ /$subfield/); + } + return 0; +} + =head2 parse_heading =cut -- 2.19.1