ILIAS  release_7 Revision v7.30-3-g800a261c036
class.ilMailCronOrphanedMailsNotifier.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2015 ILIAS open source, Extended GPL, see docs/LICENSE */
3
9{
11 private const MAIL_DELIVERY_PING_THRESHOLD = 25;
12
13 private $job;
17 protected $collector;
18
22 protected $db;
23
27 protected $threshold = 0;
28
32 protected $mail_notify_orphaned = 0;
34
42 {
43 global $DIC;
44
45 $this->db = $DIC->database();
46
47 $this->job = $job;
48 $this->collector = $collector;
49 $this->threshold = $threshold;
50 $this->mail_notify_orphaned = $mail_notify_orphaned;
51
52 $this->mark_as_notified_stmt = $this->db->prepareManip(
53 'INSERT INTO mail_cron_orphaned (mail_id, folder_id, ts_do_delete) VALUES (?, ?, ?)',
55 );
56 }
57
62 {
63 if ($this->threshold > $this->mail_notify_orphaned) {
64 $notify_days_before = $this->threshold - $this->mail_notify_orphaned;
65 } else {
66 $notify_days_before = 1;
67 }
68
69 $ts_delete = strtotime("+ " . $notify_days_before . " days");
70 $ts_for_deletion = mktime(0, 0, 0, date('m', $ts_delete), date('d', $ts_delete), date('Y', $ts_delete));
71
72 $i = 0;
73 foreach ($collection_obj->getFolderObjects() as $folder_obj) {
74 $folder_id = $folder_obj->getFolderId();
75
76 foreach ($folder_obj->getOrphanedMailObjects() as $mail_obj) {
77 $mail_id = $mail_obj->getMailId();
78
79 if ($i > 0 && $i % self::NOTIFICATION_MARKER_PING_THRESHOLD === 0) {
80 $this->job->ping();
81 }
82
83 $this->db->execute(
84 $this->mark_as_notified_stmt,
85 [$mail_id, $folder_id, $ts_for_deletion]
86 );
87 $i++;
88 }
89 }
90 }
91
96 {
97 include_once './Services/Mail/classes/class.ilMailCronOrphanedMailsNotification.php';
99
100 $mail->setRecipients(array($collection_obj->getUserId()));
101 $mail->setAdditionalInformation(array('mail_folders' => $collection_obj->getFolderObjects()));
102 $mail->send();
103 }
104
108 public function processNotification()
109 {
110 $i = 0;
111 foreach ($this->collector->getCollection() as $collection_obj) {
112 if ($i > 0 && $i % self::MAIL_DELIVERY_PING_THRESHOLD === 0) {
113 $this->job->ping();
114 }
115
116 $this->sendMail($collection_obj);
117 $this->markAsNotified($collection_obj);
118 ++$i;
119 }
120 }
121}
An exception for terminatinating execution or to throw for unit testing.
markAsNotified(ilMailCronOrphanedMailsNotificationCollectionObj $collection_obj)
sendMail(ilMailCronOrphanedMailsNotificationCollectionObj $collection_obj)
__construct(ilMailCronOrphanedMails $job, ilMailCronOrphanedMailsNotificationCollector $collector, $threshold, $mail_notify_orphaned)
ilMailCronOrphanedMailsNotifier constructor.
global $DIC
Definition: goto.php:24
$i
Definition: metadata.php:24