From 389ef2c6c79ce29d8834cea0fd62c93070f4a6dc Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Fri, 4 Sep 2015 12:23:44 +0100 Subject: [PATCH] Bug 14778: Make sure the dbh returned is checked by DBIC Signed-off-by: Martin Renvoize Signed-off-by: Kyle M Hall Signed-off-by: Tomas Cohen Arazi --- C4/Context.pm | 16 ++++------------ Koha/Database.pm | 7 +++---- 2 files changed, 7 insertions(+), 16 deletions(-) diff --git a/C4/Context.pm b/C4/Context.pm index bc95baf2d4..e314f5a01b 100644 --- a/C4/Context.pm +++ b/C4/Context.pm @@ -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 diff --git a/Koha/Database.pm b/Koha/Database.pm index 15023643b9..014554ff3d 100644 --- a/Koha/Database.pm +++ b/Koha/Database.pm @@ -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}; } -- 2.39.5