ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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 
5 include_once "./Services/Cron/classes/class.ilCronJob.php";
6 include_once "./Services/Cron/classes/class.ilCronJobResult.php";
7 require_once './Services/Logging/classes/public/class.ilLoggerFactory.php';
8 
15 {
19  public function __construct()
20  {
21  global $lng;
22  $lng->loadLanguageModule('mail');
23  }
24 
29  public function getId()
30  {
31  return "mail_orphaned_mails";
32  }
33 
37  public function getTitle()
38  {
39  global $lng;
40  return $lng->txt("mail_orphaned_mails");
41  }
42 
46  public function getDescription()
47  {
48  global $lng;
49  return $lng->txt("mail_orphaned_mails_desc");
50  }
51 
56  public function hasAutoActivation()
57  {
58  return false;
59  }
60 
65  public function hasFlexibleSchedule()
66  {
67  return false;
68  }
69 
74  public function getDefaultScheduleType()
75  {
76  return self::SCHEDULE_TYPE_DAILY;
77  }
78 
83  public function getDefaultScheduleValue()
84  {
85  return;
86  }
87 
91  public function hasCustomSettings()
92  {
93  return true;
94  }
95 
99  public function addCustomSettingsToForm(ilPropertyFormGUI $a_form)
100  {
101  global $ilSetting, $lng;
102 
103  parent::addCustomSettingsToForm($a_form);
104 
105  $threshold = new ilNumberInputGUI($lng->txt('mail_threshold'), 'mail_threshold');
106  $threshold->setInfo($lng->txt('mail_threshold_info'));
107  $threshold->allowDecimals(false);
108  $threshold->setSuffix($lng->txt('days'));
109  $threshold->setMinValue(1);
110  $threshold->setValue($ilSetting->get('mail_threshold'));
111 
112  $a_form->addItem($threshold);
113 
114  $mail_folder = new ilCheckboxInputGUI($lng->txt('only_inbox_trash'), 'mail_only_inbox_trash');
115  $mail_folder->setInfo($lng->txt('only_inbox_trash_info'));
116  $mail_folder->setChecked($ilSetting->get('mail_only_inbox_trash'));
117  $a_form->addItem($mail_folder);
118 
119  $notification = new ilNumberInputGUI($lng->txt('mail_notify_orphaned'), 'mail_notify_orphaned');
120  $notification->setInfo($lng->txt('mail_notify_orphaned_info'));
121  $notification->allowDecimals(false);
122  $notification->setSuffix($lng->txt('days'));
123  $notification->setMinValue(0);
124 
125  $mail_threshold = isset($_POST['mail_threshold']) ? (int)$_POST['mail_threshold'] : $ilSetting->get('mail_threshold');
126  $maxvalue = $mail_threshold-1;
127  $notification->setMaxValue($maxvalue);
128  $notification->setValue($ilSetting->get('mail_notify_orphaned'));
129  $a_form->addItem($notification);
130  }
131 
136  public function saveCustomSettings(ilPropertyFormGUI $a_form)
137  {
138  global $ilSetting, $ilUser;
139 
140  $ilSetting->set('mail_threshold', (int)$a_form->getInput('mail_threshold'));
141  $ilSetting->set('mail_only_inbox_trash', (int)$a_form->getInput('mail_only_inbox_trash'));
142  $ilSetting->set('mail_notify_orphaned', (int)$a_form->getInput('mail_notify_orphaned'));
143 
144  if($ilSetting->get('mail_notify_orphaned') == 0)
145  {
146  global $ilDB;
147  //delete all mail_cron_orphaned-table entries!
148  $ilDB->manipulate('DELETE FROM mail_cron_orphaned');
149 
150  ilLoggerFactory::getLogger('mail')->info(sprintf(
151  "Deleted all scheduled mail deletions because a reminder should't be sent (login: %s|usr_id: %s) anymore!", $ilUser->getLogin(), $ilUser->getId()
152  ));
153  }
154 
155  return true;
156  }
157 
162  public function run()
163  {
164  global $ilSetting;
165 
166  $mail_threshold = (int)$ilSetting->get('mail_threshold');
167 
168  ilLoggerFactory::getLogger('mail')->info(sprintf(
169  'Started mail deletion job with threshold: %s day(s)', var_export($mail_threshold, 1)
170  ));
171 
172  if((int)$ilSetting->get('mail_notify_orphaned') >= 1 && $mail_threshold >= 1)
173  {
174  $this->processNotification();
175  }
176 
177  if((int)$ilSetting->get('last_cronjob_start_ts') && $mail_threshold >= 1)
178  {
179  $this->processDeletion();
180  }
181 
182  $result = new ilCronJobResult();
183  $status = ilCronJobResult::STATUS_OK;
184  $result->setStatus($status);
185 
186  ilLoggerFactory::getLogger('mail')->info(sprintf(
187  'Finished mail deletion job with threshold: %s day(s)', var_export($mail_threshold, 1)
188  ));
189 
190  return $result;
191  }
192 
193  private function processNotification()
194  {
195  include_once './Services/Mail/classes/class.ilMailCronOrphanedMailsNotificationCollector.php';
197 
198  include_once'./Services/Mail/classes/class.ilMailCronOrphanedMailsNotifier.php';
199  $notifier = new ilMailCronOrphanedMailsNotifier($collector);
200  $notifier->processNotification();
201  }
202 
203  private function processDeletion()
204  {
205  include_once './Services/Mail/classes/class.ilMailCronOrphanedMailsDeletionCollector.php';
206  $collector = new ilMailCronOrphanedMailsDeletionCollector();
207 
208  include_once './Services/Mail/classes/class.ilMailCronOrphanedMailsDeletionProcessor.php';
209  $processor = new ilMailCronOrphanedMailsDeletionProcessor($collector);
210  $processor->processDeletion();
211  }
212 }
hasAutoActivation()
Is to be activated on "installation".
$result
This class represents a property form user interface.
Cron job application base class.
getDefaultScheduleType()
Get schedule type.
getDefaultScheduleValue()
Get schedule value.
This class represents a checkbox property in a property form.
addItem($a_item)
Add Item (Property, SectionHeader).
addCustomSettingsToForm(ilPropertyFormGUI $a_form)
hasFlexibleSchedule()
Can the schedule be configured?
setInfo($a_info)
Set Information Text.
This class represents a number property in a property form.
saveCustomSettings(ilPropertyFormGUI $a_form)
$ilUser
Definition: imgupload.php:18
getInput($a_post_var, $ensureValidation=true)
Returns the value of a HTTP-POST variable, identified by the passed id.
global $ilSetting
Definition: privfeed.php:17
global $lng
Definition: privfeed.php:17
global $ilDB
static getLogger($a_component_id)
Get component logger.
Cron job result data container.
$_POST["username"]