From abca8052dfdfdff84961ab81c6bf5735b31fd61b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20V=C3=A9ron?= Date: Mon, 20 Apr 2015 22:13:04 +0200 Subject: [PATCH] Bug 14024 - add reports to action logs This patch sets adds the possibility to log new, update and delete actions for saved reports. To test: -Apply patch -Run updatedatabase.pl -Enable system preference ReportsLog -Create, duplicate, edit and delete saved reports -Go to Home > Tools > Logs -Verify that you can select "Reports" in Modules list -Verify that your actions were logged Signed-off-by: Nicole Engard Signed-off-by: Nicole Engard Signed-off-by: Jonathan Druart --- C4/Reports/Guided.pm | 6 +++++- .../data/mysql/atomicupdate/bug_14024_add_reportslog_syspref.sql | 1 + installer/data/mysql/sysprefs.sql | 1 + koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/logs.pref | 6 ++++++ koha-tmpl/intranet-tmpl/prog/en/modules/tools/viewlog.tt | 3 ++- reports/guided_reports.pl | 4 ++++ 6 files changed, 19 insertions(+), 2 deletions(-) create mode 100644 installer/data/mysql/atomicupdate/bug_14024_add_reportslog_syspref.sql diff --git a/C4/Reports/Guided.pm b/C4/Reports/Guided.pm index 97a41c7..af92141 100644 --- a/C4/Reports/Guided.pm +++ b/C4/Reports/Guided.pm @@ -32,6 +32,7 @@ use XML::Dumper; use C4::Debug; # use Smart::Comments; # use Data::Dumper; +use C4::Log; BEGIN { # set the version for version checking @@ -639,6 +640,10 @@ sub format_results { sub delete_report { my (@ids) = @_; return unless @ids; + foreach my $id (@ids) { + my $data = get_saved_report($id); + logaction( "REPORTS", "DELETE", $id, "Name: $data->{'report_name'} SQL: $data->{'savedsql'} " ) if C4::Context->preference("ReportsLog"); + } my $dbh = C4::Context->dbh; my $query = 'DELETE FROM saved_sql WHERE id IN (' . join( ',', ('?') x @ids ) . ')'; my $sth = $dbh->prepare($query); @@ -646,7 +651,6 @@ sub delete_report { } sub get_saved_reports_base_query { - my $area_name_sql_snippet = get_area_name_sql_snippet; return <All [% END %] - [% FOREACH modx IN [ 'CATALOGUING' 'AUTHORITIES' 'MEMBERS' 'ACQUISITIONS' 'SERIAL' 'CIRCULATION' 'LETTER' 'FINES' 'SYSTEMPREFERENCE' 'CRONJOBS' ] %] + [% FOREACH modx IN [ 'CATALOGUING' 'AUTHORITIES' 'MEMBERS' 'ACQUISITIONS' 'SERIAL' 'CIRCULATION' 'LETTER' 'FINES' 'SYSTEMPREFERENCE' 'CRONJOBS', 'REPORTS' ] %] [% IF modules.grep(modx).size %] [% ELSE %] diff --git a/reports/guided_reports.pl b/reports/guided_reports.pl index 5d8b302..d2b658f 100755 --- a/reports/guided_reports.pl +++ b/reports/guided_reports.pl @@ -31,6 +31,8 @@ use C4::Dates qw/format_date/; use C4::Debug; use C4::Branch; # XXX subfield_is_koha_internal_p use C4::Koha qw/IsAuthorisedValueCategory GetFrameworksLoop/; +use C4::Context; +use C4::Log; =head1 NAME @@ -237,6 +239,7 @@ elsif ( $phase eq 'Update SQL'){ 'reportname' => $reportname, 'id' => $id, ); + logaction( "REPORTS", "MODIFY", $id, "$reportname: SQL: $sql" ) if C4::Context->preference("ReportsLog"); } if ( $usecache ) { $template->param( @@ -594,6 +597,7 @@ elsif ( $phase eq 'Save Report' ) { cache_expiry => $cache_expiry, public => $public, } ); + logaction( "REPORTS", "ADD", 0, "Name: $name: SQL: $sql" ) if C4::Context->preference("ReportsLog"); $template->param( 'save_successful' => 1, 'reportname' => $name, -- 2.1.0