From 1864c034884be92abce2be5fc6186d78359b53b6 Mon Sep 17 00:00:00 2001 From: Kyle M Hall Date: Tue, 7 Jun 2016 14:07:19 +0000 Subject: [PATCH] Bug 16685 - Use eval instead of do for .perl atomicupdates If we use eval instead of do for our .perl atomic update files, it will allow developers to put in the exact code that should go into updatedatabase.pl. The problem with do is that none of the variables defined in updatadatabase.pl are available, whereas with eval they are. Test Plan: 1) Apply this patch 2) Create a .perl file in atomicupdates with the following in it: say "DBversion: $DBversion"; 3) Run updatadatabase.pl 4) Note the output 5) Add a syntax error to your atomic update 6) Run updatedatabase.pl 7) Note the error is displayed --- installer/data/mysql/updatedatabase.pl | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/installer/data/mysql/updatedatabase.pl b/installer/data/mysql/updatedatabase.pl index ab20870..72f5254 100755 --- a/installer/data/mysql/updatedatabase.pl +++ b/installer/data/mysql/updatedatabase.pl @@ -30,6 +30,8 @@ use strict; use warnings; +use feature 'say'; + # CPAN modules use DBI; use Getopt::Long; @@ -45,6 +47,7 @@ use MARC::File::XML ( BinaryEncoding => 'utf8' ); use File::Path qw[remove_tree]; # perl core module use File::Spec; +use File::Slurp; # FIXME - The user might be installing a new database, so can't rely # on /etc/koha.conf anyway. @@ -12697,7 +12700,9 @@ foreach my $file ( sort readdir $dirh ) { my $installer = C4::Installer->new(); my $rv = $installer->load_sql( $update_dir . $file ) ? 0 : 1; } elsif ( $file =~ /\.perl$/ ) { - do $update_dir . $file; + my $code = read_file( $update_dir . $file ); + eval $code; + say "Atomic update generated errors: $@" if $@; } } -- 2.1.4