From 306dc79217783ebd7896be64deee12491febc4d3 Mon Sep 17 00:00:00 2001 From: Colin Campbell Date: Mon, 29 Nov 2010 17:53:22 +0000 Subject: [PATCH] Bug 5453 : Move declarations out of conditionals Patched for C4 Modules Signed-off-by: Chris Cormack --- C4/Auth.pm | 15 ++++---- C4/Auth_with_ldap.pm | 5 +-- C4/Biblio.pm | 81 ++++++++++++++++++++++++++++++++++---------- C4/Budgets.pm | 5 ++- C4/Letters.pm | 24 +++++++------ C4/Members.pm | 8 +++-- C4/Record.pm | 17 +++++++--- 7 files changed, 110 insertions(+), 45 deletions(-) diff --git a/C4/Auth.pm b/C4/Auth.pm index b6ec69acd6..f580e53eee 100644 --- a/C4/Auth.pm +++ b/C4/Auth.pm @@ -137,12 +137,15 @@ sub get_template_and_user { my $in = shift; my $template = gettemplate( $in->{'template_name'}, $in->{'type'}, $in->{'query'} ); - my ( $user, $cookie, $sessionID, $flags ) = checkauth( - $in->{'query'}, - $in->{'authnotrequired'}, - $in->{'flagsrequired'}, - $in->{'type'} - ) unless ($in->{'template_name'}=~/maintenance/); + my ( $user, $cookie, $sessionID, $flags ); + if ( $in->{'template_name'} !~m/maintenance/ ) { + ( $user, $cookie, $sessionID, $flags ) = checkauth( + $in->{'query'}, + $in->{'authnotrequired'}, + $in->{'flagsrequired'}, + $in->{'type'} + ); + } my $borrowernumber; my $insecure = C4::Context->preference('insecure'); diff --git a/C4/Auth_with_ldap.pm b/C4/Auth_with_ldap.pm index 462ff07bd2..5baa07f049 100644 --- a/C4/Auth_with_ldap.pm +++ b/C4/Auth_with_ldap.pm @@ -171,8 +171,9 @@ sub checkpw_ldap { if (C4::Context->preference('ExtendedPatronAttributes') && $borrowernumber && ($config{update} ||$config{replicate})) { my @types = C4::Members::AttributeTypes::GetAttributeTypes(); my @attributes = grep{my $key=$_; any{$_ eq $key}@types;} keys %borrower; - my $extended_patron_attributes = map{{code=>$_,value=>$borrower{$_}}}@attributes; - my $extended_patron_attributes = [] unless $extended_patron_attributes; + my $extended_patron_attributes; + @{$extended_patron_attributes} = + map { { code => $_, value => $borrower{$_} } } @attributes; my @errors; #Check before add for (my $i; $i< scalar(@$extended_patron_attributes)-1;$i++) { diff --git a/C4/Biblio.pm b/C4/Biblio.pm index d797f40563..33908f9280 100644 --- a/C4/Biblio.pm +++ b/C4/Biblio.pm @@ -1513,7 +1513,10 @@ sub GetMarcSubjects { my $value = $subject_subfield->[1]; my $linkvalue = $value; $linkvalue =~ s/(\(|\))//g; - my $operator = " and " unless $counter == 0; + my $operator; + if ( $counter != 0 ) { + $operator = ' and '; + } if ( $code eq 9 ) { $found9 = 1; @link_loop = ( { 'limit' => 'an', link => "$linkvalue" } ); @@ -1521,7 +1524,10 @@ sub GetMarcSubjects { if ( not $found9 ) { push @link_loop, { 'limit' => $subject_limit, link => $linkvalue, operator => $operator }; } - my $separator = C4::Context->preference("authoritysep") unless $counter == 0; + my $separator; + if ( $counter != 0 ) { + $separator = C4::Context->preference('authoritysep'); + } # ignore $9 my @this_link_loop = @link_loop; @@ -1579,7 +1585,10 @@ sub GetMarcAuthors { my $value = $authors_subfield->[1]; my $linkvalue = $value; $linkvalue =~ s/(\(|\))//g; - my $operator = " and " unless $count_auth == 0; + my $operator; + if ( $count_auth != 0 ) { + $operator = ' and '; + } # if we have an authority link, use that as the link, otherwise use standard searching if ($subfield9) { @@ -1595,8 +1604,17 @@ sub GetMarcAuthors { $value = GetAuthorisedValueDesc( $field->tag(), $authors_subfield->[0], $authors_subfield->[1], '', $tagslib ) if ( $marcflavour eq 'UNIMARC' and ( $authors_subfield->[0] =~ /4/ ) ); my @this_link_loop = @link_loop; - my $separator = C4::Context->preference("authoritysep") unless $count_auth == 0; - push @subfields_loop, { code => $subfieldcode, value => $value, link_loop => \@this_link_loop, separator => $separator } unless ( $authors_subfield->[0] eq '9' ); + my $separator; + if ( $count_auth != 0 ) { + $separator = C4::Context->preference('authoritysep'); + } + push @subfields_loop, + { code => $subfieldcode, + value => $value, + link_loop => \@this_link_loop, + separator => $separator + } + unless ( $authors_subfield->[0] eq '9' ); $count_auth++; } push @marcauthors, { MARCAUTHOR_SUBFIELDS_LOOP => \@subfields_loop }; @@ -1707,13 +1725,27 @@ sub GetMarcSeries { my $value = $series_subfield->[1]; my $linkvalue = $value; $linkvalue =~ s/(\(|\))//g; - my $operator = " and " unless $counter == 0; - push @link_loop, { link => $linkvalue, operator => $operator }; - my $separator = C4::Context->preference("authoritysep") unless $counter == 0; + if ( $counter != 0 ) { + push @link_loop, { link => $linkvalue, operator => ' and ', }; + } else { + push @link_loop, { link => $linkvalue, operator => undef, }; + } + my $separator; + if ( $counter != 0 ) { + $separator = C4::Context->preference('authoritysep'); + } if ($volume_number) { push @subfields_loop, { volumenum => $value }; } else { - push @subfields_loop, { code => $code, value => $value, link_loop => \@link_loop, separator => $separator, volumenum => $volume_number } unless ( $series_subfield->[0] eq '9' ); + if ( $series_subfield->[0] ne '9' ) { + push @subfields_loop, { + code => $code, + value => $value, + link_loop => \@link_loop, + separator => $separator, + volumenum => $volume_number, + }; + } } $counter++; } @@ -2329,8 +2361,11 @@ sub PrepareItemrecordDisplay { my $tagslib = &GetMarcStructure( 1, $frameworkcode ); # return nothing if we don't have found an existing framework. - return "" unless $tagslib; - my $itemrecord = C4::Items::GetMarcItem( $bibnum, $itemnum ) if ($itemnum); + return q{} unless $tagslib; + my $itemrecord; + if ($itemnum) { + $itemrecord = C4::Items::GetMarcItem( $bibnum, $itemnum ); + } my @loop_data; my $authorised_values_sth = $dbh->prepare( "SELECT authorised_value,lib FROM authorised_values WHERE category=? ORDER BY lib" ); foreach my $tag ( sort keys %{$tagslib} ) { @@ -2369,15 +2404,20 @@ sub PrepareItemrecordDisplay { && C4::Context->preference('itemcallnumber') ) { my $CNtag = substr( C4::Context->preference('itemcallnumber'), 0, 3 ); my $CNsubfield = substr( C4::Context->preference('itemcallnumber'), 3, 1 ); - my $temp = $itemrecord->field($CNtag) if ($itemrecord); - if ($temp) { - $defaultvalue = $temp->subfield($CNsubfield); + if ($itemrecord) { + my $temp = $itemrecord->field($CNtag); + if ($temp) { + $defaultvalue = $temp->subfield($CNsubfield); + } } } if ( $tagslib->{$tag}->{$subfield}->{kohafield} eq 'items.itemcallnumber' && $defaultvalues && $defaultvalues->{'callnumber'} ) { - my $temp = $itemrecord->field($subfield) if ($itemrecord); + my $temp; + if ($itemrecord) { + $temp = $itemrecord->field($subfield); + } unless ($temp) { $defaultvalue = $defaultvalues->{'callnumber'} if $defaultvalues; } @@ -2385,7 +2425,10 @@ sub PrepareItemrecordDisplay { if ( ( $tagslib->{$tag}->{$subfield}->{kohafield} eq 'items.holdingbranch' || $tagslib->{$tag}->{$subfield}->{kohafield} eq 'items.homebranch' ) && $defaultvalues && $defaultvalues->{'branchcode'} ) { - my $temp = $itemrecord->field($subfield) if ($itemrecord); + my $temp; + if ($itemrecord) { + $temp = $itemrecord->field($subfield); + } unless ($temp) { $defaultvalue = $defaultvalues->{branchcode} if $defaultvalues; } @@ -2510,8 +2553,10 @@ sub PrepareItemrecordDisplay { } } } - my $itemnumber = $itemrecord->subfield( $itemtagfield, $itemtagsubfield ) - if ( $itemrecord && $itemrecord->field($itemtagfield) ); + my $itemnumber; + if ( $itemrecord && $itemrecord->field($itemtagfield) ) { + $itemnumber = $itemrecord->subfield( $itemtagfield, $itemtagsubfield ); + } return { 'itemtagfield' => $itemtagfield, 'itemtagsubfield' => $itemtagsubfield, diff --git a/C4/Budgets.pm b/C4/Budgets.pm index d2010d06a4..d516a12dc2 100644 --- a/C4/Budgets.pm +++ b/C4/Budgets.pm @@ -590,7 +590,10 @@ sub GetBudgetHierarchy { # add budget-percent and allocation, and flags for html-template foreach my $r (@sort) { my $subs_href = $r->{'child'}; - my @subs_arr = @$subs_href if defined $subs_href; + my @subs_arr = (); + if ( defined $subs_href ) { + @subs_arr = @{$subs_href}; + } my $moo = $r->{'budget_code_indent'}; $moo =~ s/\ /\ \;/g; diff --git a/C4/Letters.pm b/C4/Letters.pm index c894a57d62..cb47c7ec79 100644 --- a/C4/Letters.pm +++ b/C4/Letters.pm @@ -323,12 +323,14 @@ sub SendAlerts { $letter->{content} =~ s/<>/$userenv->{surname}/g; $letter->{content} =~ s/<>/$userenv->{emailaddress}/g; - foreach my $data (@$dataorders) { - my $line = $1 if ( $letter->{content} =~ m/(<<.*>>)/ ); - foreach my $field ( keys %$data ) { - $line =~ s/(<<[^\.]+.$field>>)/$data->{$field}/; + foreach my $data ( @{$dataorders} ) { + if ( $letter->{content} =~ m/(<<.*>>)/ ) { + my $line = $1; + foreach my $field ( keys %{$data} ) { + $line =~ s/(<<[^\.]+.$field>>)/$data->{$field}/; + } + $letter->{content} =~ s/(<<.*>>)/$line\n$1/; } - $letter->{content} =~ s/(<<.*>>)/$line\n$1/; } $letter->{content} =~ s/<<[^>]*>>//g; my $innerletter = $letter; @@ -391,12 +393,14 @@ sub SendAlerts { $letter->{content} =~ s/<>/$userenv->{surname}/g; $letter->{content} =~ s/<>/$userenv->{emailaddress}/g; - foreach my $data (@$dataorders) { - my $line = $1 if ( $letter->{content} =~ m/(<<.*>>)/ ); - foreach my $field ( keys %$data ) { - $line =~ s/(<<[^\.]+.$field>>)/$data->{$field}/; + foreach my $data ( @{$dataorders} ) { + if ( $letter->{content} =~ m/(<<.*>>)/ ) { + my $line = $1; + foreach my $field ( keys %{$data} ) { + $line =~ s/(<<[^\.]+.$field>>)/$data->{$field}/; + } + $letter->{content} =~ s/(<<.*>>)/$line\n$1/; } - $letter->{content} =~ s/(<<.*>>)/$line\n$1/; } $letter->{content} =~ s/<<[^>]*>>//g; my $innerletter = $letter; diff --git a/C4/Members.pm b/C4/Members.pm index 9049534fb3..670042f792 100644 --- a/C4/Members.pm +++ b/C4/Members.pm @@ -1177,9 +1177,11 @@ sub GetMemberAccountRecords { $sth->execute( @bind ); my $total = 0; while ( my $data = $sth->fetchrow_hashref ) { - my $biblio = GetBiblioFromItemNumber($data->{itemnumber}) if $data->{itemnumber}; - $data->{biblionumber} = $biblio->{biblionumber}; - $data->{title} = $biblio->{title}; + if ( $data->{itemnumber} ) { + my $biblio = GetBiblioFromItemNumber( $data->{itemnumber} ); + $data->{biblionumber} = $biblio->{biblionumber}; + $data->{title} = $biblio->{title}; + } $acctlines[$numlines] = $data; $numlines++; $total += int(1000 * $data->{'amountoutstanding'}); # convert float to integer to avoid round-off errors diff --git a/C4/Record.pm b/C4/Record.pm index c5727f3c03..cecb6ed266 100644 --- a/C4/Record.pm +++ b/C4/Record.pm @@ -266,12 +266,19 @@ sub marc2modsxml { sub marc2endnote { my ($marc) = @_; my $marc_rec_obj = MARC::Record->new_from_usmarc($marc); - my $f260 = $marc_rec_obj->field('260'); - my $f260a = $f260->subfield('a') if $f260; + my ( $abstract, $f260a, $f710a ); + my $f260 = $marc_rec_obj->field('260'); + if ($f260) { + $f260a = $f260->subfield('a') if $f260; + } my $f710 = $marc_rec_obj->field('710'); - my $f710a = $f710->subfield('a') if $f710; - my $f500 = $marc_rec_obj->field('500'); - my $abstract = $f500->subfield('a') if $f500; + if ($f710) { + $f710a = $f710->subfield('a'); + } + my $f500 = $marc_rec_obj->field('500'); + if ($f500) { + $abstract = $f500->subfield('a'); + } my $fields = { DB => C4::Context->preference("LibraryName"), Title => $marc_rec_obj->title(), -- 2.39.5