Bug 13669: Re-adds error handling to load_sql
authorBernardo Gonzalez Kriegel <bgkriegel@gmail.com>
Fri, 20 May 2016 17:26:14 +0000 (14:26 -0300)
committerKyle M Hall <kyle@bywatersolutions.com>
Mon, 23 May 2016 16:47:32 +0000 (16:47 +0000)
This patch prevents crashing in case an
error is detected when loading a file

To test:
1) Apply patch
2) Mangle kohastructure.sql or any sample
file adding and invalid SQL line
3) Run webinstaller and check that the error
is handled gracefully

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
C4/Installer.pm

index 54587de..9ffc396 100644 (file)
@@ -428,18 +428,24 @@ with missing files, e.g.
 =cut
 
 sub load_sql {
-
     my $self = shift;
     my $filename = shift;
+    my $error;
 
     my $dbh = $self->{ dbh };
 
-    my $error = DBIx::RunSQL->run_sql_file(
-        dbh     => $dbh,
-        sql     => $filename,
-    );
-
-    $error = ( $error ) ? "ERROR: $filename" : "";
+    eval {
+        DBIx::RunSQL->run_sql_file(
+            dbh     => $dbh,
+            sql     => $filename,
+        );
+    };
+    #   errors thrown while loading installer data should be logged
+    if( $@ ) {
+        warn "C4::Installer::load_sql returned the following errors while attempting to load $filename:\n";
+        warn "$@";
+        $error = "Error attempting to load $filename:\n$@";
+    }
 
     return $error;
 }