ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
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";
13 {
17  public function __construct()
18  {
19  global $lng;
20  $lng->loadLanguageModule('mail');
21  }
22 
27  public function getId()
28  {
29  return "mail_orphaned_mails";
30  }
31 
35  public function getTitle()
36  {
37  global $lng;
38  return $lng->txt("mail_orphaned_mails");
39  }
40 
44  public function getDescription()
45  {
46  global $lng;
47  return $lng->txt("mail_orphaned_mails_desc");
48  }
49 
54  public function hasAutoActivation()
55  {
56  return false;
57  }
58 
63  public function hasFlexibleSchedule()
64  {
65  return false;
66  }
67 
72  public function getDefaultScheduleType()
73  {
74  return self::SCHEDULE_TYPE_DAILY;
75  }
76 
81  public function getDefaultScheduleValue()
82  {
83  return;
84  }
85 
89  public function hasCustomSettings()
90  {
91  return true;
92  }
93 
97  public function addCustomSettingsToForm(ilPropertyFormGUI $a_form)
98  {
99  global $ilSetting, $lng;
100 
101  parent::addCustomSettingsToForm($a_form);
102 
103  $threshold = new ilNumberInputGUI($lng->txt('mail_threshold'), 'mail_threshold');
104  $threshold->setInfo($lng->txt('mail_threshold_info'));
105  $threshold->allowDecimals(false);
106  $threshold->setSuffix($lng->txt('days'));
107  $threshold->setMinValue(1);
108  $threshold->setValue($ilSetting->get('mail_threshold'));
109 
110  $a_form->addItem($threshold);
111 
112  $mail_folder = new ilCheckboxInputGUI($lng->txt('only_inbox_trash'), 'mail_only_inbox_trash');
113  $mail_folder->setInfo($lng->txt('only_inbox_trash_info'));
114  $mail_folder->setChecked($ilSetting->get('mail_only_inbox_trash'));
115  $a_form->addItem($mail_folder);
116 
117  $notification = new ilNumberInputGUI($lng->txt('mail_notify_orphaned'), 'mail_notify_orphaned');
118  $notification->setInfo($lng->txt('mail_notify_orphaned_info'));
119  $notification->allowDecimals(false);
120  $notification->setSuffix($lng->txt('days'));
121  $notification->setMinValue(0);
122 
123  $mail_threshold = isset($_POST['mail_threshold']) ? (int)$_POST['mail_threshold'] : $ilSetting->get('mail_threshold');
124  $maxvalue = $mail_threshold-1;
125  $notification->setMaxValue($maxvalue);
126  $notification->setValue($ilSetting->get('mail_notify_orphaned'));
127  $a_form->addItem($notification);
128  }
129 
134  public function saveCustomSettings(ilPropertyFormGUI $a_form)
135  {
136  global $ilSetting;
137 
138  $ilSetting->set('mail_threshold', (int)$a_form->getInput('mail_threshold'));
139  $ilSetting->set('mail_only_inbox_trash', (int)$a_form->getInput('mail_only_inbox_trash'));
140  $ilSetting->set('mail_notify_orphaned', (int)$a_form->getInput('mail_notify_orphaned'));
141 
142  if($ilSetting->get('mail_notify_orphaned') == 0)
143  {
144  global $ilDB;
145  //delete all mail_cron_orphaned-table entries!
146  $ilDB->manipulate('DELETE FROM mail_cron_orphaned');
147  }
148 
149  return true;
150  }
151 
156  public function run()
157  {
158  global $ilSetting;
159 
160  $mail_threshold = (int)$ilSetting->get('mail_threshold');
161 
162  if( (int)$ilSetting->get('mail_notify_orphaned') >= 1 && $mail_threshold >= 1)
163  {
164  $this->processNotification();
165  }
166 
167  if((int)$ilSetting->get('last_cronjob_start_ts') && $mail_threshold >= 1)
168  {
169  $this->processDeletion();
170  }
171 
172  $result = new ilCronJobResult();
173  $status = ilCronJobResult::STATUS_OK;
174  $result->setStatus($status);
175  return $result;
176  }
177 
178  private function processNotification()
179  {
180  include_once './Services/Mail/classes/class.ilMailCronOrphanedMailsNotificationCollector.php';
182 
183  include_once'./Services/Mail/classes/class.ilMailCronOrphanedMailsNotifier.php';
184  $notifier = new ilMailCronOrphanedMailsNotifier($collector);
185  $notifier->processNotification();
186  }
187 
188  private function processDeletion()
189  {
190  include_once './Services/Mail/classes/class.ilMailCronOrphanedMailsDeletionCollector.php';
191  $collector = new ilMailCronOrphanedMailsDeletionCollector();
192 
193  include_once './Services/Mail/classes/class.ilMailCronOrphanedMailsDeletionProcessor.php';
194  $processor = new ilMailCronOrphanedMailsDeletionProcessor($collector);
195  $processor->processDeletion();
196  }
197 }
hasAutoActivation()
Is to be activated on "installation".
$_POST['username']
Definition: cron.php:12
$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)
getInput($a_post_var, $ensureValidation=true)
Returns the value of a HTTP-POST variable, identified by the passed id.
global $ilSetting
Definition: privfeed.php:40
global $lng
Definition: privfeed.php:40
global $ilDB
Cron job result data container.