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 <dpavlin@rot13.org>

Signed-off-by: Brendan Gallagher <brendan@bywatersolutions.com>

Signed-off-by: Brendan Gallagher <brendan@bywatersolutions.com>
Signed-off-by: Tomas Cohen Arazi <tomascohen@gmail.com>
This commit is contained in:
Jonathan Druart 2015-03-04 11:51:56 +01:00 committed by Tomas Cohen Arazi
parent 66db4a64ef
commit 83fee24dbc
1 changed files with 26 additions and 11 deletions

View File

@ -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 {