From ada73c317c31827072938ad066006aefdce72f58 Mon Sep 17 00:00:00 2001 From: Lucas Gass Date: Thu, 10 Sep 2026 15:06:44 +0000 Subject: [PATCH] Bug 41920: Move total_running_reports_per_instance_limit to Koha/Reports.pm Signed-off-by: Pedro Amorim --- Koha/Exceptions/Report.pm | 5 +++++ Koha/Report.pm | 8 ++++++++ Koha/Reports.pm | 2 +- 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/Koha/Exceptions/Report.pm b/Koha/Exceptions/Report.pm index d23c7113fb..b854587c74 100644 --- a/Koha/Exceptions/Report.pm +++ b/Koha/Exceptions/Report.pm @@ -14,6 +14,11 @@ use Exception::Class ( description => "The configured per-user limit on total simultaneous report runs has been reached", fields => [ 'user_id', 'limit' ], }, + 'Koha::Exceptions::Report::InstanceTotalRunning' => { + isa => 'Koha::Exceptions::Report', + description => "The configured instance-wide limit on total simultaneous report runs has been reached", + fields => ['limit'], + } ); 1; diff --git a/Koha/Report.pm b/Koha/Report.pm index aac9c16a3c..e172d2a03a 100644 --- a/Koha/Report.pm +++ b/Koha/Report.pm @@ -283,6 +283,14 @@ sub prep_report { } } + my $instance_limit = C4::Context->config('total_running_reports_per_instance_limit'); + if ($instance_limit) { + my $running = Koha::Reports->running(); + if ( $running->count >= $instance_limit ) { + Koha::Exceptions::Report::InstanceTotalRunning->throw( limit => $instance_limit ); + } + } + $sql .= " /* { saved_sql.id: $report_id } { user_id: $user_id } */"; return $sql, $headers; diff --git a/Koha/Reports.pm b/Koha/Reports.pm index e36bb464d3..83b92c49e1 100644 --- a/Koha/Reports.pm +++ b/Koha/Reports.pm @@ -104,7 +104,7 @@ sub running { } my $rs = $class->search( { id => { -in => [ keys %report_ids ] } } ); - return wantarray ? $rs->as_list : $rs; + return $class->search( { id => { -in => [ keys %report_ids ] } } ); } =head3 _processlist_rows