ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
ilMassMailTaskProcessor Class Reference
+ Collaboration diagram for ilMassMailTaskProcessor:

Public Member Functions

 __construct (private readonly int $anonymousUserId=ANONYMOUS_USER_ID, TaskManager $taskManager=null, TaskFactory $taskFactory=null, ilLanguage $language=null, ilLogger $logger=null, Container $dic=null, \ILIAS\Mail\Object\MailPayloadEncoder $payload_encoder=null)
 
 run (array $mailValueObjects, int $userId, string $contextId, array $contextParameters, int $mailsPerTask=100)
 

Private Member Functions

 runTask (\ILIAS\BackgroundTasks\Task $task, int $userId)
 
 createInteraction (int $userId, string $contextId, array $contextParameters, $remainingObjects)
 

Private Attributes

readonly TaskManager $taskManager
 
readonly TaskFactory $taskFactory
 
readonly ilLanguage $language
 
readonly ilLogger $logger
 
readonly ILIAS Mail Object MailPayloadEncoder $payload_encoder
 

Detailed Description

Definition at line 26 of file class.ilMassMailTaskProcessor.php.

Constructor & Destructor Documentation

◆ __construct()

ilMassMailTaskProcessor::__construct ( private readonly int  $anonymousUserId = ANONYMOUS_USER_ID,
TaskManager  $taskManager = null,
TaskFactory  $taskFactory = null,
ilLanguage  $language = null,
ilLogger  $logger = null,
Container  $dic = null,
\ILIAS\Mail\Object\MailPayloadEncoder  $payload_encoder = null 
)

Definition at line 34 of file class.ilMassMailTaskProcessor.php.

References $DIC, $dic, $language, $logger, $payload_encoder, $taskFactory, $taskManager, ilLoggerFactory\getLogger(), ILIAS\UI\examples\Symbol\Glyph\Language\language(), and ILIAS\Repository\logger().

42  {
43  if (null === $dic) {
44  global $DIC;
45  $dic = $DIC;
46  }
47 
48  if (null === $taskManager) {
49  $taskManager = $dic->backgroundTasks()->taskManager();
50  }
51  $this->taskManager = $taskManager;
52 
53  if (null === $taskFactory) {
54  $taskFactory = $dic->backgroundTasks()->taskFactory();
55  }
56  $this->taskFactory = $taskFactory;
57 
58  if (null === $language) {
59  $language = $dic->language();
60  }
61  $this->language = $language;
62 
63  if (null === $logger) {
64  $logger = ilLoggerFactory::getLogger('mail');
65  }
66  $this->logger = $logger;
67 
68  if ($payload_encoder === null) {
70  new ILIAS\Mail\Object\PureJsonMailEncoder(
72  ),
73  new ILIAS\Mail\Transformation\Utf8Mb4Sanitizer()
74  );
75  }
76  $this->payload_encoder = $payload_encoder;
77  }
static getLogger(string $a_component_id)
Get component logger.
Class ChatMainBarProvider .
global $DIC
Definition: feed.php:28
readonly ILIAS Mail Object MailPayloadEncoder $payload_encoder
RFC 822 Email address list validation Utility.
language()
Get interface to the i18n service.
Definition: Container.php:95
+ Here is the call graph for this function:

Member Function Documentation

◆ createInteraction()

ilMassMailTaskProcessor::createInteraction ( int  $userId,
string  $contextId,
array  $contextParameters,
  $remainingObjects 
)
private

Definition at line 150 of file class.ilMassMailTaskProcessor.php.

Referenced by run().

156  $jsonString = $this->payload_encoder->encode($remainingObjects);
157 
158  $task = $this->taskFactory->createTask(ilMassMailDeliveryJob::class, [
159  $userId,
160  $jsonString,
161  $contextId,
162  serialize($contextParameters),
163  ]);
164 
165  // Important: Don't return the task (e.g. as an early return for anonymous user id) https://mantis.ilias.de/view.php?id=33618
166 
167  $parameters = [$task, $userId];
168 
169  return $this->taskFactory->createTask(
170  ilMailDeliveryJobUserInteraction::class,
171  $parameters
172  );
173  }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: Job.php:19
+ Here is the caller graph for this function:

