@@ -, +, @@ --- C4/Context.pm | 16 ++++------------ Koha/Database.pm | 7 +++---- 2 files changed, 7 insertions(+), 16 deletions(-) --- a/C4/Context.pm +++ a/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 --- a/Koha/Database.pm +++ a/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}; } --