From 5cd357e76c56210592f298669041a6e27acd6b1c Mon Sep 17 00:00:00 2001 From: Galen Charlton Date: Sat, 1 Aug 2009 12:17:18 -0400 Subject: [PATCH] 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 --- INSTALL.debian | 2 +- Makefile.PL | 1 + about.pl | 1 + installer/install.pl | 27 ++++++++++--------- .../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 885f3f9152..bfb94e269e 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 315039436f..99d1189813 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 56d1717dd7..e21dafc758 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 207e2b6b1e..9d2196207a 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/
/g; - $string =~ - s/(DBD::mysql.*? failed: .*? line [0-9]*.|=================.*?====================)/$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 352b61532c..b5dd2fe576 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; +} + 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 94679deb30..4d3f0ac930 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 @@

Updating database structure

- -

Update report :

-

- -

- + +

Update report :

+
    + +
  • + +
+ + +

Update errors :

+
    + +
  • + +
+ +

Everything went OK, update done.

- + Continue to log in to Koha
-- 2.20.1