Bug 10915: (QA followup) warn if cannot read history.txt
authorTomas Cohen Arazi <tomascohen@gmail.com>
Thu, 19 Sep 2013 15:40:03 +0000 (12:40 -0300)
committerGalen Charlton <gmc@esilibrary.com>
Fri, 20 Sep 2013 17:25:57 +0000 (17:25 +0000)
This patch makes about.pl test if success opening history.txt, and
shows a convenient warning to the end user. No more warnings in the logs
(about.pl: readline() on closed filehandle $file at /usr/share/koha/intranet/cgi-bin/about.pl line 166)
and better problem solving information for the end user.

Sponsored-by: Universidad Nacional de Cordoba
Signed-off-by: Galen Charlton <gmc@esilibrary.com>

about.pl
koha-tmpl/intranet-tmpl/prog/en/modules/about.tt

index 0ba7291..6b44ea8 100755 (executable)
--- a/about.pl
+++ b/about.pl
@@ -157,39 +157,43 @@ if ( defined C4::Context->config('docdir') ) {
     $docdir = C4::Context->config('intranetdir') . '/docs';
 }
 
-open( my $file, "<", "$docdir" . "/history.txt" );
-my $i = 0;
+if ( open( my $file, "<", "$docdir" . "/history.txt" ) ) {
 
-my @rows2 = ();
-my $row2  = [];
+    my $i = 0;
 
-my @lines = <$file>;
-close($file);
+    my @rows2 = ();
+    my $row2  = [];
 
-shift @lines; #remove header row
+    my @lines = <$file>;
+    close($file);
 
-foreach (@lines) {
-    my ( $date, $desc, $tag ) = split(/\t/);
-    if(!$desc && $date=~ /(?<=\d{4})\s+/) {
-        ($date, $desc)= ($`, $');
-    }
-    push(
-        @rows2,
-        {
-            date => $date,
-            desc => $desc,
+    shift @lines; #remove header row
+
+    foreach (@lines) {
+        my ( $date, $desc, $tag ) = split(/\t/);
+        if(!$desc && $date=~ /(?<=\d{4})\s+/) {
+            ($date, $desc)= ($`, $');
         }
-    );
-}
+        push(
+            @rows2,
+            {
+                date => $date,
+                desc => $desc,
+            }
+        );
+    }
 
-my $table2 = [];
-#foreach my $row2 (@rows2) {
-foreach  (@rows2) {
-    push (@$row2, $_);
-    push( @$table2, { row2 => $row2 } );
-    $row2 = [];
-}
+    my $table2 = [];
+    #foreach my $row2 (@rows2) {
+    foreach  (@rows2) {
+        push (@$row2, $_);
+        push( @$table2, { row2 => $row2 } );
+        $row2 = [];
+    }
 
-$template->param( table2 => $table2 );
+    $template->param( table2 => $table2 );
+} else {
+    $template->param( timeline_read_error => 1 );
+}
 
 output_html_with_http_headers $query, $cookie, $template->output;
index 5d32bbe..57aa522 100644 (file)
 
         <div id="history">
         <h2>Koha history timeline</h2>
+    [% IF ! timeline_read_error %]
         <table style="cursor:pointer">
         <thead>
         <tr>
             </tr>
         [% END %]
         </table>
+    [% ELSE %]
+        <div class="dialog alert">
+            Could not read the history.txt file. Please make sure &lt;docdir&gt; is correctly defined in koha-conf.xml.
+        </div>
+    [% END %]
         </div>
 
     </div>