ILIAS  release_7 Revision v7.30-3-g800a261c036
class.ilMassMailDeliveryJob.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2019 ILIAS open source, Extended GPL, see docs/LICENSE */
3
10
15{
19 private $dic;
20
25
31 public function __construct()
32 {
33 global $DIC;
34 $this->dic = $DIC;
35
36 $this->mailJsonService = new ilMailValueObjectJsonService();
37 }
38
43 public function run(array $input, Observer $observer)
44 {
45 $mailValueObjects = $this->mailJsonService->convertFromJson((string) $input[1]->getValue());
46
47 foreach ($mailValueObjects as $mailValueObject) {
48 $mail = new ilMail((int) $input[0]->getValue());
49
50 $mail->setSaveInSentbox((bool) $mailValueObject->shouldSaveInSentBox());
51 $contextId = $input[2]->getValue();
52 $mail = $mail
53 ->withContextId((string) $contextId)
54 ->withContextParameters((array) unserialize($input[3]->getValue()));
55
56 $recipients = (string) $mailValueObject->getRecipients();
57 $recipientsCC = (string) $mailValueObject->getRecipientsCC();
58 $recipientsBCC = (string) $mailValueObject->getRecipientsBCC();
59
60 $this->dic->logger()->mail()->info(
61 sprintf(
62 'Mail delivery to recipients: "%s" CC: "%s" BCC: "%s" From sender: "%s"',
63 $recipients,
64 $recipientsCC,
65 $recipientsBCC,
66 $mailValueObject->getFrom()
67 )
68 );
69
70 $mail->sendMail(
71 $recipients,
72 $recipientsCC,
73 $recipientsBCC,
74 (string) $mailValueObject->getSubject(),
75 (string) $mailValueObject->getBody(),
76 (array) $mailValueObject->getAttachments(),
77 (bool) $mailValueObject->isUsingPlaceholders()
78 );
79 }
80
81 $output = new BooleanValue();
82 $output->setValue(true);
83
84 return $output;
85 }
86
90 public function getInputTypes()
91 {
92 return [
93 new SingleType(IntegerValue::class), // User Id
94 new SingleType(StringValue::class), // JSON encoded array of ilMailValueObject
95 new SingleType(StringValue::class), // Context Id
96 new SingleType(StringValue::class), // Context Parameters
97 ];
98 }
99
103 public function isStateless()
104 {
105 return true;
106 }
107
112 {
113 return 42; // The answer to life, universe and the rest
114 }
115
119 public function getOutputType()
120 {
121 return new SingleType(BooleanValue::class);
122 }
123}
An exception for terminatinating execution or to throw for unit testing.
getExpectedTimeOfTaskInSeconds()
int the amount of seconds this task usually taskes. If your task-duration scales with the the amount ...
isStateless()
bool returns true iff the job's output ONLY depends on the input. Stateless task results may be cache...
__construct()
ilMassMailDeliveryJob constructor.
getInputTypes()
Type[] A list of types that are taken as input.
run(array $input, Observer $observer)
Value The returned Value must be of the type hinted by getOutputType.
global $DIC
Definition: goto.php:24