ILIAS  release_8 Revision v8.24
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, int $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 $taskManager
 
TaskFactory $taskFactory
 
ilLanguage $language
 
ilLogger $logger
 
ilMailValueObjectJsonService $objectJsonService
 
int $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,
int  $anonymousUserId = ANONYMOUS_USER_ID 
)

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

46 {
47 if (null === $dic) {
48 global $DIC;
49 $dic = $DIC;
50 }
51
52 if (null === $taskManager) {
53 $taskManager = $dic->backgroundTasks()->taskManager();
54 }
55 $this->taskManager = $taskManager;
56
57 if (null === $taskFactory) {
58 $taskFactory = $dic->backgroundTasks()->taskFactory();
59 }
60 $this->taskFactory = $taskFactory;
61
62 if (null === $language) {
63 $language = $dic->language();
64 }
65 $this->language = $language;
66
67 if (null === $logger) {
69 }
70 $this->logger = $logger;
71
72 if (null === $objectJsonService) {
74 }
75 $this->objectJsonService = $objectJsonService;
76
77 $this->anonymousUserId = $anonymousUserId;
78 }
static getLogger(string $a_component_id)
Get component logger.
ilMailValueObjectJsonService $objectJsonService
global $DIC
Definition: feed.php:28
$dic
Definition: result.php:32

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

+ 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 153 of file class.ilMassMailTaskProcessor.php.

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

◆ 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 88 of file class.ilMassMailTaskProcessor.php.

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

◆ runTask()

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

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

141 : void
142 {
143 $bucket = new BasicBucket();
144 $bucket->setUserId($userId);
145
146 $bucket->setTask($task);
147 $bucket->setTitle($this->language->txt('mail_bg_task_title'));
148
149 $this->logger->info('Delegated delivery to background task');
150 $this->taskManager->run($bucket);
151 }

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

+ Here is the call graph for this function:

Field Documentation

◆ $anonymousUserId

int ilMassMailTaskProcessor::$anonymousUserId
private

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

Referenced by __construct().

◆ $language

ilLanguage ilMassMailTaskProcessor::$language
private

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

Referenced by __construct().

◆ $logger

ilLogger ilMassMailTaskProcessor::$logger
private

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

Referenced by __construct().

◆ $objectJsonService

ilMailValueObjectJsonService ilMassMailTaskProcessor::$objectJsonService
private

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

Referenced by __construct().

◆ $taskFactory

TaskFactory ilMassMailTaskProcessor::$taskFactory
private

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

Referenced by __construct().

◆ $taskManager

TaskManager ilMassMailTaskProcessor::$taskManager
private

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

Referenced by __construct().


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