ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilUserCronCheckAccounts.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
24
30{
31 protected int $counter = 0;
32
36
37 public function __construct()
38 {
40 global $DIC;
41
42 if (isset($DIC['ilDB'])) {
43 $this->db = $DIC['ilDB'];
44 }
45
46 if (isset($DIC['lng'])) {
47 $this->lng = $DIC['lng'];
48 }
49
50 if (isset($DIC['ilDB'])) {
51 $this->log = $DIC['ilLog'];
52 }
53 }
54
55 public function getId(): string
56 {
57 return 'user_check_accounts';
58 }
59
60 public function getTitle(): string
61 {
62 return $this->lng->txt('check_user_accounts');
63 }
64
65 public function getDescription(): string
66 {
67 return $this->lng->txt('check_user_accounts_desc');
68 }
69
71 {
72 return JobScheduleType::DAILY;
73 }
74
75 public function getDefaultScheduleValue(): ?int
76 {
77 return null;
78 }
79
80 public function hasAutoActivation(): bool
81 {
82 return false;
83 }
84
85 public function hasFlexibleSchedule(): bool
86 {
87 return false;
88 }
89
90 public function run(): JobResult
91 {
92 $status = JobResult::STATUS_NO_ACTION;
93
94 $now = time();
95 $two_weeks_in_seconds = $now + (60 * 60 * 24 * 14); // #14630
96
97 // all users who are currently active and expire in the next 2 weeks
98 $query = 'SELECT usr_id, login, time_limit_until ' .
99 'FROM usr_data ' .
100 'WHERE time_limit_message = "0" ' .
101 'AND time_limit_unlimited = "0" ' .
102 'AND time_limit_from < ' . $this->db->quote($now, 'integer') . ' ' .
103 'AND time_limit_until > ' . $this->db->quote($now, 'integer') . ' ' .
104 'AND time_limit_until < ' . $this->db->quote($two_weeks_in_seconds, 'integer');
105
106 $res = $this->db->query($query);
107
108 while ($row = $this->db->fetchObject($res)) {
109 $expires = $row->time_limit_until;
110 $login = $row->login;
111 $usr_id = $row->usr_id;
112
114 $lng->loadLanguageModule('mail');
115
116 $salutation = ilMail::getSalutation($usr_id, $lng);
117
118 $body = $salutation . "\n\n";
119 $body .= sprintf(
120 $lng->txt('account_expires_body'),
121 $login,
122 ILIAS_HTTP_PATH,
123 date('Y-m-d H:i', $expires)
124 );
125
127
128 // force email
129 $mail = new ilMail(ANONYMOUS_USER_ID);
130 $mail->enqueue(
132 '',
133 '',
134 $lng->txt('account_expires_subject'),
135 $body,
136 []
137 );
138
139 // set status 'mail sent'
140 $query = 'UPDATE usr_data SET time_limit_message = "1" WHERE usr_id = "' . $usr_id . '"';
141 $this->db->query($query);
142
143 // Send log message
144 $this->log->write('Cron: (checkUserAccounts()) sent message to ' . $login . '.');
145
146 $this->counter++;
147 }
148
150
151 if ($this->counter) {
152 $status = JobResult::STATUS_OK;
153 }
154 $result = new JobResult();
155 $result->setStatus($status);
156 return $result;
157 }
158
159 protected function checkNotConfirmedUserAccounts(): void
160 {
161 $registration_settings = new ilRegistrationSettings();
162
163 $query = 'SELECT usr_id FROM usr_data '
164 . 'WHERE (reg_hash IS NOT NULL AND reg_hash != %s)'
165 . 'AND active = %s '
166 . 'AND create_date < %s';
167 $res = $this->db->queryF(
168 $query,
169 ['text', 'integer', 'timestamp'],
170 ['', 0, date('Y-m-d H:i:s', time() - $registration_settings->getRegistrationHashLifetime())]
171 );
172 while ($row = $this->db->fetchAssoc($res)) {
173 $user = ilObjectFactory::getInstanceByObjId((int) $row['usr_id']);
174 $user->delete();
175 $this->log->write('Cron: Deleted ' . $user->getLogin() . ' [' . $user->getId() . '] ' . __METHOD__);
176
177 $this->counter++;
178 }
179 }
180}
Component logger with individual log levels by component id.
static _getLanguageOfUser(int $a_usr_id)
Get language object of user.
language handling
loadLanguageModule(string $a_module)
Load language module.
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...
static getSalutation(int $a_usr_id, ?ilLanguage $a_language=null)
static _getAutoGeneratedMessageString(?ilLanguage $lang=null)
static _lookupEmail(int $a_user_id)
static getInstanceByObjId(?int $obj_id, bool $stop_on_error=true)
get an instance of an Ilias object by object id
Class ilObjAuthSettingsGUI.
This cron send notifications about expiring user accounts.
hasAutoActivation()
Is to be activated on "installation", does only work for ILIAS core cron jobs.
const ANONYMOUS_USER_ID
Definition: constants.php:27
Interface ilDBInterface.
$res
Definition: ltiservices.php:69
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
global $DIC
Definition: shib_login.php:26