This enhances the web installer so that messages from updatedatabase.pl will be displayed to the user running a database update. Messages printed to STDOUT will be displayed as the update report, while messages printed to STDERR will be displayed as update errors.
This patch introduces a new module dependency, IPC::Cmd. IPC::Cmd lets one run an external program such as updatedatabase.pl and easily capture STDERR and STDOUT for further munging. IPC::Cmd is core in Perl 5.10 and stable in Perl 5.8. Signed-off-by: Galen Charlton <[email protected]> --- INSTALL.debian | 2 +- Makefile.PL | 1 + about.pl | 1 + installer/install.pl | 27 +++++++++++--------- .../prog/en/includes/installer-doc-head-close.inc | 5 +++ .../prog/en/modules/installer/step3.tmpl | 25 +++++++++++++----- 6 files changed, 41 insertions(+), 20 deletions(-) diff --git a/INSTALL.debian b/INSTALL.debian index 885f3f9..bfb94e2 100644 --- a/INSTALL.debian +++ b/INSTALL.debian @@ -111,7 +111,7 @@ Run the following command: Net::Z3950::ZOOM HTML::Template::Pro MARC::Crosswalk::DublinCore \ PDF::Reuse PDF::Reuse::Barcode Data::ICal GD::Barcode::UPCE \ XML::RSS Algorithm::CheckDigits::M43_001 Biblio::EndnoteStyle POE \ - Schedule::At DBD::SQLite GD SMS::Send HTTP::OAI + Schedule::At DBD::SQLite GD SMS::Send HTTP::OAI IPC::Cmd WARNINGS: diff --git a/Makefile.PL b/Makefile.PL index 3150394..99d1189 100644 --- a/Makefile.PL +++ b/Makefile.PL @@ -560,6 +560,7 @@ WriteMakefile( 'HTTP::Cookies' => 1.39, 'HTTP::OAI' => 3.20, 'HTTP::Request::Common' => 1.26, + 'IPC::Cmd' => 0.46, 'JSON' => 2.07, # Needed by admin/item_circulation_alerts.pl 'LWP::Simple' => 1.41, 'LWP::UserAgent' => 2.033, diff --git a/about.pl b/about.pl index 56d1717..e21dafc 100755 --- a/about.pl +++ b/about.pl @@ -91,6 +91,7 @@ HTTP::Cookies HTTP::OAI HTTP::Request::Common HTML::Scrubber +IPC::Cmd JSON LWP::Simple LWP::UserAgent diff --git a/installer/install.pl b/installer/install.pl index 207e2b6..9d21962 100755 --- a/installer/install.pl +++ b/installer/install.pl @@ -1,5 +1,7 @@ -#!/usr/bin/perl -w # please develop with -w +#!/usr/bin/perl +use strict; +use warnings; use diagnostics; # use Install; @@ -9,9 +11,8 @@ use C4::Output; use C4::Languages qw(getAllLanguages getTranslatedLanguages); use C4::Installer; -use strict; # please develop with the strict pragma - use CGI; +use IPC::Cmd; my $query = new CGI; my $step = $query->param('step'); @@ -391,16 +392,18 @@ elsif ( $step && $step == 3 ) { # Not 1st install, the only sub-step : update database # #Do updatedatabase And report - my $execstring = - C4::Context->config("intranetdir") . "/installer/data/$info{dbms}/updatedatabase.pl"; - undef $/; - my $string = qx($execstring 2>&1 1>/dev/null); # added '1>/dev/null' to return only stderr in $string. Needs testing here. -fbcit - if ($string) { - $string =~ s/\n|\r/<br \/>/g; - $string =~ - s/(DBD::mysql.*? failed: .*? line [0-9]*.|=================.*?====================)/<font color=red>$1<\/font>/g; - $template->param( "updatereport" => $string ); + 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); + + if (@$stdout_buf) { + $template->param(update_report => [ map { { line => $_ } } split(/\n/, join('', @$stdout_buf)) ] ); + $template->param(has_update_succeeds => 1); } + if (@$stderr_buf) { + $template->param(update_errors => [ map { { line => $_ } } split(/\n/, join('', @$stderr_buf)) ] ); + $template->param(has_update_errors => 1); + } + $template->param( $op => 1 ); } else { diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/installer-doc-head-close.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/installer-doc-head-close.inc index 352b615..b5dd2fe 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/installer-doc-head-close.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/installer-doc-head-close.inc @@ -65,6 +65,11 @@ td input { font-size: 1.5em; } font-style: italic; } +.update_error { + color: red; + font-weight: bold; +} + </style> </head> <body> diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/installer/step3.tmpl b/koha-tmpl/intranet-tmpl/prog/en/modules/installer/step3.tmpl index 94679de..4d3f0ac 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/installer/step3.tmpl +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/installer/step3.tmpl @@ -271,14 +271,25 @@ <!--TMPL_IF Name="updatestructure"--> <div><h2 align="center">Updating database structure</h2> - <!--TMPL_IF Name="updatereport"--> - <p>Update report :</p> - <p> - <!--TMPL_VAR Name="updatereport"--> - </p> - <!--TMPL_ELSE--> + <!-- TMPL_IF NAME="has_update_succeeds" --> + <p>Update report :</p> + <ul> + <!-- TMPL_LOOP NAME="update_report" --> + <li><!-- TMPL_VAR NAME="line" ESCAPE="html" --></li> + <!-- /TMPL_LOOP --> + </ul> + <!-- /TMPL_IF --> + <!-- TMPL_IF NAME="has_update_errors" --> + <p>Update errors :</p> + <ul> + <!-- TMPL_LOOP NAME="update_errors" --> + <li class="update_error"><!-- TMPL_VAR NAME="line" ESCAPE="html" --></li> + <!-- /TMPL_LOOP --> + </ul> + <!-- /TMPL_IF --> + <!-- TMPL_UNLESS NAME="has_update_errors" --> <p>Everything went OK, update done.</p> - <!--/TMPL_IF--> + <!-- /TMPL_UNLESS --> <a href="install.pl?step=3&op=finished" class="button">Continue to log in to Koha</a> </div> <!--/TMPL_IF--> -- 1.5.6.5 _______________________________________________ Koha-patches mailing list [email protected] http://lists.koha.org/mailman/listinfo/koha-patches
