From 83fee24dbcb03769649ed8afdab2d7a9d1e2a8a2 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Wed, 4 Mar 2015 11:51:56 +0100 Subject: [PATCH] Bug 13793: Make the installer output the result of the updates under Plack Test plan: 0/ Start plack for intranet 1/ Create a new entry in updatedatabase.pl, something like: $DBversion = "3.19.00.013"; if(CheckVersion($DBversion)) { print "Upgrade to $DBversion done (Bug test plack - This is a est)\n"; print "Upgrade to $DBversion done (Bug test plack - This is anoter est)\n"; print "Upgrade to $DBversion done (Bug test plack - This is a third est)\n"; warn "this is an error"; } and modify the kohaversion.pl accordingly. You can also warn something to simulate an error. 2/ Go on the mainpage (or wherever you want), you should be redirected to the installer 3/ Notice that the output of the updatedatabase is displayed on the screen. 4/ Confirm that new files have been created in your Koha log directory (check the logdir entry in your koha conf file). 5/ Confirm that the output is still displayed without Plack. Signed-off-by: Dobrica Pavlinusic Signed-off-by: Brendan Gallagher Signed-off-by: Brendan Gallagher Signed-off-by: Tomas Cohen Arazi --- installer/install.pl | 37 ++++++++++++++++++++++++++----------- 1 file changed, 26 insertions(+), 11 deletions(-) diff --git a/installer/install.pl b/installer/install.pl index 4420fde4ab..46f3e3ad46 100755 --- a/installer/install.pl +++ b/installer/install.pl @@ -6,7 +6,7 @@ use diagnostics; use C4::InstallAuth; use CGI qw ( -utf8 ); -use IPC::Cmd; +use POSIX qw(strftime); use C4::Context; use C4::Output; @@ -320,20 +320,35 @@ elsif ( $step && $step == 3 ) { warn "# plack? inserted PERL5LIB $ENV{PERL5LIB}\n"; } - my $cmd = C4::Context->config("intranetdir") . "/installer/data/$info{dbms}/updatedatabase.pl"; - my ($success, $error_code, $full_buf, $stdout_buf, $stderr_buf) = IPC::Cmd::run(command => $cmd, verbose => 0); + my $now = POSIX::strftime( "%Y-%m-%dT%H:%M:%S", localtime() ); + my $logdir = C4::Context->config('logdir'); + my ( $logfilepath, $logfilepath_errors ) = ( $logdir . "/updatedatabase_$now.log", $logdir . "/updatedatabase-error_$now.log" ); - if (@$stdout_buf) { - $template->param(update_report => [ map { { line => $_ } } split(/\n/, join('', @$stdout_buf)) ] ); - $template->param(has_update_succeeds => 1); + my $cmd = C4::Context->config("intranetdir") . "/installer/data/$info{dbms}/updatedatabase.pl > $logfilepath 2> $logfilepath_errors"; + + system($cmd ); + + my $fh; + open( $fh, "<", $logfilepath ) or die "Cannot open log file $logfilepath: $!"; + my @report = <$fh>; + close $fh; + if (@report) { + $template->param( update_report => [ map { { line => $_ } } split( /\n/, join( '', @report ) ) ] ); + $template->param( has_update_succeeds => 1 ); + } else { + eval{ `rm $logfilepath` }; } - if (@$stderr_buf) { - $template->param(update_errors => [ map { { line => $_ } } split(/\n/, join('', @$stderr_buf)) ] ); - $template->param(has_update_errors => 1); + open( $fh, "<", $logfilepath_errors ) or die "Cannot open log file $logfilepath_errors: $!"; + @report = <$fh>; + close $fh; + if (@report) { + $template->param( update_errors => [ map { { line => $_ } } split( /\n/, join( '', @report ) ) ] ); + $template->param( has_update_errors => 1 ); warn "The following errors were returned while attempting to run the updatedatabase.pl script:\n"; - foreach my $line (@$stderr_buf) {warn "$line\n";} + foreach my $line (@report) { warn "$line\n"; } + } else { + eval{ `rm $logfilepath_errors` }; } - $template->param( $op => 1 ); } else { -- 2.39.5