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>
=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;
}