Bug 22544: Clarify documentation and change param 'type' to 'location'
[koha-ffzg.git] / Koha / Database.pm
index f460618..df4d45c 100644 (file)
@@ -49,21 +49,19 @@ sub _new_schema {
 
     require Koha::Schema;
 
-    my $context = C4::Context->new();
-
-    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 $tls = $context->config("tls");
+    my $db_driver = C4::Context::db_scheme2dbi(C4::Context->config('db_scheme'));;
+
+    my $db_name   = C4::Context->config("database");
+    my $db_host   = C4::Context->config("hostname");
+    my $db_port   = C4::Context->config("port") || '';
+    my $db_user   = C4::Context->config("user");
+    my $db_passwd = C4::Context->config("pass");
+    my $tls = C4::Context->config("tls");
     my $tls_options;
     if( $tls && $tls eq 'yes' ) {
-        my $ca = $context->config('ca');
-        my $cert = $context->config('cert');
-        my $key = $context->config('key');
+        my $ca = C4::Context->config('ca');
+        my $cert = C4::Context->config('cert');
+        my $key = C4::Context->config('key');
         $tls_options = ";mysql_ssl=1;mysql_ssl_client_key=".$key.";mysql_ssl_client_cert=".$cert.";mysql_ssl_ca_file=".$ca;
     }
 
@@ -110,17 +108,19 @@ sub _new_schema {
 
     my $dbh = $schema->storage->dbh;
     eval {
+        my $HandleError = $dbh->{HandleError};
         if ( $ENV{KOHA_DB_DO_NOT_RAISE_OR_PRINT_ERROR} ) {
-            $dbh->{RaiseError} = 0;
-            $dbh->{PrintError} = 0;
+            $dbh->{HandleError} = sub { return 1 };
         }
         $dbh->do(q|
             SELECT * FROM systempreferences WHERE 1 = 0 |
         );
-        $dbh->{RaiseError} = 1;
-        $dbh->{PrintError} = 1;
+        $dbh->{HandleError} = $HandleError;
     };
-    $dbh->{RaiseError} = 0 if $@;
+
+    if ( $@ ) {
+        $dbh->{HandleError} = sub { warn $_[0]; return 1 };
+    }
 
     return $schema;
 }