From aa178bcf6a31cc4335fe417c89d85bc94f279667 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Thu, 3 Dec 2020 10:46:31 +0100 Subject: [PATCH] Bug 25026: Use HandleError to not raise or print error DBIC has its own HandleError, and so it does not work to unset RaiseError or PrintError if unsafe is not set (what we don't want here). The idea of this patch is to overwrite the HandleError when we need it: Either if KOHA_DB_DO_NOT_RAISE_OR_PRINT_ERROR is set (misc4dev) Or if the installer is triggered (we don't want to explode if the DB does not exist). There is an additional trick, when the installer is completed, we want to restore the original behaviour, and so a disconnect is made. Note that during the installer we want to display eventual SQL errors, that's why we still display the errors. Signed-off-by: Martin Renvoize Signed-off-by: Jonathan Druart --- Koha/Database.pm | 12 +++++++----- installer/install.pl | 5 +++-- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/Koha/Database.pm b/Koha/Database.pm index f460618b68..0f398c7022 100644 --- a/Koha/Database.pm +++ b/Koha/Database.pm @@ -110,17 +110,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; } diff --git a/installer/install.pl b/installer/install.pl index 7aab43f89c..be6ee27f8c 100755 --- a/installer/install.pl +++ b/installer/install.pl @@ -220,9 +220,10 @@ elsif ( $step && $step == 3 ) { my $op = $query->param('op'); if ( $op && $op eq 'finished' ) { - # + # Remove the HandleError set at the beginning of the installer process + C4::Context->dbh->disconnect; + # we have finished, just redirect to mainpage. - # print $query->redirect("/cgi-bin/koha/mainpage.pl"); exit; } -- 2.39.5