Bug 23830: Make Koha::AuthorisedValues use Koha::Objects::Limit::Library
[srvgit] / Koha / Database.pm
index 2d6110a..f000a78 100644 (file)
@@ -5,18 +5,18 @@ package Koha::Database;
 #
 # This file is part of Koha.
 #
-# Koha is free software; you can redistribute it and/or modify it under the
-# terms of the GNU General Public License as published by the Free Software
-# Foundation; either version 3 of the License, or (at your option) any later
-# version.
+# Koha is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
 #
-# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
-# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
-# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
+# Koha is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
 #
-# You should have received a copy of the GNU General Public License along
-# with Koha; if not, write to the Free Software Foundation, Inc.,
-# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+# You should have received a copy of the GNU General Public License
+# along with Koha; if not, see <http://www.gnu.org/licenses>.
 
 =head1 NAME
 
@@ -76,26 +76,36 @@ sub _new_schema {
         %encoding_attr = ( mysql_enable_utf8 => 1 );
         $encoding_query = "set NAMES 'utf8mb4'";
         $tz_query = qq(SET time_zone = "$tz") if $tz;
-        if ( ( $ENV{_} && $ENV{_} =~ m|prove| ) or C4::Context->config('strict_sql_modes') ) {
-            $sql_mode_query = q{SET sql_mode = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION'};
+        if (   C4::Context->config('strict_sql_modes')
+            || ( exists $ENV{_} && $ENV{_} =~ m|prove| )
+            || $ENV{KOHA_TESTING}
+        ) {
+            $sql_mode_query = q{SET sql_mode = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION'};
         } else {
-            $sql_mode_query = q{SET sql_mode = 'IGNORE_SPACE,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION'};
+            $sql_mode_query = q{SET sql_mode = 'IGNORE_SPACE,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION'};
         }
     }
     elsif ( $db_driver eq 'Pg' ) {
         $encoding_query = "set client_encoding = 'UTF8';";
         $tz_query = qq(SET TIME ZONE = "$tz") if $tz;
     }
+
+    my $RaiseError = (
+           $ENV{DEBUG}
+        || $ENV{KOHA_TESTING}
+        ||  exists $ENV{_} && $ENV{_} =~ m|prove|
+    ) ? 1 : 0;
     my $schema = Koha::Schema->connect(
         {
             dsn => "dbi:$db_driver:database=$db_name;host=$db_host;port=$db_port".($tls_options? $tls_options : ""),
             user => $db_user,
             password => $db_passwd,
             %encoding_attr,
-            RaiseError => $ENV{DEBUG} ? 1 : 0,
+            RaiseError => $RaiseError,
             PrintError => 1,
-            unsafe => 1,
+            unsafe => !$RaiseError,
             quote_names => 1,
+            auto_savepoint => 1,
             on_connect_do => [
                 $encoding_query || (),
                 $tz_query || (),
@@ -114,7 +124,7 @@ sub _new_schema {
         $dbh->do(q|
             SELECT * FROM systempreferences WHERE 1 = 0 |
         );
-        $dbh->{RaiseError} = $ENV{DEBUG} ? 1 : 0;
+        $dbh->{RaiseError} = $RaiseError
     };
     $dbh->{RaiseError} = 0 if $@;