From 5fb7fd5f2d92a083f691bd538787d21c8712c1c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1s=20Cohen=20Arazi?= Date: Fri, 19 Jun 2026 17:36:31 -0300 Subject: [PATCH] Bug 35142: Remove GetNormalizedOCLCNumber, oclc_number, strip_orgcode All callers migrated. Removes dead code: - C4::Koha::GetNormalizedOCLCNumber - Koha::Util::MARC::oclc_number - Koha::Util::MARC::strip_orgcode - Koha::Util::MARC::OCLC_REGEX constant Test plan: $ prove t/Koha/Util/MARC.t t/db_dependent/Koha.t Signed-off-by: Martin Renvoize Assisted-by: Sonnet 4.6 (Anthropic) Signed-off-by: David Nind Signed-off-by: Jonathan Druart Signed-off-by: Pedro Amorim --- C4/Koha.pm | 28 ---------------------------- Koha/Util/MARC.pm | 37 ------------------------------------- opac/opac-ISBDdetail.pl | 1 - t/Koha/Util/MARC.t | 19 ++----------------- t/db_dependent/Koha.t | 6 +----- 5 files changed, 3 insertions(+), 88 deletions(-) diff --git a/C4/Koha.pm b/C4/Koha.pm index ec561a08e3..66e491699a 100644 --- a/C4/Koha.pm +++ b/C4/Koha.pm @@ -36,7 +36,6 @@ BEGIN { GetNormalizedUPC GetNormalizedISBN GetNormalizedEAN - GetNormalizedOCLCNumber xml_escape GetVariationsOfISBN @@ -705,33 +704,6 @@ sub GetNormalizedEAN { } } -=head2 GetNormalizedOCLCNumber - -Missing POD for GetNormalizedOCLCNumber. - -=cut - -sub GetNormalizedOCLCNumber { - my ( $marcrecord, $marcflavour ) = @_; - return unless $marcrecord; - - $marcflavour ||= C4::Context->preference('marcflavour'); - - if ( $marcflavour ne 'UNIMARC' ) { - my @fields = $marcrecord->field('035'); - foreach my $field (@fields) { - my $oclc = $field->subfield('a'); - if ( $oclc && $oclc =~ /OCoLC/ ) { - $oclc =~ s/\(OCoLC\)//; - return $oclc; - } - } - } else { - - # TODO for UNIMARC - } -} - sub _normalize_match_point { my $match_point = shift; ( my $normalized_match_point ) = $match_point =~ /([\d-]*[X]*)/; diff --git a/Koha/Util/MARC.pm b/Koha/Util/MARC.pm index e7dada4870..608a14b5f2 100644 --- a/Koha/Util/MARC.pm +++ b/Koha/Util/MARC.pm @@ -19,8 +19,6 @@ package Koha::Util::MARC; use Modern::Perl; -use constant OCLC_REGEX => qr/OCoLC/i; # made it case insensitive, includes the various oclc suffixes too - =head1 NAME Koha::Util::MARC - utility class with routines for working with MARC records @@ -249,39 +247,4 @@ sub find_marc_info { return $rv[0] if @rv; } -=head2 strip_orgcode - - my $id = strip_orgcode( '(code) 123' ); # returns '123' - - Strips from starting left paren to first right paren and trailing whitespace. - -=cut - -sub strip_orgcode { - my $arg = shift; - $arg =~ s/^\([^)]*\)\s*// if $arg; - return $arg; -} - -=head2 oclc_number - - my $id = oclc_number( $record ); - - Based on applying strip_orgcode on first occurrence of find_marc_info - with orgcode matching regex in 035$a. - -=cut; - -sub oclc_number { - my $record = shift; - return strip_orgcode( - scalar find_marc_info( - { - # Note: Field 035 same for MARC21 and UNIMARC - record => $record, field => '035', subfield => 'a', match => OCLC_REGEX, - } - ) - ); -} - 1; diff --git a/opac/opac-ISBDdetail.pl b/opac/opac-ISBDdetail.pl index 246aed3bd0..405e94b0a3 100755 --- a/opac/opac-ISBDdetail.pl +++ b/opac/opac-ISBDdetail.pl @@ -105,7 +105,6 @@ unless ( $patron and $patron->category->override_hidden_items ) { my $record = $biblio->metadata->record; my @items = $biblio->items->filter_by_visible_in_opac( { patron => $patron } )->as_list; - my $record_processor = Koha::RecordProcessor->new( { filters => [ 'EmbedItems', 'ViewPolicy' ], diff --git a/t/Koha/Util/MARC.t b/t/Koha/Util/MARC.t index bc339d6d74..5d6df27e2d 100755 --- a/t/Koha/Util/MARC.t +++ b/t/Koha/Util/MARC.t @@ -44,8 +44,8 @@ subtest 'set_marc_field' => sub { is( $subfields[0], 'foobaz', 'Subfield value has been changed' ); }; -subtest 'find_marc_info, strip_orgcode, oclc_number' => sub { - plan tests => 9; +subtest 'find_marc_info' => sub { + plan tests => 4; my $record = MARC::Record->new; $record->append_fields( @@ -90,19 +90,4 @@ subtest 'find_marc_info, strip_orgcode, oclc_number' => sub { ); is_deeply( \@list, [ '(change)456', '(change) 567' ], '035a, match, list' ); - @list = map { Koha::Util::MARC::strip_orgcode($_) } @list; - is_deeply( \@list, [ '456', '567' ], 'strip the orgcodes' ); - @list = map { Koha::Util::MARC::strip_orgcode($_) } ( '() a', '(a)(b) c', '(abc', ' (a)b' ); - is_deeply( \@list, [ 'a', '(b) c', '(abc', ' (a)b' ], 'edge cases for strip_orgcode' ); - - is( Koha::Util::MARC::oclc_number(), undef, 'No arg for oclc_number' ); - $record->append_fields( - MARC::Field->new( '035', '', '', a => '(OCoLC) 678' ), - ); - is( Koha::Util::MARC::oclc_number($record), '678', 'orgcode mixed case' ); - $record->insert_fields_ordered( - MARC::Field->new( '035', '', '', a => '(ocolc) 789' ), - ); - is( Koha::Util::MARC::oclc_number($record), '789', 'orgcode lower case' ); - }; diff --git a/t/db_dependent/Koha.t b/t/db_dependent/Koha.t index 47a9998610..119716857d 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 => 33; + plan tests => 32; my $isbn13 = "9780330356473"; my $isbn13D = "978-0-330-35647-3"; @@ -288,10 +288,6 @@ subtest 'isbn tests' => sub { C4::Koha::GetNormalizedEAN(), undef, 'GetNormalizedEAN should return undef if no record and no isbn are passed' ); - is( - C4::Koha::GetNormalizedOCLCNumber(), undef, - 'GetNormalizedOCLCNumber should return undef if no record and no isbn are passed' - ); is( C4::Koha::GetNormalizedISBN('979-8-88650-962-5'), '9798886509625', 'Test GetNormalizedISBN' );