From b95617ec9eb62d3b4b9b2b97848b3efd7d207fb6 Mon Sep 17 00:00:00 2001 From: Kyle M Hall Date: Fri, 17 Oct 2014 07:52:13 -0400 Subject: [PATCH] Bug 13084 [Master] - QA Followup - Use DBIx::Class to simplify logic Signed-off-by: Kyle M Hall Signed-off-by: Tomas Cohen Arazi --- C4/Members.pm | 32 ++++++++++---------------------- 1 file changed, 10 insertions(+), 22 deletions(-) diff --git a/C4/Members.pm b/C4/Members.pm index da8dfafc95..09780781f4 100644 --- a/C4/Members.pm +++ b/C4/Members.pm @@ -1814,28 +1814,16 @@ The routine returns 1 for success, undef for failure. sub MoveMemberToDeleted { my ($member) = shift or return; - my $dbh = C4::Context->dbh; - my $query = qq|SELECT * - FROM borrowers - WHERE borrowernumber=?|; - my $sth = $dbh->prepare($query); - $sth->execute($member); - my $data = $sth->fetchrow_hashref; - return if !$data; # probably bad borrowernumber - - #now construct a insert query that does not depend on the same order of - #columns in borrowers and deletedborrowers (see BZ 13084) - my $insertq = "INSERT INTO deletedborrowers ("; - my @values; - foreach my $key ( keys %$data ) { - $insertq.= $key.","; - push @values, $data->{$key}; - } - $insertq =~ s/,$//; #remove last comma - $insertq .= ") VALUES (" . ( "?," x ( scalar(@values) - 1 ) ) . "?)"; - $sth = $dbh->prepare( $insertq ); - $sth->execute(@values); - return $sth->err? undef: 1; + + my $schema = Koha::Database->new()->schema(); + my $borrowers_rs = $schema->resultset('Borrower'); + $borrowers_rs->result_class('DBIx::Class::ResultClass::HashRefInflator'); + my $borrower = $borrowers_rs->find($member); + return unless $borrower; + + my $deleted = $schema->resultset('Deletedborrower')->create($borrower); + + return $deleted ? 1 : undef; } =head2 DelMember -- 2.39.5