Bug 6460: alternative fix, updating template and script instead of C4::Log
authorMJ Ray <mjr@phonecoop.coop>
Thu, 22 Sep 2011 18:27:43 +0000 (19:27 +0100)
committerChris Cormack <chrisc@catalyst.net.nz>
Fri, 23 Sep 2011 22:01:09 +0000 (10:01 +1200)
Add some test cases and fix a bug in C4::Log found by in review.
Thanks-to: Katrin Fischer.

Signed-off-by: Liz Rea <lrea@nekls.org>
Passes test, interface works as expected.

Signed-off-by: Liz Rea <lrea@nekls.org>
Signed-off-by: Chris Cormack <chrisc@catalyst.net.nz>
C4/Log.pm
koha-tmpl/intranet-tmpl/prog/en/modules/tools/viewlog.tt
t/db_dependent/Log.t [new file with mode: 0644]
tools/viewlog.pl

index 98cd8d5..6b8ff17 100644 (file)
--- a/C4/Log.pm
+++ b/C4/Log.pm
@@ -4,6 +4,7 @@ package C4::Log;
 
 
 # Copyright 2000-2002 Katipo Communications
+# Copyright 2011 MJ Ray and software.coop
 #
 # This file is part of Koha.
 #
@@ -217,7 +218,7 @@ sub GetLogs {
        $query .= " AND user = ? ";
        push(@parameters,$user);
     }
