ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.ilMailCronOrphanedMails.php
Go to the documentation of this file.
1<?php
2
3/* Copyright (c) 1998-2015 ILIAS open source, Extended GPL, see docs/LICENSE */
4
5include_once "./Services/Cron/classes/class.ilCronJob.php";
6include_once "./Services/Cron/classes/class.ilCronJobResult.php";
7require_once './Services/Logging/classes/public/class.ilLoggerFactory.php';
8
15{
19 protected $lng;
20
24 protected $settings;
25
29 protected $db;
30
34 protected $user;
35
39 protected $initDone = false;
40
44 protected function init()
45 {
46 global $DIC;
47
48 if (!$this->initDone) {
49 $this->settings = $DIC->settings();
50 $this->lng = $DIC->language();
51 $this->db = $DIC->database();
52 $this->user = $DIC->user();
53
54 $this->lng->loadLanguageModule('mail');
55 $this->initDone = true;
56 }
57 }
58
63 public function getId()
64 {
65 return "mail_orphaned_mails";
66 }
67
71 public function getTitle()
72 {
73 $this->init();
74 return $this->lng->txt("mail_orphaned_mails");
75 }
76
80 public function getDescription()
81 {
82 $this->init();
83 return $this->lng->txt("mail_orphaned_mails_desc");
84 }
85
90 public function hasAutoActivation()
91 {
92 return false;
93 }
94
99 public function hasFlexibleSchedule()
100 {
101 return true;
102 }
103
107 public function getValidScheduleTypes()
108 {
109 return array(
110 self::SCHEDULE_TYPE_DAILY,
111 self::SCHEDULE_TYPE_WEEKLY,
112 self::SCHEDULE_TYPE_MONTHLY,
113 self::SCHEDULE_TYPE_QUARTERLY,
114 self::SCHEDULE_TYPE_YEARLY,
115 self::SCHEDULE_TYPE_IN_DAYS
116 );
117 }
118
123 public function getDefaultScheduleType()
124 {
126 }
127
132 public function getDefaultScheduleValue()
133 {
134 return 1;
135 }
136
140 public function hasCustomSettings()
141 {
142 return true;
143 }
144
149 {
150 $this->init();
151 parent::addCustomSettingsToForm($a_form);
152
153 $threshold = new ilNumberInputGUI($this->lng->txt('mail_threshold'), 'mail_threshold');
154 $threshold->setInfo($this->lng->txt('mail_threshold_info'));
155 $threshold->allowDecimals(false);
156 $threshold->setSuffix($this->lng->txt('days'));
157 $threshold->setMinValue(1);
158 $threshold->setValue($this->settings->get('mail_threshold'));
159
160 $a_form->addItem($threshold);
161
162 $mail_folder = new ilCheckboxInputGUI($this->lng->txt('only_inbox_trash'), 'mail_only_inbox_trash');
163 $mail_folder->setInfo($this->lng->txt('only_inbox_trash_info'));
164 $mail_folder->setChecked($this->settings->get('mail_only_inbox_trash'));
165 $a_form->addItem($mail_folder);
166
167 $notification = new ilNumberInputGUI($this->lng->txt('mail_notify_orphaned'), 'mail_notify_orphaned');
168 $notification->setInfo($this->lng->txt('mail_notify_orphaned_info'));
169 $notification->allowDecimals(false);
170 $notification->setSuffix($this->lng->txt('days'));
171 $notification->setMinValue(0);
172
173 $mail_threshold = isset($_POST['mail_threshold']) ? (int) $_POST['mail_threshold'] : $this->settings->get('mail_threshold');
174 $maxvalue = $mail_threshold - 1;
175 $notification->setMaxValue($maxvalue);
176 $notification->setValue($this->settings->get('mail_notify_orphaned'));
177 $a_form->addItem($notification);
178 }
179
184 public function saveCustomSettings(ilPropertyFormGUI $a_form)
185 {
186 $this->init();
187 $this->settings->set('mail_threshold', (int) $a_form->getInput('mail_threshold'));
188 $this->settings->set('mail_only_inbox_trash', (int) $a_form->getInput('mail_only_inbox_trash'));
189 $this->settings->set('mail_notify_orphaned', (int) $a_form->getInput('mail_notify_orphaned'));
190
191 if ($this->settings->get('mail_notify_orphaned') == 0) {
192 //delete all mail_cron_orphaned-table entries!
193 $this->db->manipulate('DELETE FROM mail_cron_orphaned');
194
195 ilLoggerFactory::getLogger('mail')->info(sprintf(
196 "Deleted all scheduled mail deletions because a reminder should't be sent (login: %s|usr_id: %s) anymore!",
197 $this->user->getLogin(),
198 $this->user->getId()
199 ));
200 }
201
202 return true;
203 }
204
209 public function run()
210 {
211 $this->init();
212 $mail_threshold = (int) $this->settings->get('mail_threshold');
213
214 ilLoggerFactory::getLogger('mail')->info(sprintf(
215 'Started mail deletion job with threshold: %s day(s)',
216 var_export($mail_threshold, 1)
217 ));
218
219 if ((int) $this->settings->get('mail_notify_orphaned') >= 1 && $mail_threshold >= 1) {
220 $this->processNotification();
221 }
222
223 if ((int) $this->settings->get('last_cronjob_start_ts', time()) && $mail_threshold >= 1) {
224 $this->processDeletion();
225 }
226
227 $result = new ilCronJobResult();
229 $result->setStatus($status);
230
231 ilLoggerFactory::getLogger('mail')->info(sprintf(
232 'Finished mail deletion job with threshold: %s day(s)',
233 var_export($mail_threshold, 1)
234 ));
235
236 return $result;
237 }
238
239 private function processNotification()
240 {
241 $this->init();
242 include_once './Services/Mail/classes/class.ilMailCronOrphanedMailsNotificationCollector.php';
244
245 include_once'./Services/Mail/classes/class.ilMailCronOrphanedMailsNotifier.php';
246 $notifier = new ilMailCronOrphanedMailsNotifier(
247 $collector,
248 (int) $this->settings->get('mail_threshold'),
249 (int) $this->settings->get('mail_notify_orphaned')
250 );
251 $notifier->processNotification();
252 }
253
254 private function processDeletion()
255 {
256 $this->init();
257 include_once './Services/Mail/classes/class.ilMailCronOrphanedMailsDeletionCollector.php';
259
260 include_once './Services/Mail/classes/class.ilMailCronOrphanedMailsDeletionProcessor.php';
261 $processor = new ilMailCronOrphanedMailsDeletionProcessor($collector);
262 $processor->processDeletion();
263 }
264}
$result
user()
Definition: user.php:4
$_POST["username"]
An exception for terminatinating execution or to throw for unit testing.
This class represents a checkbox property in a property form.
Cron job result data container.
Cron job application base class.
const SCHEDULE_TYPE_DAILY
static getLogger($a_component_id)
Get component logger.
addCustomSettingsToForm(ilPropertyFormGUI $a_form)
getValidScheduleTypes()
Returns a collection of all valid schedule types for a specific job.int[]
hasFlexibleSchedule()
Can the schedule be configured?
getDefaultScheduleValue()
Get schedule value.
saveCustomSettings(ilPropertyFormGUI $a_form)
hasAutoActivation()
Is to be activated on "installation".
This class represents a number property in a property form.
This class represents a property form user interface.
addItem($a_item)
Add Item (Property, SectionHeader).
getInput($a_post_var, $ensureValidation=true)
Returns the value of a HTTP-POST variable, identified by the passed id.
global $DIC
Definition: saml.php:7
settings()
Definition: settings.php:2