Bug 13669: Re-adds error handling to load_sql

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>
(cherry picked from commit 080f5a6b8e)
Signed-off-by: Julian Maurice <julian.maurice@biblibre.com>
This commit is contained in:
Bernardo Gonzalez Kriegel 2016-05-20 14:26:14 -03:00 committed by Julian Maurice
parent e8a703b076
commit b5035de9d6
1 changed files with 13 additions and 7 deletions

View File

@ -429,18 +429,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;
}