ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
ilMailCronOrphanedMails Class Reference

Delete orphaned mails. More...

+ Inheritance diagram for ilMailCronOrphanedMails:
+ Collaboration diagram for ilMailCronOrphanedMails:

Public Member Functions

 getId ()
 
 getTitle ()
 
 getDescription ()
 
 hasAutoActivation ()
 
 hasFlexibleSchedule ()
 
 getValidScheduleTypes ()
 
 getDefaultScheduleType ()
 
 getDefaultScheduleValue ()
 
 hasCustomSettings ()
 
 addCustomSettingsToForm (ilPropertyFormGUI $a_form)
 
 saveCustomSettings (ilPropertyFormGUI $a_form)
 
 ping ()
 
 run ()
 
- Public Member Functions inherited from ilCronJob
 setDateTimeProvider (?Closure $date_time_provider)
 
 isDue (?DateTimeImmutable $last_run, ?CronJobScheduleType $schedule_type, ?int $schedule_value, bool $is_manually_executed=false)
 
 getScheduleType ()
 Get current schedule type (if flexible) More...
 
 getScheduleValue ()
 Get current schedule value (if flexible) More...
 
 setSchedule (?CronJobScheduleType $a_type, ?int $a_value)
 Update current schedule (if flexible) More...
 
 getAllScheduleTypes ()
 Get all available schedule types. More...
 
 getScheduleTypesWithValues ()
 
 getValidScheduleTypes ()
 Returns a collection of all valid schedule types for a specific job. More...
 
 isManuallyExecutable ()
 
 hasCustomSettings ()
 
 addCustomSettingsToForm (ilPropertyFormGUI $a_form)
 
 saveCustomSettings (ilPropertyFormGUI $a_form)
 
 addToExternalSettingsForm (int $a_form_id, array &$a_fields, bool $a_is_active)
 
 activationWasToggled (ilDBInterface $db, ilSetting $setting, bool $a_currently_active)
 Important: This method is (also) called from the setup process, where the constructor of an ilCronJob ist NOT executed. More...
 
 getId ()
 
 getTitle ()
 
 getDescription ()
 
 hasAutoActivation ()
 Is to be activated on "installation", does only work for ILIAS core cron jobs. More...
 
 hasFlexibleSchedule ()
 
 getDefaultScheduleType ()
 
 getDefaultScheduleValue ()
 
 run ()
 

Private Member Functions

 init ()
 
 emptyStringOrFloatOrIntToEmptyOrIntegerString ()
 
 processNotification ()
 
 processDeletion ()
 

Private Attributes

GlobalHttpState $http
 
Refinery $refinery
 
ilLanguage $lng
 
ilSetting $settings
 
ilDBInterface $db
 
ilObjUser $user
 
bool $initDone = false
 
ilCronManager $cron_manager
 

Additional Inherited Members

- Protected Attributes inherited from ilCronJob
CronJobScheduleType $schedule_type = null
 
int $schedule_value = null
 
Closure $date_time_provider = null
 

Detailed Description

Delete orphaned mails.

Author
Nadia Matuschek nmatu.nosp@m.sche.nosp@m.k@dat.nosp@m.abay.nosp@m..de

Definition at line 35 of file class.ilMailCronOrphanedMails.php.

Member Function Documentation

◆ addCustomSettingsToForm()

ilMailCronOrphanedMails::addCustomSettingsToForm ( ilPropertyFormGUI  $a_form)

Definition at line 141 of file class.ilMailCronOrphanedMails.php.

References ilPropertyFormGUI\addItem(), emptyStringOrFloatOrIntToEmptyOrIntegerString(), ILIAS\FileDelivery\http(), init(), ILIAS\Repository\int(), ILIAS\Repository\lng(), and ILIAS\Repository\settings().

