Bug 14778: Make sure the dbh returned is checked by DBIC
authorJonathan Druart <jonathan.druart@bugs.koha-community.org>
Fri, 4 Sep 2015 11:23:44 +0000 (12:23 +0100)
committerTomas Cohen Arazi <tomascohen@theke.io>
Fri, 23 Oct 2015 15:01:17 +0000 (12:01 -0300)
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
C4/Context.pm
Koha/Database.pm

index bc95baf..e314f5a 100644 (file)
@@ -364,7 +364,6 @@ sub new {
     warn "read_config_file($conf_fname) returned undef" if !defined($self->{"config"});
     return if !defined($self->{"config"});
 
-    $self->{"dbh"} = undef;        # Database handle
     $self->{"Zconn"} = undef;    # Zebra Connections
     $self->{"stopwords"} = undef; # stopwords list
     $self->{"marcfromkohafield"} = undef; # the hash with relations between koha table fields and MARC field/subfield
@@ -725,7 +724,7 @@ sub _new_Zconn {
 sub _new_dbh
 {
 
-    Koha::Database->schema->storage->dbh;
+    Koha::Database->schema({ new => 1 })->storage->dbh;
 }
 
 =head2 dbh
@@ -751,17 +750,10 @@ sub dbh
     my $sth;
 
     unless ( $params->{new} ) {
-        if ( defined($context->{db_driver}) && $context->{db_driver} eq 'mysql' && $context->{"dbh"} ) {
-            return $context->{"dbh"};
-        } elsif ( defined($context->{"dbh"}) && $context->{"dbh"}->ping() ) {
-            return $context->{"dbh"};
-        }
+        return Koha::Database->schema->storage->dbh;
     }
 
-    # No database handle or it died . Create one.
-    $context->{"dbh"} = &_new_dbh();
-
-    return $context->{"dbh"};
+    return Koha::Database->schema({ new => 1 })->storage->dbh;
 }
 
 =head2 new_dbh
@@ -782,7 +774,7 @@ sub new_dbh
 {
     my $self = shift;
 
-    return &_new_dbh();
+    return &dbh({ new => 1 });
 }
 
 =head2 set_dbh
index 1502364..014554f 100644 (file)
@@ -115,13 +115,12 @@ possibly C<&set_schema>.
 
 sub schema {
     my $self = shift;
-    my $sth;
+    my $params = shift;
 
-    if ( defined( $database->{schema} ) and $database->{schema}->storage->connected() ) {
-        return $database->{schema};
+    unless ( $params->{new} ) {
+        return $database->{schema} if defined $database->{schema};
     }
 
-    # No database handle or it died . Create one.
     $database->{schema} = &_new_schema();
     return $database->{schema};
 }