-    if(scalar @$modules > 1 or @$modules[0] ne "") {
+    if($modules && scalar(@$modules)) {
        $query .= " AND module IN (".join(",",map {"?"} @$modules).") ";
        push(@parameters,@$modules);
     }
index c109744..f20569d 100644 (file)
                                                                <label for="action">Action:</label>
                                                                <select name="action" id="action">
                                                                        <option value ="">All</option>
-                                                                       <option value ="add">Add</option>
-                                                                       <option value ="del">Delete</option>
-                                                                       <option value ="mod">Modify</option>
-                                                                       <option value="issue">Checkout</option>
-                                                                       <option value="return">Return</option>
+                                                                       <option value ="ADD">Add</option>
+                                                                       <option value ="DELETE">Delete</option>
+                                                                       <option value ="MODIFY">Modify</option>
+                                                                       <option value="ISSUE">Checkout</option>
+                                                                       <option value="RETURN">Return</option>
                                                                </select>
                                                        </li>
                                                        <li>
                                                <input type="submit" value="Submit" />
                                                <input type="hidden" name="do_it" value="1" />
                                        </fieldset>
-                                       [% IF ( do_it ) %]
-                                               [% IF ( total ) %]
-                                                       <h4>[% total %] lines found.</h4>
-                                                       <table>
-                                                               <tr>
-                                                                       <th>Date</th>
-                                                                       <th>Librarian</th>
-                                                                       <th>Module</th>
-                                                                       <th>Action</th>
-                                                                       <th>Object</th>
-                                                                       <th>Info</th>
-                                                               </tr>
-                                                               [% FOREACH loopro IN looprow %]
-                                                                       [% UNLESS ( loop.odd ) %]<tr class="highlight">[% ELSE %]<tr>[% END %]
-                                                                               <td>[% loopro.timestamp %]</td>
-                                                                               <td>
-                                                                                       <a href="/cgi-bin/koha/members/moremember.pl?borrowernumber=[% loopro.user %]" title="display detail for this librarian."> [% loopro.user %] </a>
-                                                                               </td>
-                                                                               <td>[% loopro.module %]</td>
-                                                                               <td>[% loopro.action %]</td>
-                                                                               <td>
-                                                                                       [% IF ( module == 'MEMBERS' ) %]
-                                                                                               <a href="/cgi-bin/koha/members/moremember.pl?borrowernumber=[% loopro.object %]" title="Display member details."> member [% loopro.object %] </a>
-                                                                                       [% ELSE %]
-                                                                                               [% IF ( module == 'CIRCULATION' ) %]
-                                                                                                       <a href="/cgi-bin/koha/members/moremember.pl?borrowernumber=[% loopro.object %]" title="Display member details.">
-                                                                                                               [% IF ( loopro.object ) %]
-                                                                                                                       member [% loopro.object %]
-                                                                                                               [% END %]
-                                                                                                       </a>
-                                                                                               [% ELSE %]
-                                                                                                       [% IF ( module == 'CATALOGUING' ) %]
-                                                                                                               [% IF ( info == 'item' ) %]
-                                                                                                                       <a href="/cgi-bin/koha/catalogue/moredetail.pl?item=[% loopro.object %]&amp;biblionumber=[% loopro.biblionumber %]&amp;bi=[% loopro.biblioitemnumber %]#item[% loopro.object %]">Item [% loopro.object %]</a>
-                                                                                                               [% ELSE %]
-                                                                                                                       <a href="/cgi-bin/koha/catalogue/detail.pl?biblionumber=[% loopro.object %]" title="Display detail for this biblio">biblio [% loopro.object %]</a>
-                                                                                                               [% END %]
-                                                                                                       [% ELSE %]
-                                                                                                               [% IF ( module == 'SERIAL' ) %]
-                                                                                                                       <a href="/cgi-bin/koha/serials/subscription-detail.pl?subscriptionid=[% loopro.object %]"> [% loopro.object %] </a>
-                                                                                                               [% ELSE %]
-                                                                                                                       [% IF ( module == 'AUTHORITIES' ) %]
-                                                                                                                               <a href="/cgi-bin/koha/authorities/detail.pl?authid=[% loopro.object %]" title="Display detail for this authority">auth [% loopro.object %]</a>
-                                                                                                                       [% ELSE %]
-                                                                                                                               [% loopro.object %]
-                                                                                                                       [% END %]
-                                                                                                               [% END %]
-                                                                                                       [% END %]
-                                                                                               [% END %]
-                                                                                       [% END %]
-                                                                               </td>
-                                                                               <td>
-                                                                                       [% IF ( loopro.CIRCULATION ) %]
-                                                                                               <a href="/cgi-bin/koha/catalogue/detail.pl?biblionumber=[% loopro.info %]" title="Display detail for this biblio">biblio [% loopro.info |html %]</a>
-                                                                                       [% ELSE %]
-                                                                                               [% loopro.info |html %]
-                                                                                       [% END %]
-                                                                               </td>
-                                                                       </tr>
-                                                               [% END %]
-                                                       </table>
-                                               [% ELSE %]
-                                                       <div class="dialog alert">
-                                                               No log found
-                                                               [% IF ( CATALOGUING ) %]
-                                                                       for <a href="/cgi-bin/koha/catalogue/detail.pl?biblionumber=[% object %]">Bibliographic Record [% object %]</a>
-                                                               [% END %]
-                                                               [% IF ( MEMBERS ) %]
-                                                                       for <a href="/cgi-bin/koha/members/moremember.pl?borrowernumber=[% object %]">[% firstname %] [% surname %] ([% cardnumber %])</a>
-                                                               [% END %]
-                                                               .
-                                                       </div>
-                                               [% END %]
-                                       [% END %]
-
                                </form>
                 [% END %]
                 [% IF ( do_it ) %]
diff --git a/t/db_dependent/Log.t b/t/db_dependent/Log.t
new file mode 100644 (file)
index 0000000..b110bae
--- /dev/null
@@ -0,0 +1,52 @@
+#!/usr/bin/perl
+#
+# Copyright 2011 MJ Ray and software.coop
+# This Koha test module is a stub!  
+# Add more tests here!!!
+
+use strict;
+use warnings;
+use Test::More tests => 5;
+use C4::Log;
+
+BEGIN {
+       use_ok('C4::Log');
+}
+my $success;
+
+eval {
+    # FIXME: are we sure there is an member number 1?
+    # FIXME: can we remove this log entry somehow?
+    logaction("MEMBERS","MODIFY",1,"test operation");
+    $success = 1;
+} or do {
+    diag($@);
+    $success = 0;
+};
+ok($success, "logaction seemed to work");
+
+eval {
+    # FIXME: US formatted date hardcoded into test for now
+    $success = scalar(@{GetLogs("","","",undef,undef,"","")});
+} or do {
+    diag($@);
+    $success = 0;
+};
+ok($success, "GetLogs returns results for an open search");
+
+eval {
+    # FIXME: US formatted date hardcoded into test for now
+    $success = scalar(@{GetLogs("09/01/2011","10/01/2011","",undef,undef,"","")});
+} or do {
+    diag($@);
+    $success = 0;
+};
+ok($success, "GetLogs accepts dates in an All-matching search");
+
+eval {
+    $success = scalar(@{GetLogs("","","",["MEMBERS"],["MODIFY"],1,"")});
+} or do {
+    diag($@);
+    $success = 0;
+};
+ok($success, "GetLogs seemed to find ".$success." like our test record in a tighter search");
index d689217..5c43098 100755 (executable)
@@ -1,6 +1,7 @@
 #!/usr/bin/perl
 
 # Copyright 2010 BibLibre
+# Copyright 2011 MJ Ray and software.coop
 #
 # This file is part of Koha.
 #
@@ -105,7 +106,10 @@ $template->param(
 if ($do_it) {
 
     my @data;
-    my $results = GetLogs($datefrom,$dateto,$user,\@modules,\@action,$object,$info);
+    my ($results,$modules,$action);
+    if ($action[0] ne '') { $action = \@action; } # match All means no limit
+    if ($modules[0] ne '') { $modules = \@modules; } # match All means no limit
+    $results = GetLogs($datefrom,$dateto,$user,$modules,$action,$object,$info);
     @data=@$results;
     my $total = scalar @data;
     foreach my $result (@data){