141  : void
142  {
143  $this->init();
144 
145  parent::addCustomSettingsToForm($a_form);
146 
147  $threshold = new ilNumberInputGUI($this->lng->txt('mail_threshold'), 'mail_threshold');
148  $threshold->setInfo($this->lng->txt('mail_threshold_info'));
149  $threshold->allowDecimals(false);
150  $threshold->setSuffix($this->lng->txt('days'));
151  $threshold->setMinValue(1);
152  $threshold->setSize(4);
153  $threshold->setValue($this->settings->get('mail_threshold', ''));
154 
155  $a_form->addItem($threshold);
156 
157  $mail_folder = new ilCheckboxInputGUI(
158  $this->lng->txt('only_inbox_trash'),
159  'mail_only_inbox_trash'
160  );
161  $mail_folder->setValue('1');
162  $mail_folder->setInfo($this->lng->txt('only_inbox_trash_info'));
163  $mail_folder->setChecked((bool) $this->settings->get('mail_only_inbox_trash', '0'));
164  $a_form->addItem($mail_folder);
165 
166  $notification = new ilNumberInputGUI(
167  $this->lng->txt('mail_notify_orphaned'),
168  'mail_notify_orphaned'
169  );
170  $notification->setInfo($this->lng->txt('mail_notify_orphaned_info'));
171  $notification->allowDecimals(false);
172  $notification->setSize(4);
173  $notification->setSuffix($this->lng->txt('days'));
174  $notification->setMinValue(0);
175 
176  if ($this->http->wrapper()->post()->has('mail_threshold')) {
177  $mail_threshold = (int) $this->http->wrapper()->post()->retrieve(
178  'mail_threshold',
180  );
181  } else {
182  $mail_threshold = (int) $this->settings->get('mail_threshold');
183  }
184  $maxvalue = $mail_threshold - 1;
185  $notification->setMaxValue($maxvalue);
186  $notification->setValue($this->settings->get('mail_notify_orphaned', ''));
187  $a_form->addItem($notification);
188  }
static http()
Fetches the global http state from ILIAS.
+ Here is the call graph for this function:

◆ emptyStringOrFloatOrIntToEmptyOrIntegerString()

ilMailCronOrphanedMails::emptyStringOrFloatOrIntToEmptyOrIntegerString ( )
private

Definition at line 64 of file class.ilMailCronOrphanedMails.php.

References ILIAS\Repository\refinery().

Referenced by addCustomSettingsToForm(), and saveCustomSettings().

65  {
66  $empty_string_or_null_to_stirng_trafo = $this->refinery->custom()->transformation(static function ($value): string {
67  if ($value === '' || null === $value) {
68  return '';
69  }
70 
71  throw new Exception('The value to be transformed is not an empty string');
72  });
73 
74  return $this->refinery->in()->series([
75  $this->refinery->byTrying([
76  $empty_string_or_null_to_stirng_trafo,
77  $this->refinery->kindlyTo()->int(),
78  $this->refinery->in()->series([
79  $this->refinery->kindlyTo()->float(),
80  $this->refinery->kindlyTo()->int()
81  ])
82  ]),
83  $this->refinery->kindlyTo()->string()
84  ]);
85  }
A transformation is a function from one datatype to another.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getDefaultScheduleType()

ilMailCronOrphanedMails::getDefaultScheduleType ( )

Definition at line 126 of file class.ilMailCronOrphanedMails.php.

127  {
128  return CronJobScheduleType::SCHEDULE_TYPE_DAILY;
129  }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...

◆ getDefaultScheduleValue()

ilMailCronOrphanedMails::getDefaultScheduleValue ( )

Definition at line 131 of file class.ilMailCronOrphanedMails.php.

131  : ?int
132  {
133  return 1;
134  }

◆ getDescription()

ilMailCronOrphanedMails::getDescription ( )

Definition at line 98 of file class.ilMailCronOrphanedMails.php.

References init(), and ILIAS\Repository\lng().

98  : string
99  {
100  $this->init();
101  return $this->lng->txt('mail_orphaned_mails_desc');
102  }
+ Here is the call graph for this function:

◆ getId()

ilMailCronOrphanedMails::getId ( )

Definition at line 87 of file class.ilMailCronOrphanedMails.php.

Referenced by ping().

87  : string
88  {
89  return 'mail_orphaned_mails';
90  }
+ Here is the caller graph for this function:

◆ getTitle()

ilMailCronOrphanedMails::getTitle ( )

Definition at line 92 of file class.ilMailCronOrphanedMails.php.

References init(), and ILIAS\Repository\lng().

