From b2b7d376d4854394322310f28d2f5aa1560384e0 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. Sponsored-by: National Library of Finland Signed-off-by: Brendan Gallagher Signed-off-by: Martin Renvoize Signed-off-by: Marcel de Rooy Signed-off-by: Nick Clemens --- 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 642ecbaa6b..53dd0074f2 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 5.010; @@ -172,6 +174,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.39.5