ILIAS  release_7 Revision v7.30-3-g800a261c036
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilMailCronOrphanedMailsNotificationCollector.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2015 ILIAS open source, Extended GPL, see docs/LICENSE */
3 include_once './Services/Mail/classes/class.ilMailCronOrphanedMailsNotificationCollectionObj.php';
4 include_once './Services/Mail/classes/class.ilMailCronOrphanedMailsFolderObject.php';
5 include_once './Services/Mail/classes/class.ilMailCronOrphanedMailsFolderMailObject.php';
6 
12 {
13  private const PING_THRESHOLD = 500;
17  protected $collection = array();
18 
22  protected $db;
23 
27  protected $setting;
28  private $job;
29 
31  {
32  global $DIC;
33 
34  $this->db = $DIC->database();
35  $this->setting = $DIC->settings();
36 
37  $this->job = $job;
38 
39  $this->collect();
40  }
41 
45  public function collect()
46  {
47  $mail_notify_orphaned = (int) $this->setting->get('mail_notify_orphaned');
48  $mail_threshold = (int) $this->setting->get('mail_threshold');
49 
50  if ($mail_threshold > $mail_notify_orphaned) {
51  $notify_days_before = $mail_threshold - $mail_notify_orphaned;
52  } else {
53  $notify_days_before = 1;
54  }
55 
56  $ts_notify = strtotime("- " . $notify_days_before . " days");
57  $ts_for_notification = date('Y-m-d', $ts_notify) . ' 23:59:59';
58 
59  $types = array('timestamp');
60  $data = array($ts_for_notification);
61 
62  $notification_query = "
63  SELECT m.mail_id, m.user_id, m.folder_id, m.send_time, m.m_subject, mdata.title
64  FROM mail m
65  LEFT JOIN mail_obj_data mdata ON mdata.obj_id = m.folder_id
66  LEFT JOIN mail_cron_orphaned mco ON mco.mail_id = m.mail_id
67  WHERE mco.mail_id IS NULL AND m.send_time <= %s
68  ";
69 
70  if ((int) $this->setting->get('mail_only_inbox_trash') > 0) {
71  $notification_query .= " AND ((mdata.m_type = %s OR mdata.m_type = %s) OR mdata.obj_id IS NULL)";
72  $types = array('timestamp', 'text', 'text');
73  $data = array($ts_for_notification, 'inbox', 'trash');
74  }
75 
76  $notification_query .= " ORDER BY m.user_id, m.folder_id, m.mail_id";
77 
78  $collection_obj = null;
79 
80  $res = $this->db->queryF($notification_query, $types, $data);
81  $i = 0;
82  while ($row = $this->db->fetchAssoc($res)) {
83  if ($i > 0 && $i % self::PING_THRESHOLD === 0) {
84  $this->job->ping();
85  }
86 
87  if ($collection_obj !== null && !$this->existsCollectionObjForUserId($row['user_id'])) {
88  // The user changed, so we'll have to set the collection to NULL after adding it to the queue
89  $collection_obj = null;
90  }
91 
92  if ($collection_obj === null) {
93  // For the first user or if the user changed, we'll create a new collection object
94  $collection_obj = new ilMailCronOrphanedMailsNotificationCollectionObj($row['user_id']);
95  $this->addCollectionObject($collection_obj);
96  }
97 
98  $folder_obj = $collection_obj->getFolderObjectById($row['folder_id']);
99  if (!$folder_obj) {
100  $folder_obj = new ilMailCronOrphanedMailsFolderObject($row['folder_id']);
101  $folder_obj->setFolderTitle($row['title']);
102  $collection_obj->addFolderObject($folder_obj);
103  }
104 
105  $orphaned_mail_obj = new ilMailCronOrphanedMailsFolderMailObject($row['mail_id'], $row['m_subject']);
106  $folder_obj->addMailObject($orphaned_mail_obj);
107  ++$i;
108  }
109  }
110 
115  {
116  $this->collection[$collection_obj->getUserId()] = $collection_obj;
117  }
118 
123  private function existsCollectionObjForUserId($user_id)
124  {
125  if (isset($this->collection[$user_id])) {
126  return true;
127  }
128 
129  return false;
130  }
131 
135  public function getCollection()
136  {
137  return $this->collection;
138  }
139 }
$data
Definition: storeScorm.php:23
addCollectionObject(ilMailCronOrphanedMailsNotificationCollectionObj $collection_obj)
foreach($_POST as $key=> $value) $res
global $DIC
Definition: goto.php:24
$i
Definition: metadata.php:24