92  : string
93  {
94  $this->init();
95  return $this->lng->txt('mail_orphaned_mails');
96  }
+ Here is the call graph for this function:

◆ getValidScheduleTypes()

ilMailCronOrphanedMails::getValidScheduleTypes ( )

Definition at line 114 of file class.ilMailCronOrphanedMails.php.

References ILIAS\Cron\Schedule\SCHEDULE_TYPE_YEARLY.

114  : array
115  {
116  return [
117  CronJobScheduleType::SCHEDULE_TYPE_DAILY,
118  CronJobScheduleType::SCHEDULE_TYPE_WEEKLY,
119  CronJobScheduleType::SCHEDULE_TYPE_MONTHLY,
120  CronJobScheduleType::SCHEDULE_TYPE_QUARTERLY,
122  CronJobScheduleType::SCHEDULE_TYPE_IN_DAYS
123  ];
124  }

◆ hasAutoActivation()

ilMailCronOrphanedMails::hasAutoActivation ( )

Definition at line 104 of file class.ilMailCronOrphanedMails.php.

104  : bool
105  {
106  return false;
107  }

◆ hasCustomSettings()

ilMailCronOrphanedMails::hasCustomSettings ( )

Definition at line 136 of file class.ilMailCronOrphanedMails.php.

136  : bool
137  {
138  return true;
139  }

◆ hasFlexibleSchedule()

ilMailCronOrphanedMails::hasFlexibleSchedule ( )

Definition at line 109 of file class.ilMailCronOrphanedMails.php.

109  : bool
110  {
111  return true;
112  }

◆ init()

ilMailCronOrphanedMails::init ( )
private

Definition at line 46 of file class.ilMailCronOrphanedMails.php.

References $DIC, ILIAS\FileDelivery\http(), ILIAS\Repository\lng(), ILIAS\Repository\refinery(), ILIAS\Repository\settings(), and ILIAS\Repository\user().

Referenced by addCustomSettingsToForm(), getDescription(), getTitle(), processDeletion(), processNotification(), run(), and saveCustomSettings().

46  : void
47  {
48  global $DIC;
49 
50  if (!$this->initDone) {
51  $this->settings = $DIC->settings();
52  $this->lng = $DIC->language();
53  $this->db = $DIC->database();
54  $this->user = $DIC->user();
55  $this->http = $DIC->http();
56  $this->refinery = $DIC->refinery();
57  $this->cron_manager = $DIC->cron()->manager();
58 
59  $this->lng->loadLanguageModule('mail');
60  $this->initDone = true;
61  }
62  }
global $DIC
Definition: feed.php:28
static http()
Fetches the global http state from ILIAS.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ ping()

ilMailCronOrphanedMails::ping ( )

Definition at line 219 of file class.ilMailCronOrphanedMails.php.

References getId().

219  : void
220  {
221  $this->cron_manager->ping($this->getId());
222  }
+ Here is the call graph for this function:

◆ processDeletion()

ilMailCronOrphanedMails::processDeletion ( )
private

Definition at line 268 of file class.ilMailCronOrphanedMails.php.

References init().

Referenced by run().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ processNotification()

ilMailCronOrphanedMails::processNotification ( )
private

Definition at line 255 of file class.ilMailCronOrphanedMails.php.

References init(), ILIAS\Repository\int(), ILIAS\Mail\Cron\ExpiredOrOrphanedMails\Notifier\send(), and ILIAS\Repository\settings().

Referenced by run().

