From 14e4e3c771648b0495f01dd4b1e249847ed7cc7d Mon Sep 17 00:00:00 2001 From: Emmi Takkinen Date: Mon, 24 May 2021 13:19:06 +0300 Subject: [PATCH] Bug 28584: Remove hyphens from EAN when adding new record Add functionality to TransformMarcToKoha so that hyphens are removed from biblioitem tables "ean" column but EAN value in MARC record is not touched. To test: 1. Apply patch. 2. Create new record with EAN field(s) having hyphen(s) e.g. 74628-8972 3. Check records MARC details => EAN has hyphen 4. Check record from biblioitem table in database => EAN doesn't have hyphen(s) Prove t/db_dependent/Biblio/TransfornMarcToKoha.t Sponsored-by: Koha-Suomi Oy --- C4/Biblio.pm | 4 ++++ t/db_dependent/Biblio/TransformMarcToKoha.t | 8 +++++--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/C4/Biblio.pm b/C4/Biblio.pm index d341e8f6c0..f0e19c5112 100644 --- a/C4/Biblio.pm +++ b/C4/Biblio.pm @@ -2437,6 +2437,10 @@ sub TransformMarcToKohaOneField { $retval = _adjust_pubyear( $retval ); } + if( $kohafield =~ /ean/ ) { + $retval =~ s/-//g; + } + return $retval; } diff --git a/t/db_dependent/Biblio/TransformMarcToKoha.t b/t/db_dependent/Biblio/TransformMarcToKoha.t index 60d7a95833..3ff3a1905f 100755 --- a/t/db_dependent/Biblio/TransformMarcToKoha.t +++ b/t/db_dependent/Biblio/TransformMarcToKoha.t @@ -42,20 +42,22 @@ Koha::MarcSubfieldStructure->new({ frameworkcode => '', tagfield => '500', tagsu Koha::Caches->get_instance->clear_from_cache( "MarcSubfieldStructure-" ); subtest 'Test a few mappings' => sub { - plan tests => 7; + plan tests => 8; my $marc = MARC::Record->new; $marc->append_fields( MARC::Field->new( '300', '', '', a => 'a1', b => 'b1' ), MARC::Field->new( '300', '', '', a => 'a2', b => 'b2' ), MARC::Field->new( '500', '', '', a => 'note1', a => 'note2' ), + MARC::Field->new( '024', '', '', a => '9678-56789', a => '8657-6547-89' ), ); my $result = C4::Biblio::TransformMarcToKoha( $marc ); # Note: TransformMarcToKoha stripped the table prefix biblio. - is( keys %{$result}, 3, 'Found all three mappings' ); + is( keys %{$result}, 4, 'Found all four mappings' ); is( $result->{field1}, 'a1 | a2', 'Check field1 results' ); is( $result->{field2}, 'b1 | b2', 'Check field2 results' ); is( $result->{field3}, 'note1 | note2', 'Check field3 results' ); + is( $result->{ean}, '967856789 | 8657654789', 'Hyphens are removed from EAN field(s)' ); is( C4::Biblio::TransformMarcToKohaOneField( 'biblio.field1', $marc ), $result->{field1}, 'TransformMarcToKohaOneField returns biblio.field1'); @@ -67,7 +69,7 @@ subtest 'Test a few mappings' => sub { # CAUTION: This parameter of TransformMarcToKoha will be removed later my $new_fw = t::lib::TestBuilder->new->build({source => 'BiblioFramework'}); $result = C4::Biblio::TransformMarcToKoha($marc, $new_fw->{frameworkcode}); - is( keys %{$result}, 3, 'Still found all three mappings' ); + is( keys %{$result}, 4, 'Still found all four mappings' ); }; subtest 'Multiple mappings for one kohafield' => sub { -- 2.25.1