ILIAS  trunk Revision v11.0_alpha-2638-g80c1d007f79
class.ilMailDeliveryJob.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
29 
31 {
32  public function run(array $input, Observer $observer): Value
33  {
34  global $DIC;
35 
36  $arguments = array_map(static fn($value) => $value->getValue(), $input);
37 
38  $DIC->logger()->mail()->info('Mail delivery background task executed');
39 
40  $DIC->logger()->mail()->debug(sprintf(
41  'Input: %s',
42  json_encode(array_slice($arguments, 0, 5), JSON_THROW_ON_ERROR | JSON_PRETTY_PRINT)
43  ));
44 
45  $context_parameters = (array) unserialize($input[10]->getValue(), ['allowed_classes' => false]);
46 
47  if ((int) $input[0]->getValue() === ANONYMOUS_USER_ID) {
48  $mail = new ilMail((int) $input[0]->getValue());
49  } else {
50  $mail = new ilFormatMail((int) $input[0]->getValue());
51  }
52 
53  if (isset($context_parameters['auto_responder'])) {
54  if ($context_parameters['auto_responder']) {
55  $mail->autoresponder()->enableAutoresponder();
56  } else {
57  $mail->autoresponder()->disableAutoresponder();
58  }
59  }
60 
61  $mail->setSaveInSentbox((bool) $input[8]->getValue());
62  $mail = $mail
63  ->withContextId((string) $input[9]->getValue())
64  ->withContextParameters($context_parameters);
65 
66  $mail_data = new MailDeliveryData(
67  (string) $input[1]->getValue(), // To
68  (string) $input[2]->getValue(), // Cc
69  (string) $input[3]->getValue(), // Bcc
70  (string) $input[4]->getValue(), // Subject
71  (string) $input[5]->getValue(), // Message
72  (array) unserialize($input[6]->getValue(), ['allowed_classes' => false]), // Attachments
73  (bool) $input[7]->getValue() // Use Placeholders
74  );
75  $mail->sendMail($mail_data);
76 
77  $DIC->logger()->mail()->info('Mail delivery background task finished');
78 
79  $output = new BooleanValue();
80  $output->setValue(true);
81 
82  return $output;
83  }
84 
85  public function getInputTypes(): array
86  {
87  return [
88  new SingleType(IntegerValue::class), // 0. User Id
89  new SingleType(StringValue::class), // 1. To
90  new SingleType(StringValue::class), // 2. CC
91  new SingleType(StringValue::class), // 3. BCC
92  new SingleType(StringValue::class), // 4. Subject
93  new SingleType(StringValue::class), // 5. Message
94  new SingleType(StringValue::class), // 6. Attachments
95  new SingleType(BooleanValue::class), // 7. Use placeholders
96  new SingleType(BooleanValue::class), // 8. Save in sentbox
97  new SingleType(StringValue::class), // 9. Context Id
98  new SingleType(StringValue::class), // 10. Context Parameters
99  ];
100  }
101 
102  public function isStateless(): bool
103  {
104  return true;
105  }
106 
108  {
109  return 30;
110  }
111 
112  public function getOutputType(): Type
113  {
114  return new SingleType(BooleanValue::class);
115  }
116 }
const ANONYMOUS_USER_ID
Definition: constants.php:27
getValue()
Get the value that is displayed in the input client side.
Definition: Group.php:49
global $DIC
Definition: shib_login.php:26
run(array $input, Observer $observer)