From bcde53b5ba071ed33caa0b5a3734a62a481da795 Mon Sep 17 00:00:00 2001 From: Colin Campbell Date: Fri, 2 Oct 2009 12:22:47 +0100 Subject: [PATCH] Bug 2505 Enabled warnings in authorities/* Fixed obvious warnings generators in scripts with mismatched comparisons or undefined variables removed temporary variable selected while ensuring the comparison it represented was between two defined variables Signed-off-by: Galen Charlton --- C4/AuthoritiesMarc.pm | 2 +- authorities/auth_finder.pl | 5 +++-- authorities/authorities-home.pl | 15 +++++++++++++-- authorities/authorities.pl | 14 +++++++++----- authorities/blinddetail-biblio-search.pl | 7 +++++-- authorities/detail-biblio-search.pl | 5 ++--- authorities/detail.pl | 8 +++----- 7 files changed, 36 insertions(+), 20 deletions(-) diff --git a/C4/AuthoritiesMarc.pm b/C4/AuthoritiesMarc.pm index 3d4564e2a0..d77ac2aec3 100644 --- a/C4/AuthoritiesMarc.pm +++ b/C4/AuthoritiesMarc.pm @@ -537,7 +537,7 @@ sub GetTagsLabels { my $dbh=C4::Context->dbh; $authtypecode="" unless $authtypecode; my $sth; - my $libfield = ($forlibrarian eq 1)? 'liblibrarian' : 'libopac'; + my $libfield = ($forlibrarian == 1)? 'liblibrarian' : 'libopac'; # check that authority exists diff --git a/authorities/auth_finder.pl b/authorities/auth_finder.pl index 7070b12d38..9f183a5fb2 100755 --- a/authorities/auth_finder.pl +++ b/authorities/auth_finder.pl @@ -19,6 +19,7 @@ # Suite 330, Boston, MA 02111-1307 USA use strict; +use warnings; use CGI; use C4::Output; @@ -44,16 +45,16 @@ my $resultsperpage; my $authtypes = getauthtypes; my @authtypesloop; foreach my $thisauthtype ( keys %$authtypes ) { - my $selected = 1 if $thisauthtype eq $authtypecode; my %row = ( value => $thisauthtype, - selected => $selected, + selected => ($thisauthtype eq $authtypecode), authtypetext => $authtypes->{$thisauthtype}{'authtypetext'}, index => $index, ); push @authtypesloop, \%row; } +$op ||= q{}; if ( $op eq "do_search" ) { my @marclist = $query->param('marclist'); my @and_or = $query->param('and_or'); diff --git a/authorities/authorities-home.pl b/authorities/authorities-home.pl index d80acc4ff9..52e7f66441 100755 --- a/authorities/authorities-home.pl +++ b/authorities/authorities-home.pl @@ -18,6 +18,7 @@ # Suite 330, Boston, MA 02111-1307 USA use strict; +use warnings; use CGI; use C4::Auth; @@ -32,7 +33,9 @@ use C4::Biblio; my $query = new CGI; my $op = $query->param('op'); +$op ||= q{}; my $authtypecode = $query->param('authtypecode'); +$authtypecode ||= q{}; my $dbh = C4::Context->dbh; my $authid = $query->param('authid'); @@ -43,10 +46,9 @@ my @authtypesloop; foreach my $thisauthtype ( sort { $authtypes->{$a}{'authtypetext'} cmp $authtypes->{$b}{'authtypetext'} } keys %$authtypes ) { - my $selected = 1 if $thisauthtype eq $authtypecode; my %row = ( value => $thisauthtype, - selected => $selected, + selected => $thisauthtype eq $authtypecode, authtypetext => $authtypes->{$thisauthtype}{'authtypetext'}, ); push @authtypesloop, \%row; @@ -88,7 +90,13 @@ if ( $op eq "do_search" ) { for ( my $i = 0 ; $i <= $#marclist ; $i++ ) { if ($value[$i]){ push @field_data, { term => "marclist", val => $marclist_ini[$i] }; + if (!defined $and_or[$i]) { + $and_or[$i] = q{}; + } push @field_data, { term => "and_or", val => $and_or[$i] }; + if (!defined $excluding[$i]) { + $excluding[$i] = q{}; + } push @field_data, { term => "excluding", val => $excluding[$i] }; push @field_data, { term => "operator", val => $operator[$i] }; push @field_data, { term => "value", val => $value[$i] }; @@ -113,6 +121,9 @@ if ( $op eq "do_search" ) { my $from = ( $startfrom - 1 ) * $resultsperpage + 1; my $to; + if (!defined $total) { + $total = 0; + } if ( $total < $startfrom * $resultsperpage ) { $to = $total; diff --git a/authorities/authorities.pl b/authorities/authorities.pl index 9eb205de35..26ef631b1d 100755 --- a/authorities/authorities.pl +++ b/authorities/authorities.pl @@ -19,6 +19,7 @@ # Suite 330, Boston, MA 02111-1307 USA use strict; +use warnings; use CGI; use C4::Auth; use C4::Output; @@ -131,6 +132,9 @@ sub create_input { # if there is no value provided but a default value in parameters, get it unless ($value) { $value = $tagslib->{$tag}->{$subfield}->{defaultvalue}; + if (!defined $value) { + $value = q{}; + } # get today date & replace YYYY, MM, DD if provided in the default value my ( $year, $month, $day ) = Today(); @@ -351,7 +355,7 @@ sub build_tabs ($$$$$) { # if MARC::Record is not empty =>use it as master loop, then add missing subfields that should be in the tab. # if MARC::Record is empty => use tab as master loop. - if ( $record ne -1 && ( $record->field($tag) || $tag eq '000' ) ) { + if ( $record != -1 && ( $record->field($tag) || $tag eq '000' ) ) { my @fields; if ( $tag ne '000' ) { @fields = $record->field($tag); @@ -552,7 +556,7 @@ if ($authid) { ($oldauthnumtagfield,$oldauthnumtagsubfield) = &GetAuthMARCFromKohaField("auth_header.authid",$authtypecode); ($oldauthtypetagfield,$oldauthtypetagsubfield) = &GetAuthMARCFromKohaField("auth_header.authtypecode",$authtypecode); } - +$op ||= q{}; #------------------------------------------------------------------------------------------------------------------------------ if ($op eq "add") { #------------------------------------------------------------------------------------------------------------------------------ @@ -577,7 +581,8 @@ if ($op eq "add") { } } - my ($duplicateauthid,$duplicateauthvalue) = FindDuplicateAuthority($record,$authtypecode) if ($op eq "add") && (!$is_a_modif); + my ($duplicateauthid,$duplicateauthvalue); + ($duplicateauthid,$duplicateauthvalue) = FindDuplicateAuthority($record,$authtypecode) if ($op eq "add") && (!$is_a_modif); my $confirm_not_duplicate = $input->param('confirm_not_duplicate'); # it is not a duplicate (determined either by Koha itself or by user checking it's not a duplicate) if (!$duplicateauthid or $confirm_not_duplicate) { @@ -626,9 +631,8 @@ $template->param(authid => $authid, my $authtypes = getauthtypes; my @authtypesloop; foreach my $thisauthtype (keys %$authtypes) { - my $selected = 1 if $thisauthtype eq $authtypecode; my %row =(value => $thisauthtype, - selected => $selected, + selected => $thisauthtype eq $authtypecode, authtypetext => $authtypes->{$thisauthtype}{'authtypetext'}, ); push @authtypesloop, \%row; diff --git a/authorities/blinddetail-biblio-search.pl b/authorities/blinddetail-biblio-search.pl index c8896aa339..a9227136c8 100755 --- a/authorities/blinddetail-biblio-search.pl +++ b/authorities/blinddetail-biblio-search.pl @@ -38,6 +38,7 @@ parameters tables. =cut use strict; +use warnings; use C4::AuthoritiesMarc; use C4::Auth; @@ -58,7 +59,10 @@ my $authtypecode = &GetAuthTypeCode($authid); my $tagslib = &GetTagsLabels( 1, $authtypecode ); my $auth_type = GetAuthType($authtypecode); -my $record = GetAuthority($authid) if $authid; +my $record; +if ($authid) { + $record = GetAuthority($authid); +} # open template my ( $template, $loggedinuser, $cookie ) = get_template_and_user( @@ -72,7 +76,6 @@ my ( $template, $loggedinuser, $cookie ) = get_template_and_user( ); # fill arrays -my $tag; my @loop_data = (); if ($authid) { foreach my $field ( $record->field( $auth_type->{auth_tag_to_report} ) ) { diff --git a/authorities/detail-biblio-search.pl b/authorities/detail-biblio-search.pl index 204dd57daf..5562e018bc 100755 --- a/authorities/detail-biblio-search.pl +++ b/authorities/detail-biblio-search.pl @@ -39,6 +39,7 @@ parameters tables. use strict; +use warnings; use C4::AuthoritiesMarc; use C4::Auth; @@ -73,7 +74,6 @@ my ($template, $loggedinuser, $cookie) # fill arrays my @loop_data =(); -my $tag; # loop through each tab 0 through 9 # for (my $tabloop = 0; $tabloop<=10;$tabloop++) { # loop through each tag @@ -121,9 +121,8 @@ my @fields = $record->fields(); my $authtypes = getauthtypes; my @authtypesloop; foreach my $thisauthtype (keys %$authtypes) { - my $selected = 1 if $thisauthtype eq $authtypecode; my %row =(value => $thisauthtype, - selected => $selected, + selected => $thisauthtype eq $authtypecode, authtypetext => $authtypes->{$thisauthtype}{'authtypetext'}, ); push @authtypesloop, \%row; diff --git a/authorities/detail.pl b/authorities/detail.pl index 9096d1cb67..66f931cca0 100755 --- a/authorities/detail.pl +++ b/authorities/detail.pl @@ -39,6 +39,7 @@ parameters tables. use strict; +use warnings; use C4::AuthoritiesMarc; use C4::Auth; @@ -324,12 +325,11 @@ sub build_tabs ($$$$$) { foreach my $tag (sort @tab_data) { $i++; next if ! $tag; - my $indicator; my $index_tag = CreateKey; # if MARC::Record is not empty =>use it as master loop, then add missing subfields that should be in the tab. # if MARC::Record is empty => use tab as master loop. - if ( $record ne -1 && ( $record->field($tag) || $tag eq '000' ) ) { + if ( $record != -1 && ( $record->field($tag) || $tag eq '000' ) ) { my @fields; if ( $tag ne '000' ) { @fields = $record->field($tag); @@ -439,7 +439,6 @@ if (C4::Context->preference("AuthDisplayHierarchy")){ my $cnt=0; my @loophierarchy; foreach my $element (@tree){ - my $cell; my $elementdata = GetAuthority($element); $record= $elementdata if ($authid==$element); push @loophierarchy, BuildUnimarcHierarchy($elementdata,"child".$cnt, $authid); @@ -477,9 +476,8 @@ my $tag; my $authtypes = getauthtypes; my @authtypesloop; foreach my $thisauthtype (sort { $authtypes->{$b} cmp $authtypes->{$a} } keys %$authtypes) { - my $selected = 1 if $thisauthtype eq $authtypecode; my %row =(value => $thisauthtype, - selected => $selected, + selected => $thisauthtype eq $authtypecode, authtypetext => $authtypes->{$thisauthtype}{'authtypetext'}, ); push @authtypesloop, \%row; -- 2.39.5