From ac0d340bd5d5f009fdd07b9db2095b3980a31500 Mon Sep 17 00:00:00 2001 From: Jesse Weaver Date: Fri, 25 Jul 2008 12:32:05 -0500 Subject: [PATCH] kohabug 2345: bad comparisons pervade reports This patch changes all $foo eq undef's to !defined($foo). It also makes misc/spellcheck_suggest/build_spellcheck_suggest.pl have proper syntax. Signed-off-by: Joshua Ferraro --- cataloguing/addbiblio.pl | 2 +- misc/cronjobs/holds/build_holds_queue.pl | 2 +- misc/spellcheck_suggest/make_spellcheck_suggest.pl | 6 ++---- reports/acquisitions_stats.pl | 6 +++--- reports/bor_issues_top.pl | 4 ++-- reports/borrowers_out.pl | 2 +- reports/borrowers_stats.pl | 6 +++--- reports/cat_issues_top.pl | 2 +- reports/catalogue_stats.pl | 6 +++--- reports/issues_avg_stats.pl | 6 +++--- 10 files changed, 20 insertions(+), 22 deletions(-) diff --git a/cataloguing/addbiblio.pl b/cataloguing/addbiblio.pl index 7713113b4a..f811c83c89 100755 --- a/cataloguing/addbiblio.pl +++ b/cataloguing/addbiblio.pl @@ -84,7 +84,7 @@ sub MARCfindbreeding { } } - if ( ref($record) eq undef ) { + if ( !defined(ref($record)) ) { return -1; } else { diff --git a/misc/cronjobs/holds/build_holds_queue.pl b/misc/cronjobs/holds/build_holds_queue.pl index 03a275f38a..e422248764 100755 --- a/misc/cronjobs/holds/build_holds_queue.pl +++ b/misc/cronjobs/holds/build_holds_queue.pl @@ -152,7 +152,7 @@ sub randarray { $rand[$randnum] = shift(@array); while (1) { my $randnum = int(rand($seed)); - if ($rand[$randnum] eq undef) { + if (!defined($rand[$randnum])) { $rand[$randnum] = shift(@array); } last if ($#array == -1); diff --git a/misc/spellcheck_suggest/make_spellcheck_suggest.pl b/misc/spellcheck_suggest/make_spellcheck_suggest.pl index 96ffea8ff3..097e792986 100755 --- a/misc/spellcheck_suggest/make_spellcheck_suggest.pl +++ b/misc/spellcheck_suggest/make_spellcheck_suggest.pl @@ -83,7 +83,7 @@ use C4::Context; # and uncomment the one after it, adding your site info (check out GRANT # syntax in the mysql manual if you're unsure how enable authentication) # -my dbh2 = C4::Context->dbh; +my $dbh2 = C4::Context->dbh; # #my $dbh2=DBI->connect("DBI:mysql::localhost","",""); ######################################################################## @@ -97,12 +97,10 @@ my $counter = 0; print "Step 1 of 5: Checking to make sure suggest tables exist\n"; my $check_tables_query = "select distinct resultcount from ?"; my @tables = ("notdistinctspchk", "notdistinctsugg", "spellcheck", "suggestions"); -my %tables = ( notdistinctspchk => "( display varchar(40) not null default, - suggestion varchar(40) not null default, foreach my $table (@tables) { my $sth_check=$dbh2->prepare($check_tables_query) || die "cant prepare query: $DBI::errstr"; my $rv = $sth_check->execute($table); - if($rv eq undef) { + if(!defined($rv)) { print "$table missing ... creating it now\n"; my $create_this = "CREATE TABLE \'$table\' \( display varchar\(40\) NOT NULL default \'\', diff --git a/reports/acquisitions_stats.pl b/reports/acquisitions_stats.pl index c5c4036c99..efa7bf2ea9 100755 --- a/reports/acquisitions_stats.pl +++ b/reports/acquisitions_stats.pl @@ -657,9 +657,9 @@ sub calculate { while ( my ( $row, $col, $value ) = $dbcalc->fetchrow ) { next if ($row eq undef || $col eq undef); #warn "filling table $row / $col / $value "; - $emptycol = 1 if ( $col eq undef ); - $col = "zzEMPTY" if ( $col eq undef ); - $row = "zzEMPTY" if ( $row eq undef ); + $emptycol = 1 if ( !defined($col) ); + $col = "zzEMPTY" if ( !defined($col) ); + $row = "zzEMPTY" if ( !defined($row) ); $table{$row}->{$col} += $value; $table{$row}->{totalrow} += $value; diff --git a/reports/bor_issues_top.pl b/reports/bor_issues_top.pl index 776136679f..f9cf661d85 100755 --- a/reports/bor_issues_top.pl +++ b/reports/bor_issues_top.pl @@ -340,7 +340,7 @@ sub calculate { # ) while (my @data = $dbcalc->fetchrow) { my ($row, $rank, $id, $col) = @data; - $col = "zzEMPTY" if ($col eq undef); + $col = "zzEMPTY" if (!defined($col)); unless ($patrons{$id}) { $patrons{$id} = {name=>$row, allcols=>{}, newcols=>{}, oldcols=>{}}; } @@ -356,7 +356,7 @@ sub calculate { $debug and print DEBUG "rows: ", $dbcalc->rows, "\n"; while (my @data = $dbcalc->fetchrow) { my ($row, $rank, $id, $col) = @data; - $col = "zzEMPTY" if ($col eq undef); + $col = "zzEMPTY" if (!defined($col)); unless ($patrons{$id}) { $patrons{$id} = {name=>$row, allcols=>{}, newcols=>{}, oldcols=>{}}; } diff --git a/reports/borrowers_out.pl b/reports/borrowers_out.pl index e836017acf..763fa7eafa 100755 --- a/reports/borrowers_out.pl +++ b/reports/borrowers_out.pl @@ -273,7 +273,7 @@ sub calculate { $i=1; while (my @data = $dbcalc->fetchrow) { my ($row, $col )=@data; - $col = "zzEMPTY" if ($col eq undef); + $col = "zzEMPTY" if (!defined($col)); $i=1 if (($previous_col) and not($col eq $previous_col)); $table[$i]->{$col}=$row; # warn " $i $col $row"; diff --git a/reports/borrowers_stats.pl b/reports/borrowers_stats.pl index df9e4df2e1..b379067f15 100755 --- a/reports/borrowers_stats.pl +++ b/reports/borrowers_stats.pl @@ -327,9 +327,9 @@ sub calculate { my $emptycol; while (my ($row, $col, $value) = $dbcalc->fetchrow) { # warn "filling table $row / $col / $value "; - $emptycol = 1 if ($col eq undef); - $col = "zzEMPTY" if ($col eq undef); - $row = "zzEMPTY" if ($row eq undef); + $emptycol = 1 if (!defined($col)); + $col = "zzEMPTY" if (!defined($col)); + $row = "zzEMPTY" if (!defined($row)); $table{$row}->{$col}+=$value; $table{$row}->{totalrow}+=$value; diff --git a/reports/cat_issues_top.pl b/reports/cat_issues_top.pl index b5db4ed3c8..c11c8998db 100755 --- a/reports/cat_issues_top.pl +++ b/reports/cat_issues_top.pl @@ -378,7 +378,7 @@ sub calculate { my %indice; while (my @data = $dbcalc->fetchrow) { my ($row, $rank, $id, $col )=@data; - $col = "zzEMPTY" if ($col eq undef); + $col = "zzEMPTY" if (!defined($col)); $indice{$col}=1 if (not($indice{$col})); $table[$indice{$col}]->{$col}->{'name'}=$row; $table[$indice{$col}]->{$col}->{'count'}=$rank; diff --git a/reports/catalogue_stats.pl b/reports/catalogue_stats.pl index 276294f493..3addbe77e0 100755 --- a/reports/catalogue_stats.pl +++ b/reports/catalogue_stats.pl @@ -432,9 +432,9 @@ sub calculate { my $emptycol; while (my ($row, $col, $value) = $dbcalc->fetchrow) { # warn "filling table $row / $col / $value "; - $emptycol = 1 if ($col eq undef); - $col = "zzEMPTY" if ($col eq undef); - $row = "zzEMPTY" if ($row eq undef); + $emptycol = 1 if (!defined($col)); + $col = "zzEMPTY" if (!defined($col)); + $row = "zzEMPTY" if (!defined($row)); $table{$row}->{$col}+=$value; $table{$row}->{totalrow}+=$value; diff --git a/reports/issues_avg_stats.pl b/reports/issues_avg_stats.pl index 8d9d70ddb1..1153aa3933 100755 --- a/reports/issues_avg_stats.pl +++ b/reports/issues_avg_stats.pl @@ -543,9 +543,9 @@ sub calculate { while (my @data = $dbcalc->fetchrow) { my ($row, $col, $issuedate, $returndate, $weight)=@data; # warn "filling table $row / $col / $issuedate / $returndate /$weight"; - $emptycol=1 if ($col eq undef); - $col = "zzEMPTY" if ($col eq undef); - $row = "zzEMPTY" if ($row eq undef); + $emptycol=1 if (!defined($col)); + $col = "zzEMPTY" if (!defined($col)); + $row = "zzEMPTY" if (!defined($row)); # fill returndate to avoid an error with date calc (needed for all non returned issues) $returndate= join '-',Date::Calc::Today if $returndate eq '0000-00-00'; # DateCalc returns => 0:0:WK:DD:HH:MM:SS the weeks, days, hours, minutes, -- 2.39.5