19 declare(strict_types=1);
51 if (
null === $taskManager) {
52 $taskManager =
$dic->backgroundTasks()->taskManager();
56 if (
null === $taskFactory) {
57 $taskFactory =
$dic->backgroundTasks()->taskFactory();
61 if (
null === $language) {
62 $language =
$dic->language();
66 if (
null === $logger) {
71 if (
null === $objectJsonService) {
86 array $mailValueObjects,
89 array $contextParameters,
90 int $mailsPerTask = 100
92 $objectsServiceSize = count($mailValueObjects);
94 if ($objectsServiceSize <= 0) {
95 throw new ilMailException(
'First parameter must contain at least 1 array element');
98 if ($mailsPerTask <= 0) {
101 'The mails per task MUST be a positive integer, "%s" given',
107 foreach ($mailValueObjects as $mailValueObject) {
109 throw new ilMailException(
'Array MUST contain ilMailValueObjects ONLY');
114 $remainingObjects = [];
115 foreach ($mailValueObjects as $mailValueObject) {
118 $remainingObjects[] = $mailValueObject;
119 if ($taskCounter === $mailsPerTask) {
120 $interaction = $this->
createInteraction($userId, $contextId, $contextParameters, $remainingObjects);
122 $this->
runTask($interaction, $userId);
125 $remainingObjects = [];
129 if ([] !== $remainingObjects) {
130 $interaction = $this->
createInteraction($userId, $contextId, $contextParameters, $remainingObjects);
132 $this->
runTask($interaction, $userId);
139 $bucket->setUserId($userId);
141 $bucket->setTask($task);
142 $bucket->setTitle($this->
language->txt(
'mail_bg_task_title'));
144 $this->
logger->info(
'Delegated delivery to background task');
145 $this->taskManager->run($bucket);
151 array $contextParameters,
154 $jsonString = $this->objectJsonService->convertToJson($remainingObjects);
156 $task = $this->taskFactory->createTask(ilMassMailDeliveryJob::class, [
160 serialize($contextParameters),
165 $parameters = [$task, $userId];
167 return $this->taskFactory->createTask(
168 ilMailDeliveryJobUserInteraction::class,
static getLogger(string $a_component_id)
Get component logger.
Interface Observer Contains several chained tasks and infos about them.
createInteraction(int $userId, string $contextId, array $contextParameters, $remainingObjects)
readonly ilLogger $logger
run(array $mailValueObjects, int $userId, string $contextId, array $contextParameters, int $mailsPerTask=100)
Customizing of pimple-DIC for ILIAS.
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
runTask(\ILIAS\BackgroundTasks\Task $task, int $userId)
readonly TaskFactory $taskFactory
__construct(private readonly int $anonymousUserId=ANONYMOUS_USER_ID, ?TaskManager $taskManager=null, ?TaskFactory $taskFactory=null, ?ilLanguage $language=null, ?ilLogger $logger=null, ?Container $dic=null, ?ilMailValueObjectJsonService $objectJsonService=null)
readonly ilMailValueObjectJsonService $objectJsonService
readonly TaskManager $taskManager
language()
description: > Example for rendring a language glyph.
readonly ilLanguage $language