Bugzilla – Attachment 42326 Details for
Bug 14778
DBIC should create/own the DB handler
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 14778: Get rid of DBIx::Connector
Bug-14778-Get-rid-of-DBIxConnector.patch (text/plain), 5.01 KB, created by
Jonathan Druart
on 2015-09-03 14:11:49 UTC
(
hide
)
Description:
Bug 14778: Get rid of DBIx::Connector
Filename:
MIME Type:
Creator:
Jonathan Druart
Created:
2015-09-03 14:11:49 UTC
Size:
5.01 KB
patch
obsolete
>From e5d19a9bfb5ab8ecacb245523a375384a9ff53bd Mon Sep 17 00:00:00 2001 >From: Jonathan Druart <jonathan.druart@bugs.koha-community.org> >Date: Thu, 3 Sep 2015 15:11:21 +0100 >Subject: [PATCH] Bug 14778: Get rid of DBIx::Connector > >--- > C4/Context.pm | 51 +--------------------------------------- > C4/Installer/PerlDependencies.pm | 5 ---- > Koha/Database.pm | 48 ++++++++++++++++++++++++++++++++++--- > 3 files changed, 46 insertions(+), 58 deletions(-) > >diff --git a/C4/Context.pm b/C4/Context.pm >index 26eeb40..bc95baf 100644 >--- a/C4/Context.pm >+++ b/C4/Context.pm >@@ -97,7 +97,6 @@ BEGIN { > $VERSION = '3.07.00.049'; > } > >-use DBIx::Connector; > use Encode; > use ZOOM; > use XML::Simple; >@@ -726,55 +725,7 @@ sub _new_Zconn { > sub _new_dbh > { > >- ## $context >- ## correct name for db_scheme >- my $db_driver = $context->{db_driver}; >- >- my $db_name = $context->config("database"); >- my $db_host = $context->config("hostname"); >- my $db_port = $context->config("port") || ''; >- my $db_user = $context->config("user"); >- my $db_passwd = $context->config("pass"); >- # MJR added or die here, as we can't work without dbh >- my $dbh = DBIx::Connector->connect( >- "dbi:$db_driver:dbname=$db_name;host=$db_host;port=$db_port", >- $db_user, $db_passwd, >- { >- 'RaiseError' => $ENV{DEBUG} ? 1 : 0 >- } >- ); >- >- # Check for the existence of a systempreference table; if we don't have this, we don't >- # have a valid database and should not set RaiseError in order to allow the installer >- # to run; installer will not run otherwise since we raise all db errors >- >- eval { >- local $dbh->{PrintError} = 0; >- local $dbh->{RaiseError} = 1; >- $dbh->do(qq{SELECT * FROM systempreferences WHERE 1 = 0 }); >- }; >- >- if ($@) { >- $dbh->{RaiseError} = 0; >- } >- >- if ( $db_driver eq 'mysql' ) { >- $dbh->{mysql_auto_reconnect} = 1; >- } >- >- my $tz = $ENV{TZ}; >- if ( $db_driver eq 'mysql' ) { >- # Koha 3.0 is utf-8, so force utf8 communication between mySQL and koha, whatever the mysql default config. >- # this is better than modifying my.cnf (and forcing all communications to be in utf8) >- $dbh->{'mysql_enable_utf8'}=1; #enable >- $dbh->do("set NAMES 'utf8'"); >- ($tz) and $dbh->do(qq(SET time_zone = "$tz")); >- } >- elsif ( $db_driver eq 'Pg' ) { >- $dbh->do( "set client_encoding = 'UTF8';" ); >- ($tz) and $dbh->do(qq(SET TIME ZONE = "$tz")); >- } >- return $dbh; >+ Koha::Database->schema->storage->dbh; > } > > =head2 dbh >diff --git a/C4/Installer/PerlDependencies.pm b/C4/Installer/PerlDependencies.pm >index dfe61b6..6953852 100644 >--- a/C4/Installer/PerlDependencies.pm >+++ b/C4/Installer/PerlDependencies.pm >@@ -64,11 +64,6 @@ our $PERL_DEPS = { > 'required' => '1', > 'min_ver' => '0.07039' > }, >- 'DBIx::Connector' => { >- 'usage' => 'Core', >- 'required' => '1', >- 'min_ver' => '0.47' >- }, > 'Net::Z3950::ZOOM' => { > 'usage' => 'Core', > 'required' => '1', >diff --git a/Koha/Database.pm b/Koha/Database.pm >index 5587570..1502364 100644 >--- a/Koha/Database.pm >+++ b/Koha/Database.pm >@@ -48,11 +48,53 @@ __PACKAGE__->mk_accessors(qw( )); > sub _new_schema { > > require Koha::Schema; >+ > my $context = C4::Context->new(); > >- # we are letting C4::Context->dbh not set the RaiseError handle attribute >- # for now for compatbility purposes >- my $schema = Koha::Schema->connect( sub { C4::Context->dbh }, { unsafe => 1 } ); >+ my $db_driver = $context->{db_driver}; >+ >+ my $db_name = $context->config("database"); >+ my $db_host = $context->config("hostname"); >+ my $db_port = $context->config("port") || ''; >+ my $db_user = $context->config("user"); >+ my $db_passwd = $context->config("pass"); >+ >+ my ( %encoding_attr, $encoding_query, $tz_query ); >+ my $tz = $ENV{TZ}; >+ if ( $db_driver eq 'mysql' ) { >+ %encoding_attr = ( mysql_enable_utf8 => 1 ); >+ $encoding_query = "set NAMES 'utf8'"; >+ $tz_query = qq(SET time_zone = "$tz") if $tz; >+ } >+ elsif ( $db_driver eq 'Pg' ) { >+ $encoding_query = "set client_encoding = 'UTF8';"; >+ $tz_query = qq(SET TIME ZONE = "$tz") if $tz; >+ } >+ my $schema = Koha::Schema->connect( >+ { >+ dsn => "dbi:$db_driver:database=$db_name;host=$db_host;port=$db_port", >+ user => $db_user, >+ password => $db_passwd, >+ %encoding_attr, >+ RaiseError => $ENV{DEBUG} ? 1 : 0, >+ unsafe => 1, >+ on_connect_do => [ >+ $encoding_query || (), >+ $tz_query || (), >+ ] >+ } >+ ); >+ >+ my $dbh = $schema->storage->dbh; >+ eval { >+ $dbh->{RaiseError} = 1; >+ $dbh->do(q| >+ SELECT * FROM systempreferences WHERE 1 = 0 | >+ ); >+ $dbh->{RaiseError} = $ENV{DEBUG} ? 1 : 0; >+ }; >+ $dbh->{RaiseError} = 0 if $@; >+ > return $schema; > } > >-- >2.1.0
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 14778
:
42326
|
42388
|
43247
|
43248
|
43249
|
43250
|
43440
|
43631
|
43632
|
43633
|
43634
|
43635
|
43636
|
43637
|
43638
|
43639
|
43640
|
43641
|
43642
|
43643
|
43644
|
43645
|
43834
|
43835
|
43836
|
43837
|
43838
|
43839
|
43840
|
43841
|
43842
|
43843
|
43844
|
43845
|
43846
|
43847
|
43848
|
43849
|
43850
|
43851
|
43852
|
43853
|
43857
|
43858
|
43859
|
43860
|
43861
|
43862
|
43863
|
43864
|
43865
|
43866
|
43867
|
43868
|
43869
|
43870
|
43871
|
43872
|
43873
|
43874
|
43875
|
43876
|
44003