ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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  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 false;
102  }
103 
108  public function getDefaultScheduleType()
109  {
110  return self::SCHEDULE_TYPE_DAILY;
111  }
112 
117  public function getDefaultScheduleValue()
118  {
119  return 1;
120  }
121 
125  public function hasCustomSettings()
126  {
127  return true;
128  }
129 
134  {
135  $this->init();
136  parent::addCustomSettingsToForm($a_form);
137 
138  $threshold = new ilNumberInputGUI($this->lng->txt('mail_threshold'), 'mail_threshold');
139  $threshold->setInfo($this->lng->txt('mail_threshold_info'));
140  $threshold->allowDecimals(false);
141  $threshold->setSuffix($this->lng->txt('days'));
142  $threshold->setMinValue(1);
143  $threshold->setValue($this->settings->get('mail_threshold'));
144 
145  $a_form->addItem($threshold);
146 
147  $mail_folder = new ilCheckboxInputGUI($this->lng->txt('only_inbox_trash'), 'mail_only_inbox_trash');
148  $mail_folder->setInfo($this->lng->txt('only_inbox_trash_info'));
149  $mail_folder->setChecked($this->settings->get('mail_only_inbox_trash'));
150  $a_form->addItem($mail_folder);
151 
152  $notification = new ilNumberInputGUI($this->lng->txt('mail_notify_orphaned'), 'mail_notify_orphaned');
153  $notification->setInfo($this->lng->txt('mail_notify_orphaned_info'));
154  $notification->allowDecimals(false);
155  $notification->setSuffix($this->lng->txt('days'));
156  $notification->setMinValue(0);
157 
158  $mail_threshold = isset($_POST['mail_threshold']) ? (int) $_POST['mail_threshold'] : $this->settings->get('mail_threshold');
159  $maxvalue = $mail_threshold-1;
160  $notification->setMaxValue($maxvalue);
161  $notification->setValue($this->settings->get('mail_notify_orphaned'));
162  $a_form->addItem($notification);
163  }
164 
169  public function saveCustomSettings(ilPropertyFormGUI $a_form)
170  {
171  $this->init();
172  $this->settings->set('mail_threshold', (int) $a_form->getInput('mail_threshold'));
173  $this->settings->set('mail_only_inbox_trash', (int) $a_form->getInput('mail_only_inbox_trash'));
174  $this->settings->set('mail_notify_orphaned', (int) $a_form->getInput('mail_notify_orphaned'));
175 
176  if ($this->settings->get('mail_notify_orphaned') == 0) {
177  //delete all mail_cron_orphaned-table entries!
178  $this->db->manipulate('DELETE FROM mail_cron_orphaned');
179 
180  ilLoggerFactory::getLogger('mail')->info(sprintf(
181  "Deleted all scheduled mail deletions because a reminder should't be sent (login: %s|usr_id: %s) anymore!",
182  $this->user->getLogin(),
183  $this->user->getId()
184  ));
185  }
186 
187  return true;
188  }
189 
194  public function run()
195  {
196  $this->init();
197  $mail_threshold = (int) $this->settings->get('mail_threshold');
198 
199  ilLoggerFactory::getLogger('mail')->info(sprintf(
200  'Started mail deletion job with threshold: %s day(s)',
201  var_export($mail_threshold, 1)
202  ));
203 
204  if ((int) $this->settings->get('mail_notify_orphaned') >= 1 && $mail_threshold >= 1) {
205  $this->processNotification();
206  }
207 
208  if ((int) $this->settings->get('last_cronjob_start_ts', time()) && $mail_threshold >= 1) {
209  $this->processDeletion();
210  }
211 
212  $result = new ilCronJobResult();
213  $status = ilCronJobResult::STATUS_OK;
214  $result->setStatus($status);
215 
216  ilLoggerFactory::getLogger('mail')->info(sprintf(
217  'Finished mail deletion job with threshold: %s day(s)',
218  var_export($mail_threshold, 1)
219  ));
220 
221  return $result;
222  }
223 
224  private function processNotification()
225  {
226  $this->init();
227  include_once './Services/Mail/classes/class.ilMailCronOrphanedMailsNotificationCollector.php';
229 
230  include_once'./Services/Mail/classes/class.ilMailCronOrphanedMailsNotifier.php';
231  $notifier = new ilMailCronOrphanedMailsNotifier(
232  $collector,
233  (int) $this->settings->get('mail_threshold'),
234  (int) $this->settings->get('mail_notify_orphaned')
235  );
236  $notifier->processNotification();
237  }
238 
239  private function processDeletion()
240  {
241  $this->init();
242  include_once './Services/Mail/classes/class.ilMailCronOrphanedMailsDeletionCollector.php';
243  $collector = new ilMailCronOrphanedMailsDeletionCollector();
244 
245  include_once './Services/Mail/classes/class.ilMailCronOrphanedMailsDeletionProcessor.php';
246  $processor = new ilMailCronOrphanedMailsDeletionProcessor($collector);
247  $processor->processDeletion();
248  }
249 }
hasAutoActivation()
Is to be activated on "installation".
$result
This class represents a property form user interface.
global $DIC
Definition: saml.php:7
Cron job application base class.
getDefaultScheduleValue()
Get schedule value.
This class represents a checkbox property in a property form.
addItem($a_item)
Add Item (Property, SectionHeader).
user()
Definition: user.php:4
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)
getInput($a_post_var, $ensureValidation=true)
Returns the value of a HTTP-POST variable, identified by the passed id.
settings()
Definition: settings.php:2
static getLogger($a_component_id)
Get component logger.
Add data(end) time
Method that wraps PHPs time in order to allow simulations with the workflow.
Cron job result data container.
$_POST["username"]