◆ run()

ilMassMailTaskProcessor::run ( array  $mailValueObjects,
int  $userId,
string  $contextId,
array  $contextParameters,
int  $mailsPerTask = 100 
)
Parameters
ilMailValueObject[]$mailValueObjects - One MailValueObject = One Task
int$userId- User ID of the user who executes the background task
string$contextId- context ID of the Background task
array$contextParameters- context parameters for the background tasks
int$mailsPerTask- Defines how many mails will be added before a background task is executed
Exceptions
ilMailException

Definition at line 87 of file class.ilMassMailTaskProcessor.php.

References createInteraction(), and runTask().

93  : void {
94  $objectsServiceSize = count($mailValueObjects);
95 
96  if ($objectsServiceSize <= 0) {
97  throw new ilMailException('First parameter must contain at least 1 array element');
98  }
99 
100  if ($mailsPerTask <= 0) {
101  throw new ilMailException(
102  sprintf(
103  'The mails per task MUST be a positive integer, "%s" given',
104  $mailsPerTask
105  )
106  );
107  }
108 
109  foreach ($mailValueObjects as $mailValueObject) {
110  if (!($mailValueObject instanceof ilMailValueObject)) {
111  throw new ilMailException('Array MUST contain ilMailValueObjects ONLY');
112  }
113  }
114  $taskCounter = 0;
115 
116  $remainingObjects = [];
117  foreach ($mailValueObjects as $mailValueObject) {
118  $taskCounter++;
119 
120  $remainingObjects[] = $mailValueObject;
121  if ($taskCounter === $mailsPerTask) {
122  $interaction = $this->createInteraction($userId, $contextId, $contextParameters, $remainingObjects);
123 
124  $this->runTask($interaction, $userId);
125 
126  $taskCounter = 0;
127  $remainingObjects = [];
128  }
129  }
130 
131  if ([] !== $remainingObjects) {
132  $interaction = $this->createInteraction($userId, $contextId, $contextParameters, $remainingObjects);
133 
134  $this->runTask($interaction, $userId);
135  }
136  }
createInteraction(int $userId, string $contextId, array $contextParameters, $remainingObjects)
runTask(\ILIAS\BackgroundTasks\Task $task, int $userId)
+ Here is the call graph for this function:

◆ runTask()

ilMassMailTaskProcessor::runTask ( \ILIAS\BackgroundTasks\Task  $task,
int  $userId 
)
private

Definition at line 138 of file class.ilMassMailTaskProcessor.php.

References ILIAS\UI\examples\Symbol\Glyph\Language\language(), and ILIAS\Repository\logger().

Referenced by run().

138  : void
139  {
140  $bucket = new BasicBucket();
141  $bucket->setUserId($userId);
142 
143  $bucket->setTask($task);
144  $bucket->setTitle($this->language->txt('mail_bg_task_title'));
145 
146  $this->logger->info('Delegated delivery to background task');
147  $this->taskManager->run($bucket);
148  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Field Documentation

◆ $language

readonly ilLanguage ilMassMailTaskProcessor::$language
private

Definition at line 30 of file class.ilMassMailTaskProcessor.php.

Referenced by __construct().

◆ $logger

readonly ilLogger ilMassMailTaskProcessor::$logger
private

Definition at line 31 of file class.ilMassMailTaskProcessor.php.

Referenced by __construct().

◆ $payload_encoder

readonly ILIAS Mail Object MailPayloadEncoder ilMassMailTaskProcessor::$payload_encoder
private

Definition at line 32 of file class.ilMassMailTaskProcessor.php.

Referenced by __construct().

◆ $taskFactory

readonly TaskFactory ilMassMailTaskProcessor::$taskFactory
private

Definition at line 29 of file class.ilMassMailTaskProcessor.php.

Referenced by __construct().

◆ $taskManager

readonly TaskManager ilMassMailTaskProcessor::$taskManager
private

Definition at line 28 of file class.ilMassMailTaskProcessor.php.

Referenced by __construct().


The documentation for this class was generated from the following file: