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

This cron send notifications about expiring user accounts. More...

+ Inheritance diagram for ilUserCronCheckAccounts:
+ Collaboration diagram for ilUserCronCheckAccounts:

Public Member Functions

 getId ()
 
 getTitle ()
 
 getDescription ()
 
 getDefaultScheduleType ()
 
 getDefaultScheduleValue ()
 
 hasAutoActivation ()
 
 hasFlexibleSchedule ()
 
 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 ()
 

Protected Member Functions

 txt (string $language, string $key, string $module='common')
 
 checkNotConfirmedUserAccounts ()
 

Protected Attributes

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

Private Attributes

ilDBInterface $db
 
ilLanguage $lng
 
ilComponentLogger $log
 

Detailed Description

This cron send notifications about expiring user accounts.

Author
Stefan Meyer meyer.nosp@m.@lei.nosp@m.fos.c.nosp@m.om

Definition at line 25 of file class.ilUserCronCheckAccounts.php.

Member Function Documentation

◆ checkNotConfirmedUserAccounts()

ilUserCronCheckAccounts::checkNotConfirmedUserAccounts ( )
protected

Definition at line 164 of file class.ilUserCronCheckAccounts.php.

References $res, and ilObjectFactory\getInstanceByObjId().

Referenced by run().

164  : void
165  {
166  $registration_settings = new ilRegistrationSettings();
167 
168  $query = 'SELECT usr_id FROM usr_data '
169  . 'WHERE (reg_hash IS NOT NULL AND reg_hash != %s)'
170  . 'AND active = %s '
171  . 'AND create_date < %s';
172  $res = $this->db->queryF(
173  $query,
174  ['text', 'integer', 'timestamp'],
175  ['', 0, date('Y-m-d H:i:s', time() - $registration_settings->getRegistrationHashLifetime())]
176  );
177  while ($row = $this->db->fetchAssoc($res)) {
178  $user = ilObjectFactory::getInstanceByObjId((int) $row['usr_id']);
179  $user->delete();
180  $this->log->write('Cron: Deleted ' . $user->getLogin() . ' [' . $user->getId() . '] ' . __METHOD__);
181 
182  $this->counter++;
183  }
184  }
$res
Definition: ltiservices.php:69
static getInstanceByObjId(?int $obj_id, bool $stop_on_error=true)
get an instance of an Ilias object by object id
Class ilObjAuthSettingsGUI.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getDefaultScheduleType()

ilUserCronCheckAccounts::getDefaultScheduleType ( )

Definition at line 66 of file class.ilUserCronCheckAccounts.php.

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

◆ getDefaultScheduleValue()

ilUserCronCheckAccounts::getDefaultScheduleValue ( )

Definition at line 71 of file class.ilUserCronCheckAccounts.php.

71  : ?int
72  {
73  return null;
74  }

◆ getDescription()

ilUserCronCheckAccounts::getDescription ( )

Definition at line 61 of file class.ilUserCronCheckAccounts.php.

References ILIAS\Repository\lng().

61  : string
62  {
63  return $this->lng->txt("check_user_accounts_desc");
64  }
+ Here is the call graph for this function:

◆ getId()

ilUserCronCheckAccounts::getId ( )

Definition at line 51 of file class.ilUserCronCheckAccounts.php.

51  : string
52  {
53  return "user_check_accounts";
54  }

◆ getTitle()

ilUserCronCheckAccounts::getTitle ( )

Definition at line 56 of file class.ilUserCronCheckAccounts.php.

References ILIAS\Repository\lng().

56  : string
57  {
58  return $this->lng->txt("check_user_accounts");
59  }
+ Here is the call graph for this function:

◆ hasAutoActivation()

ilUserCronCheckAccounts::hasAutoActivation ( )

Definition at line 76 of file class.ilUserCronCheckAccounts.php.

76  : bool
77  {
78  return false;
79  }

◆ hasFlexibleSchedule()

ilUserCronCheckAccounts::hasFlexibleSchedule ( )

Definition at line 81 of file class.ilUserCronCheckAccounts.php.

81  : bool
82  {
83  return false;
84  }

◆ run()

ilUserCronCheckAccounts::run ( )

Definition at line 86 of file class.ilUserCronCheckAccounts.php.

