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 <martin.renvoize@openfifth.co.uk> Assisted-by: Sonnet 4.6 (Anthropic) Signed-off-by: David Nind <david@davidnind.com> Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org> Signed-off-by: Pedro Amorim <pedro.amorim@openfifth.co.uk>
This commit is contained in:
parent
263a1bd536
commit
5fb7fd5f2d
28
C4/Koha.pm
28
C4/Koha.pm
|
|
@ -36,7 +36,6 @@ BEGIN {
|
||||||
GetNormalizedUPC
|
GetNormalizedUPC
|
||||||
GetNormalizedISBN
|
GetNormalizedISBN
|
||||||
GetNormalizedEAN
|
GetNormalizedEAN
|
||||||
GetNormalizedOCLCNumber
|
|
||||||
xml_escape
|
xml_escape
|
||||||
|
|
||||||
GetVariationsOfISBN
|
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 {
|
sub _normalize_match_point {
|
||||||
my $match_point = shift;
|
my $match_point = shift;
|
||||||
( my $normalized_match_point ) = $match_point =~ /([\d-]*[X]*)/;
|
( my $normalized_match_point ) = $match_point =~ /([\d-]*[X]*)/;
|
||||||
|
|
|
||||||
|
|
@ -19,8 +19,6 @@ package Koha::Util::MARC;
|
||||||
|
|
||||||
use Modern::Perl;
|
use Modern::Perl;
|
||||||
|
|
||||||
use constant OCLC_REGEX => qr/OCoLC/i; # made it case insensitive, includes the various oclc suffixes too
|
|
||||||
|
|
||||||
=head1 NAME
|
=head1 NAME
|
||||||
|
|
||||||
Koha::Util::MARC - utility class with routines for working with MARC records
|
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;
|
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;
|
1;
|
||||||
|
|
|
||||||
|
|
@ -105,7 +105,6 @@ unless ( $patron and $patron->category->override_hidden_items ) {
|
||||||
my $record = $biblio->metadata->record;
|
my $record = $biblio->metadata->record;
|
||||||
my @items = $biblio->items->filter_by_visible_in_opac( { patron => $patron } )->as_list;
|
my @items = $biblio->items->filter_by_visible_in_opac( { patron => $patron } )->as_list;
|
||||||
|
|
||||||
|
|
||||||
my $record_processor = Koha::RecordProcessor->new(
|
my $record_processor = Koha::RecordProcessor->new(
|
||||||
{
|
{
|
||||||
filters => [ 'EmbedItems', 'ViewPolicy' ],
|
filters => [ 'EmbedItems', 'ViewPolicy' ],
|
||||||
|
|
|
||||||
|
|
@ -44,8 +44,8 @@ subtest 'set_marc_field' => sub {
|
||||||
is( $subfields[0], 'foobaz', 'Subfield value has been changed' );
|
is( $subfields[0], 'foobaz', 'Subfield value has been changed' );
|
||||||
};
|
};
|
||||||
|
|
||||||
subtest 'find_marc_info, strip_orgcode, oclc_number' => sub {
|
subtest 'find_marc_info' => sub {
|
||||||
plan tests => 9;
|
plan tests => 4;
|
||||||
|
|
||||||
my $record = MARC::Record->new;
|
my $record = MARC::Record->new;
|
||||||
$record->append_fields(
|
$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' );
|
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' );
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -173,7 +173,7 @@ subtest 'Authorized Values Tests' => sub {
|
||||||
};
|
};
|
||||||
|
|
||||||
subtest 'isbn tests' => sub {
|
subtest 'isbn tests' => sub {
|
||||||
plan tests => 33;
|
plan tests => 32;
|
||||||
|
|
||||||
my $isbn13 = "9780330356473";
|
my $isbn13 = "9780330356473";
|
||||||
my $isbn13D = "978-0-330-35647-3";
|
my $isbn13D = "978-0-330-35647-3";
|
||||||
|
|
@ -288,10 +288,6 @@ subtest 'isbn tests' => sub {
|
||||||
C4::Koha::GetNormalizedEAN(), undef,
|
C4::Koha::GetNormalizedEAN(), undef,
|
||||||
'GetNormalizedEAN should return undef if no record and no isbn are passed'
|
'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' );
|
is( C4::Koha::GetNormalizedISBN('979-8-88650-962-5'), '9798886509625', 'Test GetNormalizedISBN' );
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue