From 5ee20cba58b7184ec84db850068e3319ff3428b2 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Thu, 5 Oct 2023 11:48:59 +0200 Subject: [PATCH] Bug 34828: Make normalized_oclc use Koha::Biblio::Metadata::Extractor Signed-off-by: David Nind Signed-off-by: Tomas Cohen Arazi --- Koha/Biblio.pm | 2 +- Koha/Biblio/Metadata/Extractor/MARC/MARC21.pm | 22 +++++++++++++++++++ .../Biblio/Metadata/Extractor/MARC/MARC21.t | 19 +++++++++++++++- 3 files changed, 41 insertions(+), 2 deletions(-) diff --git a/Koha/Biblio.pm b/Koha/Biblio.pm index 881e51014c..86b7151769 100644 --- a/Koha/Biblio.pm +++ b/Koha/Biblio.pm @@ -1321,7 +1321,7 @@ Normalizes and returns the OCLC number found in the MARC record. sub normalized_oclc { my ($self) = @_; my $marc_record = $self->metadata->record; - return C4::Koha::GetNormalizedOCLCNumber($marc_record); + return $self->metadata_extractor->get_normalized_oclc; } =head3 to_api diff --git a/Koha/Biblio/Metadata/Extractor/MARC/MARC21.pm b/Koha/Biblio/Metadata/Extractor/MARC/MARC21.pm index 8c4c7343f4..4fe7df8afe 100644 --- a/Koha/Biblio/Metadata/Extractor/MARC/MARC21.pm +++ b/Koha/Biblio/Metadata/Extractor/MARC/MARC21.pm @@ -74,6 +74,28 @@ sub get_normalized_upc { } } +=head2 get_normalized_oclc + + my $normalized_oclc = $extractor->get_normalized_oclc(); + +Returns a normalized OCLC number. + +=cut + +sub get_normalized_oclc { + my ($self) = @_; + + my $record = $self->metadata; + my @fields = $record->field('035'); + foreach my $field (@fields) { + my $oclc = $field->subfield('a'); + if ( $oclc && $oclc =~ /OCoLC/ ) { + $oclc =~ s/\(OCoLC\)//; + return $oclc; + } + } +} + =head1 AUTHOR Tomas Cohen Arazi, Etomascohen@theke.ioE diff --git a/t/db_dependent/Koha/Biblio/Metadata/Extractor/MARC/MARC21.t b/t/db_dependent/Koha/Biblio/Metadata/Extractor/MARC/MARC21.t index fcb17b3b51..80211f1271 100755 --- a/t/db_dependent/Koha/Biblio/Metadata/Extractor/MARC/MARC21.t +++ b/t/db_dependent/Koha/Biblio/Metadata/Extractor/MARC/MARC21.t @@ -19,7 +19,7 @@ use Modern::Perl; -use Test::More tests => 2; +use Test::More tests => 3; use Test::Exception; use t::lib::TestBuilder; @@ -69,3 +69,20 @@ subtest 'get_normalized_upc() tests' => sub { is( $extractor->get_normalized_upc, "" ); }; + +subtest 'get_normalized_oclc() tests' => sub { + + plan tests => 2; + + my $record = MARC::Record->new(); + $record->append_fields( MARC::Field->new( '035', ' ', ' ', a => "(OCoLC)902632762" ) ); + + my $extractor = Koha::Biblio::Metadata::Extractor->new( { metadata => $record } ); + is( $extractor->get_normalized_oclc, '902632762' ); + + $record = MARC::Record->new(); + $extractor = Koha::Biblio::Metadata::Extractor->new( { metadata => $record } ); + + is( $extractor->get_normalized_oclc, "" ); + +}; -- 2.39.5