From 7bd64b0f6ffd5f460ce2da28a586186771e56782 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! Signed-off-by: Alex Carver [Acerock7] Signed-off-by: Martin Renvoize Signed-off-by: Lucas Gass --- .../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 c7ab443c95..74ffefbca6 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 @@ -1638,7 +1638,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 53cfc9a2f5..6d2be0e376 100755 --- a/reports/guided_reports.pl +++ b/reports/guided_reports.pl @@ -824,6 +824,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; @@ -1009,6 +1015,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 );