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