ILIAS  release_7 Revision v7.30-3-g800a261c036
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilMailDeliveryJob.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 
16 {
20  public function run(array $input, Observer $observer)
21  {
22  global $DIC;
23 
24  $arguments = array_map(function ($value) {
25  return $value->getValue();
26  }, $input);
27 
28  $DIC->logger()->mail()->info('Mail delivery background task executed');
29 
30  $DIC->logger()->mail()->debug(sprintf(
31  'Input: %s',
32  json_encode(array_slice($arguments, 0, 5), JSON_THROW_ON_ERROR | JSON_PRETTY_PRINT)
33  ));
34 
35  if ((int) $input[0]->getValue() === (int) ANONYMOUS_USER_ID) {
36  $mail = new ilMail((int) $input[0]->getValue());
37  } else {
38  $mail = new ilFormatMail((int) $input[0]->getValue());
39  }
40  $mail->setSaveInSentbox((bool) $input[8]->getValue());
41  $mail = $mail
42  ->withContextId((string) $input[9]->getValue())
43  ->withContextParameters((array) unserialize($input[10]->getValue()));
44 
45  $mail->sendMail(
46  (string) $input[1]->getValue(), // To
47  (string) $input[2]->getValue(), // Cc
48  (string) $input[3]->getValue(), // Bcc
49  (string) $input[4]->getValue(), // Subject
50  (string) $input[5]->getValue(), // Message
51  (array) unserialize($input[6]->getValue()), // Attachments
52  (bool) $input[7]->getValue() // Use Placeholders
53  );
54 
55  $DIC->logger()->mail()->info('Mail delivery background task finished');
56 
57  $output = new BooleanValue();
58  $output->setValue(true);
59 
60  return $output;
61  }
62 
66  public function getInputTypes()
67  {
68  return [
69  new SingleType(IntegerValue::class), // 0. User Id
70  new SingleType(StringValue::class), // 1. To
71  new SingleType(StringValue::class), // 2. CC
72  new SingleType(StringValue::class), // 3. BCC
73  new SingleType(StringValue::class), // 4. Subject
74  new SingleType(StringValue::class), // 5. Message
75  new SingleType(StringValue::class), // 6. Attachments
76  new SingleType(BooleanValue::class), // 7. Use placeholders
77  new SingleType(BooleanValue::class), // 8. Save in sentbox
78  new SingleType(StringValue::class), // 9. Context Id
79  new SingleType(StringValue::class), // 10. Context Parameters
80  ];
81  }
82 
86  public function isStateless()
87  {
88  return true;
89  }
90 
95  {
96  return 30;
97  }
98 
102  public function getOutputType()
103  {
104  return new SingleType(BooleanValue::class);
105  }
106 }
getInputTypes()
Type[] A list of types that are taken as input.
const ANONYMOUS_USER_ID
Definition: constants.php:25
getOutputType()
Type A single type.
Class ilMailDeliveryJob.
isStateless()
bool returns true iff the job&#39;s output ONLY depends on the input. Stateless task results may be cache...
Class UserMail this class handles user mails.
global $DIC
Definition: goto.php:24
getExpectedTimeOfTaskInSeconds()
int the amount of seconds this task usually taskes. If your task-duration scales with the the amount ...
run(array $input, Observer $observer)