Permalink
Browse files

bug 3465: enhance DB update reporting by web installer

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 <gmcharlt@gmail.com>
  • Loading branch information...
1 parent 56c72ab commit 5cd357e76c56210592f298669041a6e27acd6b1c @gmcharlt gmcharlt committed Aug 1, 2009
View
@@ -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:
View
@@ -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,
View
@@ -91,6 +91,7 @@
HTTP::OAI
HTTP::Request::Common
HTML::Scrubber
+IPC::Cmd
JSON
LWP::Simple
LWP::UserAgent
View
@@ -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::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 @@
# 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 {
@@ -65,6 +65,11 @@ td input { font-size: 1.5em; }
font-style: italic;
}
+.update_error {
+ color: red;
+ font-weight: bold;
+}
+
</style>
</head>
<body>
@@ -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&amp;op=finished" class="button">Continue to log in to Koha</a>
</div>
<!--/TMPL_IF-->

0 comments on commit 5cd357e

Please sign in to comment.