Repository navigation
Forum: add instant push notifications #12042
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
iszmais
merged 5 commits into
ILIAS-eLearning:trunk
from
iszmais:feature/push-notifications-forum
Oct 16, 2026
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
34f68dc
initial push implementation for forum
iszmais 5692341
Merge branch 'trunk' of https://github.com/ILIAS-eLearning/ILIAS into…
iszmais b165b9e
add result handling and remove double mail job
iszmais 4929bfc
Merge branch 'trunk' of https://github.com/ILIAS-eLearning/ILIAS into…
iszmais 5d8bb3d
Deassign user from background task
iszmais File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
81 changes: 81 additions & 0 deletions
81
...LIAS/Forum/classes/Notification/BackgroundTask/class.ilForumNotificationTaskProcessor.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,81 @@ | ||
| <?php | ||
|
|
||
| /** | ||
| * This file is part of ILIAS, a powerful learning management system | ||
| * published by ILIAS open source e-Learning e.V. | ||
| * | ||
| * ILIAS is licensed with the GPL-3.0, | ||
| * see https://www.gnu.org/licenses/gpl-3.0.en.html | ||
| * You should have received a copy of said license along with the | ||
| * source code, too. | ||
| * | ||
| * If this is not the case or you just want to try ILIAS, you'll find | ||
| * us at: | ||
| * https://www.ilias.de | ||
| * https://github.com/ILIAS-eLearning | ||
| * | ||
| *********************************************************************/ | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| use ILIAS\BackgroundTasks\Implementation\Bucket\BasicBucket; | ||
| use ILIAS\BackgroundTasks\Implementation\Bucket\State; | ||
| use ILIAS\BackgroundTasks\Task\TaskFactory; | ||
| use ILIAS\BackgroundTasks\TaskManager; | ||
|
|
||
| readonly class ilForumNotificationTaskProcessor | ||
| { | ||
| private TaskManager $task_manager; | ||
| private TaskFactory $task_factory; | ||
| private ilLanguage $lng; | ||
| private ilLogger $logger; | ||
| private ilObjUser $user; | ||
|
|
||
| public function __construct(ilLogger $logger) | ||
| { | ||
| global $DIC; | ||
| $this->task_manager = $DIC->backgroundTasks()->taskManager(); | ||
| $this->task_factory = $DIC->backgroundTasks()->taskFactory(); | ||
| $this->lng = $DIC->language(); | ||
| $this->user = $DIC->user(); | ||
| $this->logger = $logger ; | ||
| } | ||
|
|
||
| /** | ||
| * @param int[] $recipients | ||
| */ | ||
| public function run( | ||
| ilForumNotificationMailData $provider, | ||
| int $notification_type, | ||
| array $recipients, | ||
| ): void { | ||
| if ($recipients === []) { | ||
| return; | ||
| } | ||
|
|
||
| $push_job = $this->task_factory->createTask(ilForumPushNotificationJob::class, [ | ||
| json_encode([ | ||
| 'post_id' => $provider->getPostId(), | ||
| 'ref_id' => $provider->getRefId(), | ||
| 'notification_type' => $notification_type, | ||
| 'recipients' => array_values($recipients), | ||
| ], JSON_THROW_ON_ERROR), | ||
| ]); | ||
|
|
||
| $bucket = new BasicBucket(); | ||
| $bucket->setUserId(ANONYMOUS_USER_ID); | ||
| $bucket->setTask($push_job); | ||
| $this->lng->loadLanguageModule('forum'); | ||
| $bucket->setTitle($this->lng->txt('frm_notification_bg_task_title')); | ||
|
|
||
| $this->logger->info('Delegated forum notification delivery to background task.'); | ||
| $this->task_manager->run($bucket); | ||
| if ($bucket->getState() === State::FINISHED) { | ||
| $this->logger->info('Delivery of forum notifications successfull!'); | ||
| } elseif ($bucket->getState() === State::ERROR) { | ||
| $this->logger->warning('Delivery of forum notifications failed!'); | ||
| } else { | ||
| $this->logger->info('Delivery status of forum notifications unknown.'); | ||
| } | ||
| } | ||
| } |
86 changes: 86 additions & 0 deletions
86
...ents/ILIAS/Forum/classes/Notification/BackgroundTask/class.ilForumPushNotificationJob.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,86 @@ | ||
| <?php | ||
|
|
||
| /** | ||
| * This file is part of ILIAS, a powerful learning management system | ||
| * published by ILIAS open source e-Learning e.V. | ||
| * | ||
| * ILIAS is licensed with the GPL-3.0, | ||
| * see https://www.gnu.org/licenses/gpl-3.0.en.html | ||
| * You should have received a copy of said license along with the | ||
| * source code, too. | ||
| * | ||
| * If this is not the case or you just want to try ILIAS, you'll find | ||
| * us at: | ||
| * https://www.ilias.de | ||
| * https://github.com/ILIAS-eLearning | ||
| * | ||
| *********************************************************************/ | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| use ILIAS\BackgroundTasks\Implementation\Tasks\AbstractJob; | ||
| use ILIAS\BackgroundTasks\Implementation\Values\ScalarValues\BooleanValue; | ||
| use ILIAS\BackgroundTasks\Implementation\Values\ScalarValues\IntegerValue; | ||
| use ILIAS\BackgroundTasks\Implementation\Values\ScalarValues\StringValue; | ||
| use ILIAS\BackgroundTasks\Observer; | ||
| use ILIAS\BackgroundTasks\Types\SingleType; | ||
| use ILIAS\BackgroundTasks\Types\Type; | ||
| use ILIAS\BackgroundTasks\Value; | ||
|
|
||
| class ilForumPushNotificationJob extends AbstractJob | ||
| { | ||
| public function run(array $input, Observer $observer): Value | ||
| { | ||
| global $DIC; | ||
|
|
||
| $data = json_decode((string) $input[0]->getValue(), true, 512, JSON_THROW_ON_ERROR); | ||
|
|
||
| $provider = new ilForumNotificationDataProvider( | ||
| new ilForumPost((int) $data['post_id']), | ||
| (int) $data['ref_id'], | ||
| new ilForumNotificationCache() | ||
| ); | ||
|
|
||
| $push_provider = new ilForumPushProvider(); | ||
| $mail_recipients = $push_provider->filterMailRecipients( | ||
| $data['recipients'], | ||
| $provider, | ||
| (int) $data['notification_type'], | ||
| $DIC->logger()->forComponent('forum') | ||
| ); | ||
|
|
||
| $output = new BooleanValue(); | ||
| $output->setValue(true); | ||
|
|
||
| if ($mail_recipients !== []) { | ||
| $mail_notification = new ilForumMailEventNotificationSender($provider, $DIC->logger()->forComponent('forum')); | ||
| $mail_notification->setType((int) $data['notification_type']); | ||
| $mail_notification->setRecipients($mail_recipients); | ||
| $mail_notification->send(); | ||
| } | ||
|
|
||
| return $output; | ||
| } | ||
|
|
||
| public function getInputTypes(): array | ||
| { | ||
| return [ | ||
| new SingleType(StringValue::class), | ||
| ]; | ||
| } | ||
|
|
||
| public function getOutputType(): Type | ||
| { | ||
| return new SingleType(BooleanValue::class); | ||
| } | ||
|
|
||
| public function isStateless(): bool | ||
| { | ||
| return true; | ||
| } | ||
|
|
||
| public function getExpectedTimeOfTaskInSeconds(): int | ||
| { | ||
| return 30; | ||
| } | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.