[Koha-patches] [PATCH] fixes print statements with missing 'STDERR', causing 500 errors when debugging

Mason James mason.loves.sushi at gmail.com
Sun Mar 8 12:58:13 CET 2009


while i was at it, i replaced the 'print STDERR' calls with warns, as it's a little cleaner (imho)
---
 C4/Auth_with_ldap.pm |   28 ++++++++++++++--------------
 1 files changed, 14 insertions(+), 14 deletions(-)

diff --git a/C4/Auth_with_ldap.pm b/C4/Auth_with_ldap.pm
index c286275..0b7c1bd 100644
--- a/C4/Auth_with_ldap.pm
+++ b/C4/Auth_with_ldap.pm
@@ -44,7 +44,7 @@ BEGIN {
 # ~ and calls the memberadd if necessary
 
 sub ldapserver_error ($) {
-	return sprintf('No ldapserver "%s" defined in KOHA_CONF: ' . $ENV{KOHA_CONF}, shift);
+	return warn sprintf('No ldapserver "%s" defined in KOHA_CONF: ' . $ENV{KOHA_CONF}, shift);
 }
 
 use vars qw($mapping @ldaphosts $base $ldapname $ldappassword);
@@ -56,9 +56,9 @@ $ldapname     = $ldap->{user}		;
 $ldappassword = $ldap->{pass}		;
 our %mapping  = %{$ldap->{mapping}}	or die ldapserver_error('mapping');
 my @mapkeys = keys %mapping;
-$debug and print STDERR "Got ", scalar(@mapkeys), " ldap mapkeys (  total  ): ", join ' ', @mapkeys, "\n";
+$debug and warn "Got ", scalar(@mapkeys), " ldap mapkeys (  total  ): ", join ' ', @mapkeys, "\n";
 @mapkeys = grep {defined $mapping{$_}->{is}} @mapkeys;
-$debug and print STDERR "Got ", scalar(@mapkeys), " ldap mapkeys (populated): ", join ' ', @mapkeys, "\n";
+$debug and warn "Got ", scalar(@mapkeys), " ldap mapkeys (populated): ", join ' ', @mapkeys, "\n";
 
 my %config = (
 	anonymous => ($ldapname and $ldappassword) ? 0 : 1,
@@ -109,7 +109,7 @@ sub checkpw_ldap {
 		return 1;
 	}
 	my %borrower = ldap_entry_2_hash($userldapentry,$userid);
-	$debug and print "checkpw_ldap received \%borrower w/ " . keys(%borrower), " keys: ", join(' ', keys %borrower), "\n";
+	$debug and warn "checkpw_ldap received \%borrower w/ " . keys(%borrower), " keys: ", join(' ', keys %borrower), "\n";
 	my ($borrowernumber,$cardnumber,$savedpw);
 	($borrowernumber,$cardnumber,$userid,$savedpw) = exists_local($userid);
 	if ($borrowernumber) {
@@ -132,9 +132,9 @@ sub ldap_entry_2_hash ($$) {
 	my %memberhash;
 	$userldapentry->exists('uid');	# This is bad, but required!  By side-effect, this initializes the attrs hash. 
 	if ($debug) {
-		print "\nkeys(\%\$userldapentry) = " . join(', ', keys %$userldapentry), "\n", $userldapentry->dump();
+		warn "\nkeys(\%\$userldapentry) = " . join(', ', keys %$userldapentry), "\n", $userldapentry->dump();
 		foreach (keys %$userldapentry) {
-			print "\n\nLDAP key: $_\t", sprintf('(%s)', ref $userldapentry->{$_}), "\n";
+			warn "\n\nLDAP key: $_\t", sprintf('(%s)', ref $userldapentry->{$_}), "\n";
 			hashdump("LDAP key: ",$userldapentry->{$_});
 		}
 	}
@@ -142,13 +142,13 @@ sub ldap_entry_2_hash ($$) {
 	my $key;
 	foreach (keys %$x) {
 		$memberhash{$_} = join ' ', @{$x->{$_}};	
-		$debug and print sprintf("building \$memberhash{%s} = ", $_, join(' ', @{$x->{$_}})), "\n";
+		$debug and warn sprintf("building \$memberhash{%s} = ", $_, join(' ', @{$x->{$_}})), "\n";
 	}
-	$debug and print "Finsihed \%memberhash has ", scalar(keys %memberhash), " keys\n",
+	$debug and warn "Finsihed \%memberhash has ", scalar(keys %memberhash), " keys\n",
 					"Referencing \%mapping with ", scalar(keys %mapping), " keys\n";
 	foreach my $key (keys %mapping) {
 		my  $data = $memberhash{$mapping{$key}->{is}}; 
-		$debug and printf "mapping %20s ==> %-20s (%s)\n", $key, $mapping{$key}->{is}, $data;
+		$debug and warn printf "mapping %20s ==> %-20s (%s)\n", $key, $mapping{$key}->{is}, $data;
 		unless (defined $data) { 
 			$data = $mapping{$key}->{content} || '';	# default or failsafe ''
 		}
@@ -168,12 +168,12 @@ sub exists_local($) {
 
 	my $sth = $dbh->prepare("$select WHERE userid=?");	# was cardnumber=?
 	$sth->execute($arg);
-	$debug and printf "Userid '$arg' exists_local? %s\n", $sth->rows;
+	$debug and warn printf "Userid '$arg' exists_local? %s\n", $sth->rows;
 	($sth->rows == 1) and return $sth->fetchrow;
 
 	$sth = $dbh->prepare("$select WHERE cardnumber=?");
 	$sth->execute($arg);
-	$debug and printf "Cardnumber '$arg' exists_local? %s\n", $sth->rows;
+	$debug and warn printf "Cardnumber '$arg' exists_local? %s\n", $sth->rows;
 	($sth->rows == 1) and return $sth->fetchrow;
 	return 0;
 }
@@ -190,9 +190,9 @@ sub update_local($$$$) {
 		"\nWHERE   borrowernumber=? "; 
 	my $sth = $dbh->prepare($query);
 	if ($debug) {
-		print STDERR $query, "\n",
+		warn $query, "\n",
 			join "\n", map {"$_ = '" . $borrower->{$_} . "'"} @keys;
-		print STDERR "\nuserid = $userid\n";
+		warn "\nuserid = $userid\n";
 	}
 	$sth->execute(
 		((map {$borrower->{$_}} @keys), $borrowerid)
@@ -200,7 +200,7 @@ sub update_local($$$$) {
 
 	# MODIFY PASSWORD/LOGIN
 	# search borrowerid
-	$debug and print "changing local password for borrowernumber=$borrowerid to '$digest'\n";
+	$debug and warn "changing local password for borrowernumber=$borrowerid to '$digest'\n";
 	changepassword($userid, $borrowerid, $digest);
 
 	# Confirm changes
-- 
1.5.6.5




More information about the Koha-patches mailing list