From 74aea8e36c95e5ac5d2f88287802b1c691bd69cb Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Mon, 30 Sep 2013 13:40:32 +0200 Subject: [PATCH] [SIGNED-OFF] Bug 10611: add a "new" parameter to C4::Context->dbh When dbh->disconnect is called and the mysql_auto_reconnect flag is set, the dbh is not recreated: the old one is used. Adding a new flag, we can now force the C4::Context->dbh method to return a new dbh. Signed-off-by: Bernardo Gonzalez Kriegel --- C4/Context.pm | 11 +++++++---- t/db_dependent/Context.t | 5 +---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/C4/Context.pm b/C4/Context.pm index 874a9ae..becab7d 100644 --- a/C4/Context.pm +++ b/C4/Context.pm @@ -860,12 +860,15 @@ possibly C<&set_dbh>. sub dbh { my $self = shift; + my $params = shift; my $sth; - if ( defined $db_driver && $db_driver eq 'mysql' && $context->{"dbh"} ) { - return $context->{"dbh"}; - } elsif ( defined $db_driver && defined($context->{"dbh"}) && $context->{"dbh"}->ping()) { - return $context->{"dbh"}; + unless ( $params->{new} ) { + if ( defined $db_driver && $db_driver eq 'mysql' && $context->{"dbh"} ) { + return $context->{"dbh"}; + } elsif ( defined $db_driver && defined($context->{"dbh"}) && $context->{"dbh"}->ping()) { + return $context->{"dbh"}; + } } # No database handle or it died . Create one. diff --git a/t/db_dependent/Context.t b/t/db_dependent/Context.t index 32ea441..54aefda 100755 --- a/t/db_dependent/Context.t +++ b/t/db_dependent/Context.t @@ -50,9 +50,6 @@ ok($config = $koha->{config}, 'Getting $koha->{config} '); diag "Testing syspref caching."; -my $dbh = C4::Context->dbh; -$dbh->disconnect; - my $module = new Test::MockModule('C4::Context'); $module->mock( '_new_dbh', @@ -64,7 +61,7 @@ $module->mock( ); my $history; -$dbh = C4::Context->dbh; +$dbh = C4::Context->dbh({ new => 1 }); $dbh->{mock_add_resultset} = [ ['value'], ['thing1'] ]; $dbh->{mock_add_resultset} = [ ['value'], ['thing2'] ]; -- 1.7.9.5