255  : void
256  {
257  $this->init();
258 
259  $notifier = new Notifier(
260  $this,
261  new NotificationsCollector($this),
262  (int) $this->settings->get('mail_threshold', '0'),
263  (int) $this->settings->get('mail_notify_orphaned', '0')
264  );
265  $notifier->send();
266  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ run()

ilMailCronOrphanedMails::run ( )

Definition at line 224 of file class.ilMailCronOrphanedMails.php.

References ilLoggerFactory\getLogger(), init(), ILIAS\Repository\int(), processDeletion(), processNotification(), ILIAS\Repository\settings(), and ilCronJobResult\STATUS_OK.

225  {
226  $this->init();
227 
228  $mail_expiration_days = (int) $this->settings->get('mail_threshold', '0');
229 
230  ilLoggerFactory::getLogger('mail')->info(sprintf(
231  'Started mail deletion job with threshold: %s day(s)',
232  var_export($mail_expiration_days, true)
233  ));
234 
235  if ($mail_expiration_days >= 1 && (int) $this->settings->get('mail_notify_orphaned', '0') >= 1) {
236  $this->processNotification();
237  }
238 
239  if ($mail_expiration_days >= 1 && (int) $this->settings->get('last_cronjob_start_ts', (string) time())) {
240  $this->processDeletion();
241  }
242 
243  $result = new ilCronJobResult();
244  $status = ilCronJobResult::STATUS_OK;
245  $result->setStatus($status);
246 
247  ilLoggerFactory::getLogger('mail')->info(sprintf(
248  'Finished mail deletion job with threshold: %s day(s)',
249  var_export($mail_expiration_days, true)
250  ));
251 
252  return $result;
253  }
static getLogger(string $a_component_id)
Get component logger.
+ Here is the call graph for this function:

◆ saveCustomSettings()

ilMailCronOrphanedMails::saveCustomSettings ( ilPropertyFormGUI  $a_form)

Definition at line 190 of file class.ilMailCronOrphanedMails.php.

References emptyStringOrFloatOrIntToEmptyOrIntegerString(), ilPropertyFormGUI\getInput(), ilLoggerFactory\getLogger(), init(), ILIAS\Repository\settings(), and ILIAS\Repository\user().

190  : bool
191  {
192  $this->init();
193 
194  $this->settings->set('mail_only_inbox_trash', (string) ((int) $a_form->getInput('mail_only_inbox_trash')));
195  $this->settings->set(
196  'mail_threshold',
197  $this->emptyStringOrFloatOrIntToEmptyOrIntegerString()->transform($a_form->getInput('mail_threshold'))
198  );
199  $this->settings->set(
200  'mail_notify_orphaned',
201  $this->emptyStringOrFloatOrIntToEmptyOrIntegerString()->transform($a_form->getInput('mail_notify_orphaned'))
202  );
203 
204  if ((int) $this->settings->get('mail_notify_orphaned', '0') === 0) {
205  //delete all mail_cron_orphaned-table entries!
206  $this->db->manipulate('DELETE FROM mail_cron_orphaned');
207 
208  ilLoggerFactory::getLogger('mail')->info(sprintf(
209  "Deleted all scheduled mail deletions " .
210  "because a reminder shouldn't be sent (login: %s|usr_id: %s) anymore!",
211  $this->user->getLogin(),
212  $this->user->getId()
213  ));
214  }
215 
216  return true;
217  }
static getLogger(string $a_component_id)
Get component logger.
getInput(string $a_post_var, bool $ensureValidation=true)
Returns the input of an item, if item provides getInput method and as fallback the value of the HTTP-...
+ Here is the call graph for this function:

Field Documentation

◆ $cron_manager

ilCronManager ilMailCronOrphanedMails::$cron_manager
private

Definition at line 44 of file class.ilMailCronOrphanedMails.php.

◆ $db

ilDBInterface ilMailCronOrphanedMails::$db
private

Definition at line 41 of file class.ilMailCronOrphanedMails.php.

◆ $http

GlobalHttpState ilMailCronOrphanedMails::$http
private

Definition at line 37 of file class.ilMailCronOrphanedMails.php.

◆ $initDone

bool ilMailCronOrphanedMails::$initDone = false
private

Definition at line 43 of file class.ilMailCronOrphanedMails.php.

◆ $lng

ilLanguage ilMailCronOrphanedMails::$lng
private

Definition at line 39 of file class.ilMailCronOrphanedMails.php.

◆ $refinery

Refinery ilMailCronOrphanedMails::$refinery
private

Definition at line 38 of file class.ilMailCronOrphanedMails.php.

◆ $settings

ilSetting ilMailCronOrphanedMails::$settings
private

Definition at line 40 of file class.ilMailCronOrphanedMails.php.

◆ $user

ilObjUser ilMailCronOrphanedMails::$user
private

Definition at line 42 of file class.ilMailCronOrphanedMails.php.


The documentation for this class was generated from the following file: