diff --git a/C4/Koha.pm b/C4/Koha.pm index 66e491699a..52c8b8f7c9 100644 --- a/C4/Koha.pm +++ b/C4/Koha.pm @@ -33,7 +33,6 @@ BEGIN { getitemtypeimagesrc getitemtypeimagelocation GetAuthorisedValues - GetNormalizedUPC GetNormalizedISBN GetNormalizedEAN xml_escape @@ -600,39 +599,6 @@ sub display_marc_indicators { return $indicators; } -=head2 GetNormalizedUPC - -Missing POD for GetNormalizedUPC. - -=cut - -sub GetNormalizedUPC { - my ( $marcrecord, $marcflavour ) = @_; - - $marcflavour ||= C4::Context->preference('marcflavour'); - - return unless $marcrecord; - if ( $marcflavour eq 'UNIMARC' ) { - my @fields = $marcrecord->field('072'); - foreach my $field (@fields) { - my $upc = _normalize_match_point( $field->subfield('a') ); - if ($upc) { - return $upc; - } - } - - } else { # assume marc21 if not unimarc - my @fields = $marcrecord->field('024'); - foreach my $field (@fields) { - my $indicator = $field->indicator(1); - my $upc = _normalize_match_point( $field->subfield('a') ); - if ( $upc && $indicator eq '1' ) { - return $upc; - } - } - } -} - # Normalizes and returns the first valid ISBN found in the record # ISBN13 are converted into ISBN10. This is required to get some book cover images. diff --git a/C4/Search.pm b/C4/Search.pm index 3f879be8a9..3dc16f86f2 100644 --- a/C4/Search.pm +++ b/C4/Search.pm @@ -35,8 +35,7 @@ BEGIN { use C4::Context; use C4::Biblio qw( TransformMarcToKoha GetMarcFromKohaField GetFrameworkCode GetAuthorisedValueDesc GetBiblioData ); -use C4::Koha - qw( getFacets GetVariationsOfISBN GetNormalizedUPC GetNormalizedEAN GetNormalizedISBN getitemtypeimagelocation ); +use C4::Koha qw( getFacets GetVariationsOfISBN GetNormalizedEAN GetNormalizedISBN getitemtypeimagelocation ); use Koha::Biblio::Metadata::Extractor; use Koha::DateUtils; use Koha::Libraries; @@ -1769,10 +1768,10 @@ sub searchResults { my $oldbiblio = TransformMarcToKoha( { record => $marcrecord, limit_table => 'no_items' } ); $oldbiblio->{result_number} = $i + 1; - $oldbiblio->{normalized_upc} = GetNormalizedUPC( $marcrecord, $marcflavour ); - $oldbiblio->{normalized_ean} = GetNormalizedEAN( $marcrecord, $marcflavour ); - $oldbiblio->{normalized_oclc} = - Koha::Biblio::Metadata::Extractor->new( { metadata => $marcrecord } )->get_normalized_oclc; + my $extractor = Koha::Biblio::Metadata::Extractor->new( { metadata => $marcrecord } ); + $oldbiblio->{normalized_upc} = $extractor->get_normalized_upc; + $oldbiblio->{normalized_ean} = GetNormalizedEAN( $marcrecord, $marcflavour ); + $oldbiblio->{normalized_oclc} = $extractor->get_normalized_oclc; $oldbiblio->{normalized_isbn} = GetNormalizedISBN( $oldbiblio->{isbn}, $marcrecord, $marcflavour ) ; # Use existing ISBN from record if we got one $oldbiblio->{content_identifier_exists} = 1 diff --git a/C4/ShelfBrowser.pm b/C4/ShelfBrowser.pm index e0e6918721..7a6787fad9 100644 --- a/C4/ShelfBrowser.pm +++ b/C4/ShelfBrowser.pm @@ -28,8 +28,7 @@ BEGIN { use C4::Biblio qw( GetAuthorisedValueDesc ); use C4::Context; -use C4::Koha qw( GetNormalizedUPC GetNormalizedISBN GetNormalizedEAN ); -use Koha::Biblio::Metadata::Extractor; +use C4::Koha qw( GetNormalizedISBN GetNormalizedEAN ); use Koha::Biblios; use Koha::Libraries; @@ -236,9 +235,8 @@ sub GetShelfInfo { $item->{part_number} = $biblio->part_number; $item->{part_name} = $biblio->part_name; my $this_record = $biblio->metadata->record; - $item->{'browser_normalized_upc'} = GetNormalizedUPC( $this_record, $marcflavour ); - $item->{'browser_normalized_oclc'} = - Koha::Biblio::Metadata::Extractor->new( { metadata => $this_record } )->get_normalized_oclc; + $item->{'browser_normalized_upc'} = $biblio->normalized_upc; + $item->{'browser_normalized_oclc'} = $biblio->normalized_oclc; $item->{'browser_normalized_isbn'} = GetNormalizedISBN( undef, $this_record, $marcflavour ); $item->{'browser_normalized_ean'} = GetNormalizedEAN( $this_record, $marcflavour ); push @valid_items, $item; diff --git a/catalogue/detail.pl b/catalogue/detail.pl index 401fdad674..9fc6f3e259 100755 --- a/catalogue/detail.pl +++ b/catalogue/detail.pl @@ -25,7 +25,6 @@ use C4::Koha qw( getitemtypeimagelocation GetNormalizedEAN GetNormalizedISBN - GetNormalizedUPC ); use C4::Serials qw( CountSubscriptionFromBiblionumber SearchSubscriptions GetLatestSerials ); use C4::Output qw( output_html_with_http_headers ); @@ -168,7 +167,7 @@ $template->param( ocoins => !$invalid_marc_record ? $biblio->get_coins : undef ) # some useful variables for enhanced content; # in each case, we're grabbing the first value we find in # the record and normalizing it -my $upc = GetNormalizedUPC( $marc_record, $marcflavour ); +my $upc = $biblio->normalized_upc; my $ean = GetNormalizedEAN( $marc_record, $marcflavour ); my $oclc = $biblio->normalized_oclc; my $isbn = GetNormalizedISBN( undef, $marc_record, $marcflavour ); diff --git a/opac/opac-ISBDdetail.pl b/opac/opac-ISBDdetail.pl index 405e94b0a3..b0a8937d3e 100755 --- a/opac/opac-ISBDdetail.pl +++ b/opac/opac-ISBDdetail.pl @@ -56,7 +56,6 @@ use C4::Serials qw( CountSubscriptionFromBiblionumber SearchSubscriptions GetLa use C4::Koha qw( GetNormalizedEAN GetNormalizedISBN - GetNormalizedUPC ); use Koha::CirculationRules; use Koha::ItemTypes; @@ -131,7 +130,7 @@ my $marcflavour = C4::Context->preference("marcflavour"); # some useful variables for enhanced content; # in each case, we're grabbing the first value we find in # the record and normalizing it -my $upc = GetNormalizedUPC( $record, $marcflavour ); +my $upc = $biblio->normalized_upc; my $ean = GetNormalizedEAN( $record, $marcflavour ); my $oclc = $extractor->get_normalized_oclc; my $isbn = GetNormalizedISBN( undef, $record, $marcflavour ); diff --git a/opac/opac-detail.pl b/opac/opac-detail.pl index b650dace60..c298ba692c 100755 --- a/opac/opac-detail.pl +++ b/opac/opac-detail.pl @@ -28,7 +28,6 @@ use C4::Koha qw( getitemtypeimagelocation GetNormalizedEAN GetNormalizedISBN - GetNormalizedUPC ); use C4::Search qw( new_record_from_zebra searchResults getRecords ); use C4::Serials qw( CountSubscriptionFromBiblionumber SearchSubscriptions GetLatestSerials ); @@ -874,7 +873,7 @@ foreach ( keys %{$dat} ) { # some useful variables for enhanced content; # in each case, we're grabbing the first value we find in # the record and normalizing it -my $upc = GetNormalizedUPC( $record, $marcflavour ); +my $upc = $extractor->get_normalized_upc; my $oclc = $extractor->get_normalized_oclc; my $isbn = GetNormalizedISBN( undef, $record, $marcflavour ); my $content_identifier_exists; diff --git a/opac/opac-shelves.pl b/opac/opac-shelves.pl index edc2942632..64eecc9140 100755 --- a/opac/opac-shelves.pl +++ b/opac/opac-shelves.pl @@ -25,7 +25,6 @@ use C4::Biblio qw( GetBiblioData GetFrameworkCode ); use C4::Koha qw( GetNormalizedEAN GetNormalizedISBN - GetNormalizedUPC ); use C4::Members; use C4::Output qw( pagination_bar output_with_http_headers ); @@ -43,6 +42,7 @@ use Koha::Patrons; use Koha::Virtualshelfshares; use Koha::Virtualshelves; use Koha::RecordProcessor; +use Koha::Biblio::Metadata::Extractor; use constant ANYONE => 2; use constant STAFF => 3; @@ -388,8 +388,9 @@ if ( $op eq 'view' ) { $this_item->{description} = $itemtype->description; #FIXME Should not it be translated_description? $this_item->{notforloan} = $itemtype->notforloan; } - $this_item->{'coins'} = $biblio->get_coins; - $this_item->{'normalized_upc'} = GetNormalizedUPC( $record, $marcflavour ); + $this_item->{'coins'} = $biblio->get_coins; + $this_item->{'normalized_upc'} = + Koha::Biblio::Metadata::Extractor->new( { metadata => $record } )->get_normalized_upc; $this_item->{'normalized_ean'} = GetNormalizedEAN( $record, $marcflavour ); $this_item->{'normalized_oclc'} = Koha::Biblio::Metadata::Extractor->new( { metadata => $record } )->get_normalized_oclc; diff --git a/opac/opac-showreviews.pl b/opac/opac-showreviews.pl index 0b71f0bbc4..ac525337ee 100755 --- a/opac/opac-showreviews.pl +++ b/opac/opac-showreviews.pl @@ -25,7 +25,6 @@ use C4::Auth qw( get_template_and_user ); use C4::Koha qw( GetNormalizedEAN GetNormalizedISBN - GetNormalizedUPC ); use C4::Output qw( output_html_with_http_headers ); use Koha::DateUtils qw( dt_from_string ); @@ -93,7 +92,7 @@ for my $result (@$reviews) { my $biblio = Koha::Biblios->find($biblionumber); my $biblioitem = $biblio->biblioitem; my $record = $biblio->metadata->record; - $result->{normalized_upc} = GetNormalizedUPC( $record, $marcflavour ); + $result->{normalized_upc} = $biblio->normalized_upc; $result->{normalized_ean} = GetNormalizedEAN( $record, $marcflavour ); $result->{normalized_oclc} = Koha::Biblio::Metadata::Extractor->new( { metadata => $record } )->get_normalized_oclc; $result->{normalized_isbn} = GetNormalizedISBN( undef, $record, $marcflavour ); diff --git a/opac/opac-user.pl b/opac/opac-user.pl index c99a2c60ed..9c446d223a 100755 --- a/opac/opac-user.pl +++ b/opac/opac-user.pl @@ -25,7 +25,6 @@ use C4::Auth qw( get_template_and_user ); use C4::Koha qw( getitemtypeimagelocation GetNormalizedISBN - GetNormalizedUPC ); use C4::Circulation qw( CanBookBeRenewed GetRenewCount GetIssuingCharges ); use C4::Reserves qw( GetReserveStatus ); @@ -33,6 +32,7 @@ use C4::Members; use C4::Output qw( output_html_with_http_headers ); use Koha::Account::Lines; use Koha::Biblios; +use Koha::Biblio::Metadata::Extractor; use Koha::Libraries; use Koha::DateUtils qw( output_pref ); use Koha::Holds; @@ -306,9 +306,9 @@ if ( $pending_checkouts->count ) { # Useless test patron => $patron } ); - $issue->{normalized_upc} = GetNormalizedUPC( $marcrecord, C4::Context->preference('marcflavour') ); - $issue->{normalized_oclc} = - Koha::Biblio::Metadata::Extractor->new( { metadata => $marcrecord } )->get_normalized_oclc; + my $extractor = Koha::Biblio::Metadata::Extractor->new( { metadata => $marcrecord } ); + $issue->{normalized_upc} = $extractor->get_normalized_upc; + $issue->{normalized_oclc} = $extractor->get_normalized_oclc; } if ( C4::Context->preference('UseRecalls') ) { diff --git a/t/db_dependent/Koha.t b/t/db_dependent/Koha.t index 119716857d..a7311b8fd9 100755 --- a/t/db_dependent/Koha.t +++ b/t/db_dependent/Koha.t @@ -173,7 +173,7 @@ subtest 'Authorized Values Tests' => sub { }; subtest 'isbn tests' => sub { - plan tests => 32; + plan tests => 31; my $isbn13 = "9780330356473"; my $isbn13D = "978-0-330-35647-3"; @@ -279,7 +279,6 @@ subtest 'isbn tests' => sub { my $test_isbn10 = Business::ISBN->new($test_normalized_isbn10); is( $test_isbn10->type, 'ISBN10', 'ISBN not starting with 979 is normalized to valid ISBN-10 format' ); - is( C4::Koha::GetNormalizedUPC(), undef, 'GetNormalizedUPC should return undef if no record is passed' ); is( C4::Koha::GetNormalizedISBN(), undef, 'GetNormalizedISBN should return undef if no record and no isbn are passed' diff --git a/t/db_dependent/Koha/Biblio.t b/t/db_dependent/Koha/Biblio.t index 86b83de00b..43eba5d103 100755 --- a/t/db_dependent/Koha/Biblio.t +++ b/t/db_dependent/Koha/Biblio.t @@ -2027,12 +2027,10 @@ subtest 'normalized_upc() tests' => sub { $schema->storage->txn_begin; - # We will move the tests from GetNormalizedUPC here when it will get replaced - # Note that only a single test exist and it's not really meaningful... my $biblio = $builder->build_sample_biblio(); is( - $biblio->normalized_upc, C4::Koha::GetNormalizedUPC( $biblio->metadata->record ), - 'normalized_upc is a wrapper around C4::Koha::GetNormalizedUPC' + $biblio->normalized_upc, $biblio->metadata_extractor->get_normalized_upc, + 'normalized_upc delegates to the metadata extractor' ); $schema->storage->txn_rollback; diff --git a/virtualshelves/shelves.pl b/virtualshelves/shelves.pl index 3167a67fa2..b419245612 100755 --- a/virtualshelves/shelves.pl +++ b/virtualshelves/shelves.pl @@ -25,7 +25,6 @@ use C4::Context; use C4::Koha qw( GetNormalizedEAN GetNormalizedISBN - GetNormalizedUPC ); use C4::Members; use C4::Output qw( pagination_bar output_html_with_http_headers output_and_exit_if_error ); @@ -352,7 +351,7 @@ if ( $op eq 'view' ) { $itemtype ? $itemtype->description : q{}; #FIXME Should this be translated_description ? $this_item->{notforloan} = $itemtype->notforloan if $itemtype; $this_item->{'coins'} = $biblio->get_coins; - $this_item->{'normalized_upc'} = GetNormalizedUPC( $record, $marcflavour ); + $this_item->{'normalized_upc'} = $biblio->normalized_upc; $this_item->{'normalized_ean'} = GetNormalizedEAN( $record, $marcflavour ); $this_item->{'normalized_oclc'} = $biblio->normalized_oclc; $this_item->{'normalized_isbn'} = GetNormalizedISBN( undef, $record, $marcflavour );