ILIAS  release_8 Revision v8.24
Notifier.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
25use ReportDto;
30
32{
34 private const MAIL_DELIVERY_PING_THRESHOLD = 25;
35
43
44 public function __construct(
49 ?ilDBInterface $db = null,
51 ) {
52 global $DIC;
53
54 $this->db = $db ?? $DIC->database();
55 $this->clock = $clock ?? (new Factory())->clock()->system();
56
57 $this->job = $job;
58 $this->collector = $collector;
59 $this->mail_expiration_days = $mail_expiration_days;
60 $this->mail_expiration_warning_days = $mail_expiration_warning_days;
61
62 $this->mark_as_notified_stmt = $this->db->prepareManip(
63 'INSERT INTO mail_cron_orphaned (mail_id, folder_id, ts_do_delete) VALUES (?, ?, ?)',
65 );
66 }
67
68 private function markAsNotified(ReportDto $collection_obj): void
69 {
70 $notify_days_before = 1;
71 if ($this->mail_expiration_days > $this->mail_expiration_warning_days) {
72 $notify_days_before = $this->mail_expiration_days - $this->mail_expiration_warning_days;
73 }
74
75 $deletion_datetime = $this->clock->now()
76 ->modify('+ ' . $notify_days_before . ' days')
77 ->setTime(0, 0);
78
79 $i = 0;
80 foreach ($collection_obj->getFolderObjects() as $folder_obj) {
81 $folder_id = $folder_obj->getFolderId();
82
83 foreach ($folder_obj->getOrphanedMailObjects() as $mail_obj) {
84 $mail_id = $mail_obj->getMailId();
85
86 if ($i > 0 && $i % self::NOTIFICATION_MARKER_PING_THRESHOLD === 0) {
87 $this->job->ping();
88 }
89
90 $this->db->execute(
91 $this->mark_as_notified_stmt,
92 [$mail_id, $folder_id, $deletion_datetime->getTimestamp()]
93 );
94 $i++;
95 }
96 }
97 }
98
99 private function sendMail(ReportDto $collection_obj): void
100 {
101 $mail = new MailNotification();
102 $mail->setRecipients([$collection_obj->getUserId()]);
103 $mail->setAdditionalInformation(['mail_folders' => $collection_obj->getFolderObjects()]);
104 $mail->send();
105 }
106
107 public function send(): void
108 {
109 $i = 0;
110 foreach ($this->collector->getCollection() as $collection_obj) {
111 if ($i > 0 && $i % self::MAIL_DELIVERY_PING_THRESHOLD === 0) {
112 $this->job->ping();
113 }
114
115 $this->sendMail($collection_obj);
116 $this->markAsNotified($collection_obj);
117 ++$i;
118 }
119 }
120}
Builds data types.
Definition: Factory.php:21
__construct(ilMailCronOrphanedMails $job, NotificationsCollector $collector, int $mail_expiration_days, int $mail_expiration_warning_days, ?ilDBInterface $db=null, ?ClockInterface $clock=null)
Definition: Notifier.php:44
markAsNotified(ReportDto $collection_obj)
Definition: Notifier.php:68
getFolderObjects()
Definition: ReportDto.php:52
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
global $DIC
Definition: feed.php:28
Interface ilDBInterface.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$i
Definition: metadata.php:41