View | Details | Raw Unified | Return to bug 14778
Collapse All | Expand All

(-)a/C4/Context.pm (-50 / +1 lines)
Lines 97-103 BEGIN { Link Here
97
    $VERSION = '3.07.00.049';
97
    $VERSION = '3.07.00.049';
98
}
98
}
99
99
100
use DBIx::Connector;
101
use Encode;
100
use Encode;
102
use ZOOM;
101
use ZOOM;
103
use XML::Simple;
102
use XML::Simple;
Lines 726-780 sub _new_Zconn { Link Here
726
sub _new_dbh
725
sub _new_dbh
727
{
726
{
728
727
729
    ## $context
728
    Koha::Database->schema->storage->dbh;
730
    ## correct name for db_scheme
731
    my $db_driver = $context->{db_driver};
732
733
    my $db_name   = $context->config("database");
734
    my $db_host   = $context->config("hostname");
735
    my $db_port   = $context->config("port") || '';
736
    my $db_user   = $context->config("user");
737
    my $db_passwd = $context->config("pass");
738
    # MJR added or die here, as we can't work without dbh
739
    my $dbh = DBIx::Connector->connect(
740
        "dbi:$db_driver:dbname=$db_name;host=$db_host;port=$db_port",
741
        $db_user, $db_passwd,
742
        {
743
            'RaiseError' => $ENV{DEBUG} ? 1 : 0
744
        }
745
    );
746
747
    # Check for the existence of a systempreference table; if we don't have this, we don't
748
    # have a valid database and should not set RaiseError in order to allow the installer
749
    # to run; installer will not run otherwise since we raise all db errors
750
751
    eval {
752
                local $dbh->{PrintError} = 0;
753
                local $dbh->{RaiseError} = 1;
754
                $dbh->do(qq{SELECT * FROM systempreferences WHERE 1 = 0 });
755
    };
756
757
    if ($@) {
758
        $dbh->{RaiseError} = 0;
759
    }
760
761
    if ( $db_driver eq 'mysql' ) {
762
        $dbh->{mysql_auto_reconnect} = 1;
763
    }
764
765
	my $tz = $ENV{TZ};
766
    if ( $db_driver eq 'mysql' ) { 
767
        # Koha 3.0 is utf-8, so force utf8 communication between mySQL and koha, whatever the mysql default config.
768
        # this is better than modifying my.cnf (and forcing all communications to be in utf8)
769
        $dbh->{'mysql_enable_utf8'}=1; #enable
770
        $dbh->do("set NAMES 'utf8'");
771
        ($tz) and $dbh->do(qq(SET time_zone = "$tz"));
772
    }
773
    elsif ( $db_driver eq 'Pg' ) {
774
	    $dbh->do( "set client_encoding = 'UTF8';" );
775
        ($tz) and $dbh->do(qq(SET TIME ZONE = "$tz"));
776
    }
777
    return $dbh;
778
}
729
}
779
730
780
=head2 dbh
731
=head2 dbh
(-)a/C4/Installer/PerlDependencies.pm (-5 lines)
Lines 64-74 our $PERL_DEPS = { Link Here
64
        'required' => '1',
64
        'required' => '1',
65
        'min_ver'  => '0.07039'
65
        'min_ver'  => '0.07039'
66
    },
66
    },
67
    'DBIx::Connector' => {
68
        'usage'    => 'Core',
69
        'required' => '1',
70
        'min_ver'  => '0.47'
71
    },
72
    'Net::Z3950::ZOOM' => {
67
    'Net::Z3950::ZOOM' => {
73
        'usage'    => 'Core',
68
        'usage'    => 'Core',
74
        'required' => '1',
69
        'required' => '1',
(-)a/Koha/Database.pm (-4 / +45 lines)
Lines 48-58 __PACKAGE__->mk_accessors(qw( )); Link Here
48
sub _new_schema {
48
sub _new_schema {
49
49
50
    require Koha::Schema;
50
    require Koha::Schema;
51
51
    my $context = C4::Context->new();
52
    my $context = C4::Context->new();
52
53
53
    # we are letting C4::Context->dbh not set the RaiseError handle attribute
54
    my $db_driver = $context->{db_driver};
54
    # for now for compatbility purposes
55
55
    my $schema = Koha::Schema->connect( sub { C4::Context->dbh }, { unsafe => 1 } );
56
    my $db_name   = $context->config("database");
57
    my $db_host   = $context->config("hostname");
58
    my $db_port   = $context->config("port") || '';
59
    my $db_user   = $context->config("user");
60
    my $db_passwd = $context->config("pass");
61
62
    my ( %encoding_attr, $encoding_query, $tz_query );
63
    my $tz = $ENV{TZ};
64
    if ( $db_driver eq 'mysql' ) {
65
        %encoding_attr = ( mysql_enable_utf8 => 1 );
66
        $encoding_query = "set NAMES 'utf8'";
67
        $tz_query = qq(SET time_zone = "$tz") if $tz;
68
    }
69
    elsif ( $db_driver eq 'Pg' ) {
70
        $encoding_query = "set client_encoding = 'UTF8';";
71
        $tz_query = qq(SET TIME ZONE = "$tz") if $tz;
72
    }
73
    my $schema = Koha::Schema->connect(
74
        {
75
            dsn => "dbi:$db_driver:database=$db_name;host=$db_host;port=$db_port",
76
            user => $db_user,
77
            password => $db_passwd,
78
            %encoding_attr,
79
            RaiseError => $ENV{DEBUG} ? 1 : 0,
80
            unsafe => 1,
81
            on_connect_do => [
82
                $encoding_query || (),
83
                $tz_query || (),
84
            ]
85
        }
86
    );
87
88
    my $dbh = $schema->storage->dbh;
89
    eval {
90
        $dbh->{RaiseError} = 1;
91
        $dbh->do(q|
92
            SELECT * FROM systempreferences WHERE 1 = 0 |
93
        );
94
        $dbh->{RaiseError} = $ENV{DEBUG} ? 1 : 0;
95
    };
96
    $dbh->{RaiseError} = 0 if $@;
97
56
    return $schema;
98
    return $schema;
57
}
99
}
58
100
59
- 

Return to bug 14778