ILIAS  release_8 Revision v8.23
class.ilUserCronCheckAccounts.php
Go to the documentation of this file.
1 <?php
2 
24 {
25  protected int $counter = 0;
26 
27  public function getId(): string
28  {
29  return "user_check_accounts";
30  }
31 
32  public function getTitle(): string
33  {
34  global $DIC;
35 
36  $lng = $DIC['lng'];
37 
38  return $lng->txt("check_user_accounts");
39  }
40 
41  public function getDescription(): string
42  {
43  global $DIC;
44 
45  $lng = $DIC['lng'];
46 
47  return $lng->txt("check_user_accounts_desc");
48  }
49 
50  public function getDefaultScheduleType(): int
51  {
52  return self::SCHEDULE_TYPE_DAILY;
53  }
54 
55  public function getDefaultScheduleValue(): ?int
56  {
57  return null;
58  }
59 
60  public function hasAutoActivation(): bool
61  {
62  return false;
63  }
64 
65  public function hasFlexibleSchedule(): bool
66  {
67  return false;
68  }
69 
70  public function run(): ilCronJobResult
71  {
73  global $DIC;
74 
75  $ilDB = $DIC['ilDB'];
76  $ilLog = $DIC['ilLog'];
77 
79 
80  $now = time();
81  $two_weeks_in_seconds = $now + (60 * 60 * 24 * 14); // #14630
82 
83  // all users who are currently active and expire in the next 2 weeks
84  $query = "SELECT usr_id, login, time_limit_until " .
85  "FROM usr_data " .
86  "WHERE time_limit_message = '0' " .
87  "AND time_limit_unlimited = '0' " .
88  "AND time_limit_from < " . $ilDB->quote($now, "integer") . " " .
89  "AND time_limit_until > " . $ilDB->quote($now, "integer") . " " .
90  "AND time_limit_until < " . $ilDB->quote($two_weeks_in_seconds, "integer");
91 
92  $res = $ilDB->query($query);
93 
95  $senderFactory = $GLOBALS['DIC']["mail.mime.sender.factory"];
96  $sender = $senderFactory->system();
97 
98  while ($row = $ilDB->fetchObject($res)) {
99  $expires = $row->time_limit_until;
100  $login = $row->login;
101  $usr_id = $row->usr_id;
102 
104  $lng->loadLanguageModule('mail');
105 
106  $salutation = ilMail::getSalutation($usr_id, $lng);
107 
108  $body = $salutation . "\n\n";
109  $body .= sprintf(
110  $lng->txt('account_expires_body'),
111  $login,
112  ILIAS_HTTP_PATH,
113  strftime('%Y-%m-%d %R', $expires)
114  );
115 
116  $body .= "\n\n" . ilMail::_getAutoGeneratedMessageString($lng);
117 
118  // force email
119  $mail = new ilMail(ANONYMOUS_USER_ID);
120  $mail->enqueue(
121  ilObjUser::_lookupEmail($usr_id),
122  "",
123  "",
124  $lng->txt('account_expires_subject'),
125  $body,
126  []
127  );
128 
129  // set status 'mail sent'
130  $query = "UPDATE usr_data SET time_limit_message = '1' WHERE usr_id = '" . $usr_id . "'";
131  $ilDB->query($query);
132 
133  // Send log message
134  $ilLog->write('Cron: (checkUserAccounts()) sent message to ' . $login . '.');
135 
136  $this->counter++;
137  }
138 
140 
141  if ($this->counter) {
142  $status = ilCronJobResult::STATUS_OK;
143  }
144  $result = new ilCronJobResult();
145  $result->setStatus($status);
146  return $result;
147  }
148 
149  // #13288 / #12345
150  protected function txt(
151  string $language,
152  string $key,
153  string $module = 'common'
154  ): string {
155  return ilLanguage::_lookupEntry($language, $module, $key);
156  }
157 
158  protected function checkNotConfirmedUserAccounts(): void
159  {
160  global $DIC;
161 
162  $ilDB = $DIC['ilDB'];
163  $ilLog = $DIC['ilLog'];
164 
165  $oRegSettigs = new ilRegistrationSettings();
166 
167  $query = 'SELECT usr_id FROM usr_data '
168  . 'WHERE (reg_hash IS NOT NULL AND reg_hash != %s)'
169  . 'AND active = %s '
170  . 'AND create_date < %s';
171  $res = $ilDB->queryF(
172  $query,
173  array('text', 'integer', 'timestamp'),
174  array('', 0, date('Y-m-d H:i:s', time() - $oRegSettigs->getRegistrationHashLifetime()))
175  );
176  while ($row = $ilDB->fetchAssoc($res)) {
177  $oUser = ilObjectFactory::getInstanceByObjId((int) $row['usr_id']);
178  $oUser->delete();
179  $ilLog->write('Cron: Deleted ' . $oUser->getLogin() . ' [' . $oUser->getId() . '] ' . __METHOD__);
180 
181  $this->counter++;
182  }
183  }
184 }
$res
Definition: ltiservices.php:69
txt(string $language, string $key, string $module='common')
const ANONYMOUS_USER_ID
Definition: constants.php:27
$lng
global $DIC
Definition: feed.php:28
static _getLanguageOfUser(int $a_usr_id)
Get language object of user.
static getSalutation(int $a_usr_id, ?ilLanguage $a_language=null)
if(!defined('PATH_SEPARATOR')) $GLOBALS['_PEAR_default_error_mode']
Definition: PEAR.php:64
string $key
Consumer key/client ID value.
Definition: System.php:193
$query
static getInstanceByObjId(?int $obj_id, bool $stop_on_error=true)
get an instance of an Ilias object by object id
Class ilObjAuthSettingsGUI.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static _getAutoGeneratedMessageString(ilLanguage $lang=null)
static _lookupEntry(string $a_lang_key, string $a_mod, string $a_id)
static _lookupEmail(int $a_user_id)