From 49a6b44e1050c881798602ea03d7d0c863fe20b9 Mon Sep 17 00:00:00 2001 From: Matheus Zych Date: Fri, 20 Feb 2026 13:59:50 +0100 Subject: [PATCH] BackgroundTasks: Skip BT aggregates for anonymous See: https://mantis.ilias.de/view.php?id=45683 The background-task popover loaded bucket lists for every session, including anonymous users without persistent tasks. `ilBTPopOverGUI::getAggregateItems` now returns an empty array when the user id is `ANONYMOUS_USER_ID`. The running-task refresh hook was rewritten as a static closure with a heredoc so `il.BGTask.refreshItem` receives the notification item directly. (cherry picked from commit bad14e7165dea269f92eb9e2b2b8983d8a7d0527) --- .../classes/class.ilBTPopOverGUI.php | 20 ++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/components/ILIAS/BackgroundTasks_/classes/class.ilBTPopOverGUI.php b/components/ILIAS/BackgroundTasks_/classes/class.ilBTPopOverGUI.php index 8577b6f034b3..6308d5d52189 100755 --- a/components/ILIAS/BackgroundTasks_/classes/class.ilBTPopOverGUI.php +++ b/components/ILIAS/BackgroundTasks_/classes/class.ilBTPopOverGUI.php @@ -68,9 +68,14 @@ public function getNotificationItem(int $nr_buckets): Notification */ protected function getAggregateItems(): array { + $user = $this->dic->user(); + if ($user->isAnonymous() || $user->getId() === 0) { + return []; + } + $persistence = $this->dic->backgroundTasks()->persistence(); $items = []; - $observer_ids = $persistence->getBucketIdsOfUser($this->dic->user()->getId(), 'id', 'DESC'); + $observer_ids = $persistence->getBucketIdsOfUser($user->getId(), 'id', 'DESC'); foreach ($persistence->loadBuckets($observer_ids) as $observer) { $items[] = $this->getItemForObserver($observer); } @@ -99,12 +104,6 @@ public function getItemForObserver(Bucket $observer): Notification } $item = $f->item()->notification($title, $icon); - // $item = $item->withProperties([ - // $this->dic->language()->txt('nc_mail_prop_time') => \ilDatePresentation::formatDate( - // new \ilDateTime(time(), IL_CAL_UNIX) - // ) - // ]); - $item = $item->withActions($f->dropdown()->standard($actions)); $input = $current_task->getInput(); $message = $current_task->getMessage($input); @@ -125,8 +124,11 @@ public function getItemForObserver(Bucket $observer): Notification if ($state === State::RUNNING) { $url = $this->getRefreshUrl($observer); //Running Items probably need to refresh themselves, right? - $item = $item->withAdditionalOnLoadCode(fn($id): string => "var notification_item = il.UI.item.notification.getNotificationItemObject($('#$id')); - il.BGTask.refreshItem(notification_item,'$url');"); + $item = $item->withAdditionalOnLoadCode( + static fn(string $id): string => <<getExpectedTimeOfTaskInSeconds() : 0; $possibly_failed = ($observer->getLastHeartbeat() < (time() - $expected));