Bug 13610 - delete_patrons.pl crashes on debian squeeze
Summary: delete_patrons.pl crashes on debian squeeze
Status: CLOSED FIXED
Alias: None
Product: Koha
Classification: Unclassified
Component: Architecture, internals, and plumbing (show other bugs)
Version: master
Hardware: All All
: P5 - low major (vote)
Assignee: Galen Charlton
QA Contact: Testopia
URL:
Keywords:
Depends on: 13084
Blocks:
  Show dependency treegraph
 
Reported: 2015-01-22 12:21 UTC by Jonathan Druart
Modified: 2016-06-21 21:36 UTC (History)
2 users (show)

See Also:
Change sponsored?: ---
Patch complexity: ---
Documentation contact:
Documentation submission:
Text to go in the release notes:
Version(s) released in:


Attachments
Simple script to reproduce the issue (837 bytes, application/x-perl)
2015-01-22 12:24 UTC, Jonathan Druart
Details
Even more simplistic script (589 bytes, application/x-perl)
2015-01-22 12:54 UTC, Jonathan Druart
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Jonathan Druart 2015-01-22 12:21:35 UTC
$ perl misc/cronjobs/delete_patrons.pl -c
Failed to delete patron 42, error handling its lists: (DBD::mysql::db do failed: MySQL server has gone away at /home/koha/src/C4/VirtualShelves.pm line 651.
)

$ perl -v
This is perl, v5.10.1 (*) built for x86_64-linux-gnu-thread-multi

$ more /etc/debian_version
6.0.10
Comment 1 Jonathan Druart 2015-01-22 12:24:01 UTC
Created attachment 35458 [details]
Simple script to reproduce the issue

koha@test1-sandbox:~/src$ perl mysql_has_gone_away.pl 
Failed to delete patron 999999999999, error handling its lists: (DBD::mysql::db do failed: MySQL server has gone away at /home/koha/src/C4/VirtualShelves.pm line 651.
) ROLLBACK
DBD::mysql::db rollback failed: MySQL server has gone away at mysql_has_gone_away.pl line 33.
Comment 2 Jonathan Druart 2015-01-22 12:25:37 UTC
$ git show  b95617ec9eb62d3b4b9b2b97848b3efd7d207fb6
commit b95617ec9eb62d3b4b9b2b97848b3efd7d207fb6
Author: Kyle M Hall <kyle@bywatersolutions.com>
Date:   Fri Oct 17 07:52:13 2014 -0400

    Bug 13084 [Master] - QA Followup - Use DBIx::Class to simplify logic
    
    Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
    Signed-off-by: Tomas Cohen Arazi <tomascohen@gmail.com>

diff --git a/C4/Members.pm b/C4/Members.pm
index da8dfaf..0978078 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


$ git revert b95617ec9eb62d3b4b9b2b97848b3efd7d207fb6

$ perl mysql_has_gone_away.pl 
No error!
Comment 3 Jonathan Druart 2015-01-22 12:54:37 UTC
Created attachment 35459 [details]
Even more simplistic script
Comment 4 Jonathan Druart 2015-01-28 14:49:24 UTC
Tomas, I think this is quite problematic since Koha is supposed to run on squeeze.
Comment 5 Jonathan Druart 2015-02-02 16:14:57 UTC
The patch on bug 12472 fixes the problem (at least for the script I submitted).
Comment 6 Katrin Fischer 2015-05-14 20:04:22 UTC
Can this be closed?
Comment 7 Jonathan Druart 2015-05-26 08:22:29 UTC
Looks good yes.