Bug 2505: adding warnings to C4/Biblio.pm
I added 'use warnings' to C4::Biblio and made a handful of changes to reduce the number of warnings emitted. One notable spot is the change in the regex in C4::Biblio::GetNoZebraIndexes. I have replaced the parens with a character class. The parens change the way 'split' works, making it return elements for each delimiter. We did not want those elements returned, and they only resulted in "'' => undef" being added to the final hash. They also resulted in two "undefined" warnings for each pass through the loop. I've included a simple test for this function. There may be a few warnings still emitted in spots, but either I haven't seen them yet, or I have chosen to not fix them yet because they require too much change. Signed-off-by: Galen Charlton <galen.charlton@liblime.com>
This commit is contained in:
parent
80781eedeb
commit
0b1c856e4b
25
C4/Biblio.pm
25
C4/Biblio.pm
|
|
@ -18,15 +18,14 @@ package C4::Biblio;
|
|||
# Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
# use utf8;
|
||||
use MARC::Record;
|
||||
use MARC::File::USMARC;
|
||||
use MARC::File::XML;
|
||||
use ZOOM;
|
||||
|
||||
use C4::Context;
|
||||
use C4::Koha;
|
||||
use C4::Branch;
|
||||
use C4::Dates qw/format_date/;
|
||||
use C4::Log; # logaction
|
||||
use C4::ClassSource;
|
||||
|
|
@ -107,12 +106,6 @@ BEGIN {
|
|||
);
|
||||
}
|
||||
|
||||
# because of interdependencies between
|
||||
# C4::Search, C4::Heading, and C4::Biblio,
|
||||
# 'use C4::Heading' must occur after
|
||||
# the exports have been defined.
|
||||
use C4::Heading;
|
||||
|
||||
=head1 NAME
|
||||
|
||||
C4::Biblio - cataloging management functions
|
||||
|
|
@ -1631,7 +1624,7 @@ sub TransformMarcToKoha {
|
|||
}
|
||||
|
||||
my %tables = ();
|
||||
if ($limit_table eq 'items') {
|
||||
if ( defined $limit_table && $limit_table eq 'items') {
|
||||
$tables{'items'} = 1;
|
||||
} else {
|
||||
$tables{'items'} = 1;
|
||||
|
|
@ -2179,9 +2172,9 @@ sub ModZebra {
|
|||
=cut
|
||||
|
||||
sub GetNoZebraIndexes {
|
||||
my $index = C4::Context->preference('NoZebraIndexes');
|
||||
my $no_zebra_indexes = C4::Context->preference('NoZebraIndexes');
|
||||
my %indexes;
|
||||
foreach my $line (split /('|"),[\n\r]*/,$index) {
|
||||
INDEX: foreach my $line (split /['"],[\n\r]*/,$no_zebra_indexes) {
|
||||
$line =~ /(.*)=>(.*)/;
|
||||
my $index = $1; # initial ' or " is removed afterwards
|
||||
my $fields = $2;
|
||||
|
|
@ -2258,7 +2251,7 @@ sub _DelBiblioNoZebra {
|
|||
foreach (split / /,$line) {
|
||||
next unless $_; # skip empty values (multiple spaces)
|
||||
# if the entry is already here, do nothing, the biblionumber has already be removed
|
||||
unless ($result{$key}->{$_} =~ /$biblionumber,$title\-(\d);/) {
|
||||
unless ( defined( $result{$key}->{$_} ) && ( $result{$key}->{$_} =~ /$biblionumber,$title\-(\d);/) ) {
|
||||
# get the index value if it exist in the nozebra table and remove the entry, otherwise, do nothing
|
||||
$sth2->execute($server,$key,$_);
|
||||
my $existing_biblionumbers = $sth2->fetchrow;
|
||||
|
|
@ -2355,8 +2348,8 @@ sub _AddBiblioNoZebra {
|
|||
next unless $_; # skip empty values (multiple spaces)
|
||||
# if the entry is already here, improve weight
|
||||
# warn "managing $_";
|
||||
if ($result{$key}->{"$_"} =~ /$biblionumber,\Q$title\E\-(\d+);/) {
|
||||
my $weight=$1 + 1;
|
||||
if ( exists $result{$key}->{$_} && $result{$key}->{"$_"} =~ /$biblionumber,\Q$title\E\-(\d+);/) {
|
||||
my $weight = $1 + 1;
|
||||
$result{$key}->{"$_"} =~ s/$biblionumber,\Q$title\E\-(\d+);//g;
|
||||
$result{$key}->{"$_"} .= "$biblionumber,$title-$weight;";
|
||||
} else {
|
||||
|
|
@ -2366,7 +2359,7 @@ sub _AddBiblioNoZebra {
|
|||
# it exists
|
||||
if ($existing_biblionumbers) {
|
||||
$result{$key}->{"$_"} =$existing_biblionumbers;
|
||||
my $weight=$1 + 1;
|
||||
my $weight = defined $1 ? $1 + 1 : 1;
|
||||
$result{$key}->{"$_"} =~ s/$biblionumber,\Q$title\E\-(\d+);//g;
|
||||
$result{$key}->{"$_"} .= "$biblionumber,$title-$weight;";
|
||||
# create a new ligne for this entry
|
||||
|
|
@ -3176,7 +3169,7 @@ sub get_biblio_authorised_values {
|
|||
foreach my $subfield ( keys( %{$tagslib->{ $tag }} ) ) {
|
||||
# warn "checking $subfield. type is: " . ref $tagslib->{ $tag }{ $subfield };
|
||||
if ( 'HASH' eq ref $tagslib->{ $tag }{ $subfield } ) {
|
||||
if ( exists $tagslib->{ $tag }{ $subfield }{'authorised_value'} && exists $bibliolevel_authorised_values->{ $tagslib->{ $tag }{ $subfield }{'authorised_value'} } ) {
|
||||
if ( defined $tagslib->{ $tag }{ $subfield }{'authorised_value'} && exists $bibliolevel_authorised_values->{ $tagslib->{ $tag }{ $subfield }{'authorised_value'} } ) {
|
||||
if ( defined $record->field( $tag ) ) {
|
||||
my $this_subfield_value = $record->field( $tag )->subfield( $subfield );
|
||||
if ( defined $this_subfield_value ) {
|
||||
|
|
|
|||
|
|
@ -0,0 +1,72 @@
|
|||
package KohaTest::Biblio::GetNoZebraIndexes;
|
||||
use base qw( KohaTest::Biblio );
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use Test::More;
|
||||
|
||||
use C4::Biblio;
|
||||
|
||||
=head2 STARTUP METHODS
|
||||
|
||||
These get run once, before the main test methods in this module
|
||||
|
||||
=cut
|
||||
|
||||
|
||||
=head2 TEST METHODS
|
||||
|
||||
standard test methods
|
||||
|
||||
=head3
|
||||
|
||||
=cut
|
||||
|
||||
sub returns_expected_hashref : Test(2) {
|
||||
my $self = shift;
|
||||
|
||||
my %nzi = C4::Biblio::GetNoZebraIndexes();
|
||||
ok( scalar keys %nzi, 'got some keys from GetNoZebraIndexes' );
|
||||
|
||||
my %expected = (
|
||||
'title' => '130a,210a,222a,240a,243a,245a,245b,246a,246b,247a,247b,250a,250b,440a,830a',
|
||||
'author' => '100a,100b,100c,100d,110a,111a,111b,111c,111d,245c,700a,710a,711a,800a,810a,811a',
|
||||
'isbn' => '020a',
|
||||
'issn' => '022a',
|
||||
'lccn' => '010a',
|
||||
'biblionumber' => '999c',
|
||||
'itemtype' => '942c',
|
||||
'publisher' => '260b',
|
||||
'date' => '260c',
|
||||
'note' => '500a,501a,504a,505a,508a,511a,518a,520a,521a,522a,524a,526a,530a,533a,538a,541a,546a,555a,556a,562a,563a,583a,585a,582a',
|
||||
'subject' => '600*,610*,611*,630*,650*,651*,653*,654*,655*,662*,690*',
|
||||
'dewey' => '082',
|
||||
'bc' => '952p',
|
||||
'callnum' => '952o',
|
||||
'an' => '6009,6109,6119',
|
||||
'homebranch' => '952a,952c'
|
||||
);
|
||||
is_deeply( \%nzi, \%expected, 'GetNoZebraIndexes returns the expected hashref' );
|
||||
}
|
||||
|
||||
=head2 HELPER METHODS
|
||||
|
||||
These methods are used by other test methods, but
|
||||
are not meant to be called directly.
|
||||
|
||||
=cut
|
||||
|
||||
=cut
|
||||
|
||||
|
||||
=head2 SHUTDOWN METHODS
|
||||
|
||||
These get run once, after the main test methods in this module
|
||||
|
||||
=head3
|
||||
|
||||
=cut
|
||||
|
||||
|
||||
1;
|
||||
Loading…
Reference in New Issue