ILIAS  release_7 Revision v7.30-3-g800a261c036
ilMassMailTaskProcessor Class Reference
+ Collaboration diagram for ilMassMailTaskProcessor:

Public Member Functions

 __construct (TaskManager $taskManager=null, TaskFactory $taskFactory=null, ilLanguage $language=null, ilLogger $logger=null, Container $dic=null, ilMailValueObjectJsonService $objectJsonService=null, string $anonymousUserId=ANONYMOUS_USER_ID)
 
 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

 $taskManager
 
 $taskFactory
 
 $language
 
 $logger
 
 $objectJsonService
 
 $anonymousUserId
 

Detailed Description

Constructor & Destructor Documentation

◆ __construct()

ilMassMailTaskProcessor::__construct ( TaskManager  $taskManager = null,
TaskFactory  $taskFactory = null,
ilLanguage  $language = null,
ilLogger  $logger = null,
Container  $dic = null,
ilMailValueObjectJsonService  $objectJsonService = null,
string  $anonymousUserId = ANONYMOUS_USER_ID 
)
Parameters
TaskManager$taskManager
TaskFactory | null$taskFactory
ilLanguage | null$language
ilLogger | null$logger
Container | null$dic
ilMailValueObjectJsonService | null$objectJsonService
string$anonymousUserId

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

61 {
62 if (null === $dic) {
63 global $DIC;
64 $dic = $DIC;
65 }
66
67 if (null === $taskManager) {
68 $taskManager = $dic->backgroundTasks()->taskManager();
69 }
70 $this->taskManager = $taskManager;
71
72 if (null === $taskFactory) {
73 $taskFactory = $dic->backgroundTasks()->taskFactory();
74 }
75 $this->taskFactory = $taskFactory;
76
77 if (null === $language) {
78 $language = $dic->language();
79 }
80 $this->language = $language;
81
82 if (null === $logger) {
84 }
85 $this->logger = $logger;
86
87 if (null === $objectJsonService) {
89 }
90 $this->objectJsonService = $objectJsonService;
91
92 $this->anonymousUserId = $anonymousUserId;
93 }
static getLogger($a_component_id)
Get component logger.
global $DIC
Definition: goto.php:24
language()
Definition: language.php:2
$dic
Definition: result.php:13

References $anonymousUserId, $DIC, $dic, $language, $logger, $objectJsonService, $taskFactory, $taskManager, ilLoggerFactory\getLogger(), and language().

+ Here is the call graph for this function:

Member Function Documentation

◆ createInteraction()

ilMassMailTaskProcessor::createInteraction ( int  $userId,
string  $contextId,
array  $contextParameters,
  $remainingObjects 
)
private
Parameters
int$userId
string$contextId
array$contextParameters
$remainingObjects
Returns
\ILIAS\BackgroundTasks\Task

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

180 $jsonString = $this->objectJsonService->convertToJson($remainingObjects);
181
182 $task = $this->taskFactory->createTask(\ilMassMailDeliveryJob::class, [
183 (int) $userId,
184 (string) $jsonString,
185 (string) $contextId,
186 (string) serialize($contextParameters),
187 ]);
188
189 // Important: Don't return the task (e.g. as an early return for anonymous user id) https://mantis.ilias.de/view.php?id=33618
190
191 $parameters = [$task, (int) $userId];
192
193 $interaction = $this->taskFactory->createTask(
194 \ilMailDeliveryJobUserInteraction::class,
195 $parameters
196 );
197
198 return $interaction;
199 }

Referenced by run().

+ 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
ilException

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

109 {
110 $objectsServiceSize = sizeof($mailValueObjects);
111
112 if ($objectsServiceSize <= 0) {
113 throw new ilException('First parameter must contain at least 1 array element');
114 }
115
116 if ($mailsPerTask <= 0) {
117 throw new ilException(sprintf('The mails per task MUST be a positive integer, "%s" given', $mailsPerTask));
118 }
119
120 foreach ($mailValueObjects as $mailValueObject) {
121 if (false === ($mailValueObject instanceof ilMailValueObject)) {
122 throw new ilException('Array MUST contain ilMailValueObjects ONLY');
123 }
124 }
125
126 $lastTask = null;
127 $taskCounter = 0;
128
129 $remainingObjects = array();
130 foreach ($mailValueObjects as $mailValueObject) {
131 $taskCounter++;
132
133 $remainingObjects[] = $mailValueObject;
134 if ($taskCounter === $mailsPerTask) {
135 $interaction = $this->createInteraction($userId, $contextId, $contextParameters, $remainingObjects);
136
137 $this->runTask($interaction, $userId);
138
139 $taskCounter = 0;
140 $remainingObjects = array();
141 }
142 }
143
144 if (array() !== $remainingObjects) {
145 $interaction = $this->createInteraction($userId, $contextId, $contextParameters, $remainingObjects);
146
147 $this->runTask($interaction, $userId);
148 }
149 }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
createInteraction(int $userId, string $contextId, array $contextParameters, $remainingObjects)
runTask(\ILIAS\BackgroundTasks\Task $task, int $userId)

References createInteraction(), and runTask().

+ Here is the call graph for this function:

◆ runTask()

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

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

156 {
157 $bucket = new BasicBucket();
158 $bucket->setUserId($userId);
159
160 $bucket->setTask($task);
161 $bucket->setTitle($this->language->txt('mail_bg_task_title'));
162
163 $this->logger->info('Delegated delivery to background task');
164 $this->taskManager->run($bucket);
165 }

References language().

Referenced by run().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Field Documentation

◆ $anonymousUserId

ilMassMailTaskProcessor::$anonymousUserId
private

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

Referenced by __construct().

◆ $language

ilMassMailTaskProcessor::$language
private

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

Referenced by __construct().

◆ $logger

ilMassMailTaskProcessor::$logger
private

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

Referenced by __construct().

◆ $objectJsonService

ilMassMailTaskProcessor::$objectJsonService
private

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

Referenced by __construct().

◆ $taskFactory

ilMassMailTaskProcessor::$taskFactory
private

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

Referenced by __construct().

◆ $taskManager

ilMassMailTaskProcessor::$taskManager
private

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

Referenced by __construct().


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