From e9eff64fa0bdecc70926dadf70eb19588f9ca003 Mon Sep 17 00:00:00 2001 From: Kyle M Hall Date: Wed, 25 Feb 2026 11:07:36 -0500 Subject: [PATCH] Bug 41918: Prevent a given librarian from running the same report multiple times simultaneously Test Plan: 1) create a long running report such as: SELECT COUNT(*) FROM items i1 JOIN items i2 JOIN items i3 JOIN items i4 JOIN items i5 JOIN items i6 2) Run this report multiple times 3) Note the processes are running via SHOW FULL PROCESSLIST from koha-mysql 4) Kill those processes 5) Apply this patch 6) Restart all the things! 7) Try to run the report in two tabs, note the second tab opened says the report is already running! --- .../en/modules/reports/guided_reports_start.tt | 4 +++- reports/guided_reports.pl | 18 ++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/reports/guided_reports_start.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/reports/guided_reports_start.tt index 17d306491dd..95491ab9751 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/reports/guided_reports_start.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/reports/guided_reports_start.tt @@ -1617,7 +1617,9 @@
The following error was encountered:
[% FOREACH error IN errors %] - [% IF ( error.sqlerr ) %] + [% IF ( error.duplicate_running_report_ids ) %] + This report is already running. Please wait for it to finish before running it again. + [% ELSIF ( error.sqlerr ) %] This report contains the SQL keyword [% error.sqlerr | html %].
Use of this keyword is not allowed in Koha reports due to security and data integrity risks. Only SELECT queries are allowed.
Please return to the "Saved Reports" screen and delete this report or retry creating a new one. diff --git a/reports/guided_reports.pl b/reports/guided_reports.pl index d1444a7c6e5..3fc6bdb0110 100755 --- a/reports/guided_reports.pl +++ b/reports/guided_reports.pl @@ -789,6 +789,12 @@ if ( $op eq 'run' ) { my $template_id = $input->param('template'); my $want_full_chart = $input->param('want_full_chart') || 0; + my @duplicate_running_report_ids; + if ( C4::Context->userenv ) { + my $user_id = C4::Context->userenv ? C4::Context->userenv->{number} : undef; + @duplicate_running_report_ids = Koha::Reports->running( { report_id => $report_id, user_id => $user_id } ); + } + # offset algorithm if ( $input->param('page') ) { $offset = ( $input->param('page') - 1 ) * $limit; @@ -973,6 +979,18 @@ if ( $op eq 'run' ) { 'id' => $report_id, 'template_id' => $template_id, ); + } elsif (@duplicate_running_report_ids) { + $template->param( + 'sql' => $sql, + 'original_sql' => $original_sql, + 'id' => $report_id, + 'execute' => 1, + 'name' => $name, + 'notes' => $notes, + 'errors' => [ { duplicate_running_report_ids => \@duplicate_running_report_ids } ], + 'sql_params' => \@sql_params, + 'param_names' => \@param_names, + ); } else { my ( $sql, $header_types ) = $report->prep_report( \@param_names, \@sql_params ); $template->param( header_types => $header_types ); -- 2.50.1 (Apple Git-155)