From c177ac05f604a6bea634785530c7f5aad7229184 Mon Sep 17 00:00:00 2001 From: Joe Atzberger Date: Fri, 19 Jun 2009 19:32:45 -0500 Subject: [PATCH] Cleanup Members.pm - minor MoveMemberToDeleted is problematic. It has a bad name, since it only copies, not moves. Also the POD for it referenced a totally different function name and was largely useless. Sanity checks inserted. A couple sth->finish removed. Signed-off-by: Galen Charlton --- C4/Members.pm | 27 +++++++++++---------------- 1 file changed, 11 insertions(+), 16 deletions(-) diff --git a/C4/Members.pm b/C4/Members.pm index 4f872485cc..5d9cc1f17a 100644 --- a/C4/Members.pm +++ b/C4/Members.pm @@ -1646,32 +1646,32 @@ sub GetSortDetails { return ($sortvalue) unless ($lib); } -=head2 DeleteBorrower +=head2 MoveMemberToDeleted - () = &DeleteBorrower($member); + $result = &MoveMemberToDeleted($borrowernumber); -delete all data fo borrowers and add record to deletedborrowers table -C<&$member>this is the borrowernumber +Copy the record from borrowers to deletedborrowers table. =cut +# FIXME: should do it in one SQL statement w/ subquery +# Otherwise, we should return the @data on success + sub MoveMemberToDeleted { - my ($member) = @_; + my ($member) = shift or return; my $dbh = C4::Context->dbh; - my $query; - $query = qq|SELECT * + my $query = qq|SELECT * FROM borrowers WHERE borrowernumber=?|; my $sth = $dbh->prepare($query); $sth->execute($member); my @data = $sth->fetchrow_array; - $sth->finish; + (@data) or return; # if we got a bad borrowernumber, there's nothing to insert $sth = $dbh->prepare( "INSERT INTO deletedborrowers VALUES (" . ( "?," x ( scalar(@data) - 1 ) ) . "?)" ); $sth->execute(@data); - $sth->finish; } =head2 DelMember @@ -1821,10 +1821,8 @@ sub GetPatronImage { my $sth = $dbh->prepare($query); $sth->execute($cardnumber); my $imagedata = $sth->fetchrow_hashref; - my $dberror = $sth->errstr; warn "Database error!" if $sth->errstr; - $sth->finish; - return $imagedata, $dberror; + return $imagedata, $sth->errstr; } =head2 PutPatronImage @@ -1844,9 +1842,7 @@ sub PutPatronImage { my $sth = $dbh->prepare($query); $sth->execute($cardnumber,$mimetype,$imgfile,$imgfile); warn "Error returned inserting $cardnumber.$mimetype." if $sth->errstr; - my $dberror = $sth->errstr; - $sth->finish; - return $dberror; + return $sth->errstr; } =head2 RmPatronImage @@ -1866,7 +1862,6 @@ sub RmPatronImage { $sth->execute($cardnumber); my $dberror = $sth->errstr; warn "Database error!" if $sth->errstr; - $sth->finish; return $dberror; } -- 2.39.5