References $res, ilMail\_getAutoGeneratedMessageString(), ilLanguageFactory\_getLanguageOfUser(), ilObjUser\_lookupEmail(), ANONYMOUS_USER_ID, checkNotConfirmedUserAccounts(), ilMail\getSalutation(), ilLanguage\loadLanguageModule(), ilCronJobResult\STATUS_NO_ACTION, ilCronJobResult\STATUS_OK, and ilLanguage\txt().

87  {
89 
90  $now = time();
91  $two_weeks_in_seconds = $now + (60 * 60 * 24 * 14); // #14630
92 
93  // all users who are currently active and expire in the next 2 weeks
94  $query = "SELECT usr_id, login, time_limit_until " .
95  "FROM usr_data " .
96  "WHERE time_limit_message = '0' " .
97  "AND time_limit_unlimited = '0' " .
98  "AND time_limit_from < " . $this->db->quote($now, "integer") . " " .
99  "AND time_limit_until > " . $this->db->quote($now, "integer") . " " .
100  "AND time_limit_until < " . $this->db->quote($two_weeks_in_seconds, "integer");
101 
102  $res = $this->db->query($query);
103 
104  while ($row = $this->db->fetchObject($res)) {
105  $expires = $row->time_limit_until;
106  $login = $row->login;
107  $usr_id = $row->usr_id;
108 
110  $lng->loadLanguageModule('mail');
111 
112  $salutation = ilMail::getSalutation($usr_id, $lng);
113 
114  $body = $salutation . "\n\n";
115  $body .= sprintf(
116  $lng->txt('account_expires_body'),
117  $login,
118  ILIAS_HTTP_PATH,
119  date('Y-m-d H:i', $expires)
120  );
121 
122  $body .= "\n\n" . ilMail::_getAutoGeneratedMessageString($lng);
123 
124  // force email
125  $mail = new ilMail(ANONYMOUS_USER_ID);
126  $mail->enqueue(
127  ilObjUser::_lookupEmail($usr_id),
128  "",
129  "",
130  $lng->txt('account_expires_subject'),
131  $body,
132  []
133  );
134 
135  // set status 'mail sent'
136  $query = "UPDATE usr_data SET time_limit_message = '1' WHERE usr_id = '" . $usr_id . "'";
137  $this->db->query($query);
138 
139  // Send log message
140  $this->log->write('Cron: (checkUserAccounts()) sent message to ' . $login . '.');
141 
142  $this->counter++;
143  }
144 
146 
147  if ($this->counter) {
148  $status = ilCronJobResult::STATUS_OK;
149  }
150  $result = new ilCronJobResult();
151  $result->setStatus($status);
152  return $result;
153  }
$res
Definition: ltiservices.php:69
const ANONYMOUS_USER_ID
Definition: constants.php:27
txt(string $a_topic, string $a_default_lang_fallback_mod="")
gets the text for a given topic if the topic is not in the list, the topic itself with "-" will be re...
loadLanguageModule(string $a_module)
Load language module.
static _getLanguageOfUser(int $a_usr_id)
Get language object of user.
final const STATUS_NO_ACTION
static getSalutation(int $a_usr_id, ?ilLanguage $a_language=null)
static _getAutoGeneratedMessageString(ilLanguage $lang=null)
static _lookupEmail(int $a_user_id)
+ Here is the call graph for this function:

◆ txt()

ilUserCronCheckAccounts::txt ( string  $language,
string  $key,
string  $module = 'common' 
)
protected

Definition at line 156 of file class.ilUserCronCheckAccounts.php.

References ilLanguage\_lookupEntry().

160  : string {
161  return ilLanguage::_lookupEntry($language, $module, $key);
162  }
string $key
Consumer key/client ID value.
Definition: System.php:193
static _lookupEntry(string $a_lang_key, string $a_mod, string $a_id)
+ Here is the call graph for this function:

Field Documentation

◆ $counter

int ilUserCronCheckAccounts::$counter = 0
protected

Definition at line 27 of file class.ilUserCronCheckAccounts.php.

◆ $db

ilDBInterface ilUserCronCheckAccounts::$db
private

Definition at line 29 of file class.ilUserCronCheckAccounts.php.

◆ $lng

ilLanguage ilUserCronCheckAccounts::$lng
private

Definition at line 30 of file class.ilUserCronCheckAccounts.php.

◆ $log

ilComponentLogger ilUserCronCheckAccounts::$log
private

Definition at line 31 of file class.ilUserCronCheckAccounts.php.


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