ILIAS  trunk Revision v11.0_alpha-1744-gb0451eebef4
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
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, ?ilMailValueObjectJsonService $objectJsonService=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 ilMailValueObjectJsonService $objectJsonService
 

Detailed Description

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,
?ilMailValueObjectJsonService  $objectJsonService = null 
)

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

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

45  {
46  if (null === $dic) {
47  global $DIC;
48  $dic = $DIC;
49  }
50 
51  if (null === $taskManager) {
52  $taskManager = $dic->backgroundTasks()->taskManager();
53  }
54  $this->taskManager = $taskManager;
55 
56  if (null === $taskFactory) {
57  $taskFactory = $dic->backgroundTasks()->taskFactory();
58  }
59  $this->taskFactory = $taskFactory;
60 
61  if (null === $language) {
62  $language = $dic->language();
63  }
64  $this->language = $language;
65 
66  if (null === $logger) {
68  }
69  $this->logger = $logger;
70 
71  if (null === $objectJsonService) {
73  }
74  $this->objectJsonService = $objectJsonService;
75  }
static getLogger(string $a_component_id)
Get component logger.
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
global $DIC
Definition: shib_login.php:22
readonly ilMailValueObjectJsonService $objectJsonService
$dic
Definition: result.php:31
language()
description: > Example for rendring a language glyph.
Definition: language.php:41
+ 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 148 of file class.ilMassMailTaskProcessor.php.

Referenced by run().

154  $jsonString = $this->objectJsonService->convertToJson($remainingObjects);
155 
156  $task = $this->taskFactory->createTask(ilMassMailDeliveryJob::class, [
157  $userId,
158  $jsonString,
159  $contextId,
160  serialize($contextParameters),
161  ]);
162 
163  // Important: Don't return the task (e.g. as an early return for anonymous user id) https://mantis.ilias.de/view.php?id=33618
164 
165  $parameters = [$task, $userId];
166 
167  return $this->taskFactory->createTask(
168  ilMailDeliveryJobUserInteraction::class,
169  $parameters
170  );
171  }
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 85 of file class.ilMassMailTaskProcessor.php.

References createInteraction(), and runTask().

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

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

Referenced by run().

136  : void
137  {
138  $bucket = new BasicBucket();
139  $bucket->setUserId($userId);
140 
141  $bucket->setTask($task);
142  $bucket->setTitle($this->language->txt('mail_bg_task_title'));
143 
144  $this->logger->info('Delegated delivery to background task');
145  $this->taskManager->run($bucket);
146  }
language()
description: > Example for rendring a language glyph.
Definition: language.php:41
+ 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 33 of file class.ilMassMailTaskProcessor.php.

Referenced by __construct().

◆ $logger

readonly ilLogger ilMassMailTaskProcessor::$logger
private

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

Referenced by __construct().

◆ $objectJsonService

readonly ilMailValueObjectJsonService ilMassMailTaskProcessor::$objectJsonService
private

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

Referenced by __construct().

◆ $taskFactory

readonly TaskFactory ilMassMailTaskProcessor::$taskFactory
private

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

Referenced by __construct().

◆ $taskManager

readonly 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: