From f6da07564a1eb1e9c78584c6c5b49c58fd7aee04 Mon Sep 17 00:00:00 2001 From: Fridolin Somers Date: Thu, 14 Jan 2021 15:34:55 +0100 Subject: [PATCH] Bug 27432: Add report run to action logs Reports run should be logged in action logs. This uses the exisiting action "Run" from cronjobs. Like for other actions, infos contains the report name ("Unknown report" is no report id provided) and executed SQL query. 1) Apply patch 2) Enable system preference "ReportsLog" 3) Run a report 4) Go to Tools > Log viewer 5) Select module "Reports" and submit 6) Check you see a log with report name and SQL query 7) Change SQL of report, re-run 8) Go to Tools > Log viewer 9) Select module "Reports" and submit 10) Select the 2 logs "Compare" and click "View comparison" Signed-off-by: Barbara Johnson Signed-off-by: Katrin Fischer Signed-off-by: Brendan Lawlor --- C4/Reports/Guided.pm | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/C4/Reports/Guided.pm b/C4/Reports/Guided.pm index 94e271cef7..604bff08fd 100644 --- a/C4/Reports/Guided.pm +++ b/C4/Reports/Guided.pm @@ -596,6 +596,8 @@ sub execute_query { my $limit = $params->{limit} || C4::Context->config('report_results_limit') || 999999; my $sql_params = defined $params->{sql_params} ? $params->{sql_params} : []; my $report_id = $params->{report_id}; + my $report = Koha::Reports->find($report_id) if $report_id; + my $report_name = $report ? $report->report_name : 'Unknown report'; # check parameters unless ($sql) { @@ -655,17 +657,10 @@ sub execute_query { eval { $sth->execute( @$sql_params, $offset, $limit ); }; warn $@ if $@; - Koha::Logger->get( { prefix => 0, interface => 'reports', category => 'execute.time.end' } ) - ->info("Report finished: $report_id") - if $report_id; - - return ( $sth, { queryerr => $sth->errstr } ) if ( $sth->err ); - - # Check if table.* contained forbidden column names - return ( $sth, { passworderr => "Illegal column in results" } ) - if Koha::Report->new->check_columns( undef, $sth->{NAME_lc} ); + logaction( "REPORTS", "Run", $report_id, "$report_name | $sql " ) if C4::Context->preference("ReportsLog"); - return ($sth); + return ( $sth, { queryerr => $sth->errstr } ) if ($sth->err); + return ( $sth ); } =head2 save_report($sql,$name,$type,$notes) -- 2.39.5