ILIAS  release_7 Revision v7.30-3-g800a261c036
class.ilMailCronOrphanedMailsDeletionCollector.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{
10 private const PING_THRESHOLD = 500;
11
12 private $job;
16 protected $db;
17
21 protected $settings;
22
26 protected $mail_ids = array();
27
29 {
30 global $DIC;
31
32 $this->settings = $DIC->settings();
33 $this->db = $DIC->database();
34
35 $this->job = $job;
36
37 $this->collect();
38 }
39
43 public function collect()
44 {
45 $mail_only_inbox_trash = (int) $this->settings->get('mail_only_inbox_trash');
46 $last_cron_start_ts = (int) $this->settings->get('last_cronjob_start_ts', time());
47 $mail_notify_orphaned = (int) $this->settings->get('mail_notify_orphaned');
48
49 $now = time();
50
51 if ($mail_notify_orphaned > 0) {
52 if ($last_cron_start_ts != null) {
53 if ($mail_only_inbox_trash) {
54 // überprüfen ob die mail in einen anderen Ordner verschoben wurde
55 // selektiere die, die tatsächlich gelöscht werden sollen
56 $res = $this->db->queryF(
57 "
58 SELECT mail_id FROM mail_cron_orphaned
59 LEFT JOIN mail_obj_data mdata ON mdata.obj_id = folder_id
60 WHERE ts_do_delete <= %s
61 AND ((mdata.m_type = %s OR mdata.m_type = %s) OR mdata.obj_id IS NULL)",
62 array('integer', 'text', 'text'),
63 array($now, 'inbox', 'trash')
64 );
65 } else {
66 // selektiere alle zu löschenden mails unabhängig vom ordner..
67 $res = $this->db->queryF(
68 "
69 SELECT mail_id FROM mail_cron_orphaned
70 WHERE ts_do_delete <= %s",
71 array('integer'),
72 array($now)
73 );
74 }
75
76 while ($row = $this->db->fetchAssoc($res)) {
77 $this->addMailIdToDelete($row['mail_id']);
78 }
79 }
80 } else {
81 // mails sollen direkt ohne vorheriger notification gelöscht werden.
82 $mail_threshold = (int) $this->settings->get('mail_threshold');
83 $ts_notify = strtotime("- " . $mail_threshold . " days");
84 $ts_for_deletion = date('Y-m-d', $ts_notify) . ' 23:59:59';
85
86 $types = array('timestamp');
87 $data = array($ts_for_deletion);
88
89 $mails_query = "
90 SELECT mail_id
91 FROM mail m
92 INNER JOIN mail_obj_data mdata ON obj_id = folder_id
93 WHERE send_time <= %s";
94
95 if ((int) $this->settings->get('mail_only_inbox_trash') > 0) {
96 $mails_query .= " AND (mdata.m_type = %s OR mdata.m_type = %s)";
97 $types = array('timestamp', 'text', 'text');
98 $data = array($ts_for_deletion, 'inbox', 'trash');
99 }
100
101 $i = 0;
102 $res = $this->db->queryF($mails_query, $types, $data);
103 while ($row = $this->db->fetchAssoc($res)) {
104 if ($i > 0 && $i % self::PING_THRESHOLD) {
105 $this->job->ping();
106 }
107
108 $this->addMailIdToDelete($row['mail_id']);
109
110 ++$i;
111 }
112 }
113 }
114
118 public function addMailIdToDelete($mail_id)
119 {
120 $this->mail_ids[] = (int) $mail_id;
121 }
122
126 public function getMailIdsToDelete()
127 {
128 return $this->mail_ids;
129 }
130}
An exception for terminatinating execution or to throw for unit testing.
global $DIC
Definition: goto.php:24
$i
Definition: metadata.php:24
foreach($_POST as $key=> $value) $res
settings()
Definition: settings.php:2
$data
Definition: storeScorm.php:23