From 2afee7b84a2d23f461dad1e39a6e97f25a90e3ed Mon Sep 17 00:00:00 2001 From: MJ Ray Date: Thu, 22 Sep 2011 19:27:43 +0100 Subject: [PATCH] Bug 6460: alternative fix, updating template and script instead of C4::Log Add some test cases and fix a bug in C4::Log found by in review. Thanks-to: Katrin Fischer. Signed-off-by: Liz Rea Passes test, interface works as expected. Signed-off-by: Liz Rea Signed-off-by: Chris Cormack (cherry picked from commit a746e11c1462df4567c007c8e73cf14a55af5ddb) Signed-off-by: Chris Nighswonger --- C4/Log.pm | 3 +- .../prog/en/modules/tools/viewlog.tt | 85 ++----------------- t/db_dependent/Log.t | 52 ++++++++++++ tools/viewlog.pl | 6 +- 4 files changed, 64 insertions(+), 82 deletions(-) create mode 100644 t/db_dependent/Log.t diff --git a/C4/Log.pm b/C4/Log.pm index 98cd8d5f1c..6b8ff17e45 100644 --- 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); } diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/viewlog.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/viewlog.tt index c109744b9a..f20569d3fc 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/viewlog.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/viewlog.tt @@ -59,11 +59,11 @@
  • @@ -133,81 +133,6 @@ - [% IF ( do_it ) %] - [% IF ( total ) %] -

    [% total %] lines found.

    - - - - - - - - - - [% FOREACH loopro IN looprow %] - [% UNLESS ( loop.odd ) %][% ELSE %][% END %] - - - - - - - - [% END %] -
    DateLibrarianModuleActionObjectInfo
    [% loopro.timestamp %] - [% loopro.user %] - [% loopro.module %][% loopro.action %] - [% IF ( module == 'MEMBERS' ) %] - member [% loopro.object %] - [% ELSE %] - [% IF ( module == 'CIRCULATION' ) %] - - [% IF ( loopro.object ) %] - member [% loopro.object %] - [% END %] - - [% ELSE %] - [% IF ( module == 'CATALOGUING' ) %] - [% IF ( info == 'item' ) %] - Item [% loopro.object %] - [% ELSE %] - biblio [% loopro.object %] - [% END %] - [% ELSE %] - [% IF ( module == 'SERIAL' ) %] - [% loopro.object %] - [% ELSE %] - [% IF ( module == 'AUTHORITIES' ) %] - auth [% loopro.object %] - [% ELSE %] - [% loopro.object %] - [% END %] - [% END %] - [% END %] - [% END %] - [% END %] - - [% IF ( loopro.CIRCULATION ) %] - biblio [% loopro.info |html %] - [% ELSE %] - [% loopro.info |html %] - [% END %] -
    - [% ELSE %] -
    - No log found - [% IF ( CATALOGUING ) %] - for Bibliographic Record [% object %] - [% END %] - [% IF ( MEMBERS ) %] - for [% firstname %] [% surname %] ([% cardnumber %]) - [% END %] - . -
    - [% END %] - [% END %] - [% END %] [% IF ( do_it ) %] diff --git a/t/db_dependent/Log.t b/t/db_dependent/Log.t new file mode 100644 index 0000000000..b110bae923 --- /dev/null +++ b/t/db_dependent/Log.t @@ -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"); diff --git a/tools/viewlog.pl b/tools/viewlog.pl index d689217bbc..5c430985da 100755 --- a/tools/viewlog.pl +++ b/tools/viewlog.pl @@ -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){ -- 2.39.5