ILIAS  release_8 Revision v8.24
ilCronDeleteNeverLoggedInUserAccounts Class Reference
+ Inheritance diagram for ilCronDeleteNeverLoggedInUserAccounts:
+ Collaboration diagram for ilCronDeleteNeverLoggedInUserAccounts:

Public Member Functions

 __construct ()
 
 getId ()
 
 getTitle ()
 
 getDescription ()
 
 getDefaultScheduleType ()
 
 getDefaultScheduleValue ()
 
 hasAutoActivation ()
 Is to be activated on "installation", does only work for ILIAS core cron jobs. More...
 
 hasFlexibleSchedule ()
 
 hasCustomSettings ()
 
 run ()
 
 addCustomSettingsToForm (ilPropertyFormGUI $a_form)
 
 saveCustomSettings (ilPropertyFormGUI $a_form)
 
- Public Member Functions inherited from ilCronJob
 setDateTimeProvider (?Closure $date_time_provider)
 
 isDue (?DateTimeImmutable $last_run, ?int $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 (?int $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 Attributes

const DEFAULT_CREATION_THRESHOLD = 365
 
string $roleIdWhiteliste = ''
 
int $thresholdInDays = self::DEFAULT_CREATION_THRESHOLD
 
ilLanguage $lng
 
ilSetting $settings
 
ilRbacReview $rbacreview
 
ilObjectDataCache $objectDataCache
 
ILIAS HTTP GlobalHttpState $http
 
ILIAS Refinery Factory $refinery
 
ilGlobalTemplateInterface $main_tpl
 

Additional Inherited Members

- Data Fields inherited from ilCronJob
const SCHEDULE_TYPE_DAILY = 1
 @depracated This will be replaced with an ENUM in ILIAS 9 More...
 
const SCHEDULE_TYPE_IN_MINUTES = 2
 @depracated This will be replaced with an ENUM in ILIAS 9 More...
 
const SCHEDULE_TYPE_IN_HOURS = 3
 @depracated This will be replaced with an ENUM in ILIAS 9 More...
 
const SCHEDULE_TYPE_IN_DAYS = 4
 @depracated This will be replaced with an ENUM in ILIAS 9 More...
 
const SCHEDULE_TYPE_WEEKLY = 5
 @depracated This will be replaced with an ENUM in ILIAS 9 More...
 
const SCHEDULE_TYPE_MONTHLY = 6
 @depracated This will be replaced with an ENUM in ILIAS 9 More...
 
const SCHEDULE_TYPE_QUARTERLY = 7
 @depracated This will be replaced with an ENUM in ILIAS 9 More...
 
const SCHEDULE_TYPE_YEARLY = 8
 @depracated This will be replaced with an ENUM in ILIAS 9 More...
 
- Protected Attributes inherited from ilCronJob
int $schedule_type = null
 
int $schedule_value = null
 
Closure $date_time_provider = null
 

Detailed Description

Constructor & Destructor Documentation

◆ __construct()

ilCronDeleteNeverLoggedInUserAccounts::__construct ( )

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

38 {
39 global $DIC;
40 $this->main_tpl = $DIC->ui()->mainTemplate();
41
42 if ($DIC) {
43 if (isset($DIC['ilSetting'])) {
44 $this->settings = $DIC->settings();
45
46 $this->roleIdWhiteliste = (string) $this->settings->get(
47 'cron_users_without_login_delete_incl_roles',
48 ''
49 );
50
51 $this->thresholdInDays = (int) $this->settings->get(
52 'cron_users_without_login_delete_threshold',
54 );
55 }
56
57 if (isset($DIC['lng'])) {
58 $this->lng = $DIC->language();
59 $this->lng->loadLanguageModule('usr');
60 }
61
62 if (isset($DIC['rbacreview'])) {
63 $this->rbacreview = $DIC->rbac()->review();
64 }
65
66 if (isset($DIC['ilObjDataCache'])) {
67 $this->objectDataCache = $DIC['ilObjDataCache'];
68 }
69
70 if (isset($DIC['http'])) {
71 $this->http = $DIC->http();
72 }
73
74 if (isset($DIC['refinery'])) {
75 $this->refinery = $DIC->refinery();
76 }
77 }
78 }
global $DIC
Definition: feed.php:28
static http()
Fetches the global http state from ILIAS.

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

+ Here is the call graph for this function:

Member Function Documentation

◆ addCustomSettingsToForm()

ilCronDeleteNeverLoggedInUserAccounts::addCustomSettingsToForm ( ilPropertyFormGUI  $a_form)

Reimplemented from ilCronJob.

Definition at line 186 of file class.ilCronDeleteNeverLoggedInUserAccounts.php.

186 : void
187 {
188 $roleWhiteList = new ilMultiSelectInputGUI(
189 $this->lng->txt('cron_users_without_login_del_role_whitelist'),
190 'role_whitelist'
191 );
192 $roleWhiteList->setInfo($this->lng->txt('cron_users_without_login_del_role_whitelist_info'));
193 $roles = array();
194 foreach ($this->rbacreview->getGlobalRoles() as $role_id) {
195 if ($role_id !== ANONYMOUS_ROLE_ID) {
196 $roles[$role_id] = $this->objectDataCache->lookupTitle($role_id);
197 }
198 }
199 $roleWhiteList->setOptions($roles);
200 $roleWhiteList->setValue(array_filter(array_map('intval', explode(',', $this->roleIdWhiteliste))));
201 $roleWhiteList->setWidth(300);
202 $a_form->addItem($roleWhiteList);
203
204 $threshold = new ilNumberInputGUI(
205 $this->lng->txt('cron_users_without_login_del_create_date_thr'),
206 'threshold'
207 );
208 $threshold->allowDecimals(false);
209 $threshold->setInfo($this->lng->txt('cron_users_without_login_del_create_date_thr_info'));
210 $threshold->setValue((string) $this->thresholdInDays);
211 $threshold->setSuffix($this->lng->txt('days'));
212 $threshold->setSize(4);
213 $threshold->setMaxLength(4);
214 $threshold->setRequired(true);
215 $a_form->addItem($threshold);
216 }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This class represents a number property in a property form.
const ANONYMOUS_ROLE_ID
Definition: constants.php:28

References ilPropertyFormGUI\addItem(), ANONYMOUS_ROLE_ID, and ILIAS\Repository\lng().

+ Here is the call graph for this function:

◆ getDefaultScheduleType()

ilCronDeleteNeverLoggedInUserAccounts::getDefaultScheduleType ( )

Reimplemented from ilCronJob.

Definition at line 99 of file class.ilCronDeleteNeverLoggedInUserAccounts.php.

99 : int
100 {
102 }
const SCHEDULE_TYPE_DAILY
@depracated This will be replaced with an ENUM in ILIAS 9

References ilCronJob\SCHEDULE_TYPE_DAILY.

◆ getDefaultScheduleValue()

ilCronDeleteNeverLoggedInUserAccounts::getDefaultScheduleValue ( )

Reimplemented from ilCronJob.

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

104 : int
105 {
106 return 1;
107 }

◆ getDescription()

ilCronDeleteNeverLoggedInUserAccounts::getDescription ( )

Reimplemented from ilCronJob.

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

92 : string
93 {
94 global $DIC;
95
96 return $DIC->language()->txt('user_never_logged_in_info');
97 }

References $DIC.

◆ getId()

ilCronDeleteNeverLoggedInUserAccounts::getId ( )

Reimplemented from ilCronJob.

Definition at line 80 of file class.ilCronDeleteNeverLoggedInUserAccounts.php.

80 : string
81 {
82 return 'user_never_logged_in';
83 }

◆ getTitle()

ilCronDeleteNeverLoggedInUserAccounts::getTitle ( )

Reimplemented from ilCronJob.

Definition at line 85 of file class.ilCronDeleteNeverLoggedInUserAccounts.php.

85 : string
86 {
87 global $DIC;
88
89 return $DIC->language()->txt('user_never_logged_in');
90 }

References $DIC.

◆ hasAutoActivation()

ilCronDeleteNeverLoggedInUserAccounts::hasAutoActivation ( )

Is to be activated on "installation", does only work for ILIAS core cron jobs.

Reimplemented from ilCronJob.

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

109 : bool
110 {
111 return false;
112 }

◆ hasCustomSettings()

ilCronDeleteNeverLoggedInUserAccounts::hasCustomSettings ( )

Reimplemented from ilCronJob.

Definition at line 119 of file class.ilCronDeleteNeverLoggedInUserAccounts.php.

119 : bool
120 {
121 return true;
122 }

◆ hasFlexibleSchedule()

ilCronDeleteNeverLoggedInUserAccounts::hasFlexibleSchedule ( )

Reimplemented from ilCronJob.

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

114 : bool
115 {
116 return true;
117 }

◆ run()

ilCronDeleteNeverLoggedInUserAccounts::run ( )

Reimplemented from ilCronJob.

Definition at line 124 of file class.ilCronDeleteNeverLoggedInUserAccounts.php.

125 {
126 global $DIC;
127
128 $result = new ilCronJobResult();
129
131 $message = 'No user deleted';
132
134 $this->thresholdInDays ?: self::DEFAULT_CREATION_THRESHOLD
135 );
136
137 $roleIdWhitelist = array_filter(array_map('intval', explode(',', $this->roleIdWhiteliste)));
138
139 $counter = 0;
140 foreach ($userIds as $userId) {
141 if ($userId === ANONYMOUS_USER_ID || $userId === SYSTEM_USER_ID) {
142 continue;
143 }
144
145 $user = ilObjectFactory::getInstanceByObjId($userId, false);
146 if (!($user instanceof ilObjUser)) {
147 continue;
148 }
149
150 $ignoreUser = true;
151
152 if (count($roleIdWhitelist) > 0) {
153 $assignedRoleIds = array_filter(array_map('intval', $this->rbacreview->assignedRoles($userId)));
154
155 $respectedRolesToInclude = array_intersect($assignedRoleIds, $roleIdWhitelist);
156 if (count($respectedRolesToInclude) > 0) {
157 $ignoreUser = false;
158 }
159 }
160
161 if ($ignoreUser) {
162 continue;
163 }
164
165 $DIC->logger()->user()->info(sprintf(
166 "Deleting user account with id %s (login: %s)",
167 $user->getId(),
168 $user->getLogin()
169 ));
170 $user->delete();
171
172 $counter++;
173 }
174
175 if ($counter) {
177 $message = sprintf('%s user(s) deleted', $counter);
178 }
179
180 $result->setStatus($status);
181 $result->setMessage($message);
182
183 return $result;
184 }
User class.
static getUserIdsNeverLoggedIn(int $thresholdInDays)
Get ids of all users that have never logged in.
static getInstanceByObjId(?int $obj_id, bool $stop_on_error=true)
get an instance of an Ilias object by object id
const SYSTEM_USER_ID
This file contains constants for PHPStan analyis, see: https://phpstan.org/config-reference#constants...
Definition: constants.php:26
const ANONYMOUS_USER_ID
Definition: constants.php:27
$message
Definition: xapiexit.php:32

References $DIC, $message, ANONYMOUS_USER_ID, ilObjectFactory\getInstanceByObjId(), ilObjUser\getUserIdsNeverLoggedIn(), ilCronJobResult\STATUS_NO_ACTION, ilCronJobResult\STATUS_OK, and SYSTEM_USER_ID.

+ Here is the call graph for this function:

◆ saveCustomSettings()

ilCronDeleteNeverLoggedInUserAccounts::saveCustomSettings ( ilPropertyFormGUI  $a_form)

Reimplemented from ilCronJob.

Definition at line 218 of file class.ilCronDeleteNeverLoggedInUserAccounts.php.

218 : bool
219 {
220 $valid = true;
221
222 $this->roleIdWhiteliste = implode(',', $this->http->wrapper()->post()->retrieve(
223 'role_whitelist',
224 $this->refinery->byTrying([
225 $this->refinery->kindlyTo()->listOf($this->refinery->kindlyTo()->int()),
226 $this->refinery->always([])
227 ])
228 ));
229
230 try {
231 $this->thresholdInDays = $this->http->wrapper()->post()->retrieve(
232 'threshold',
233 $this->refinery->kindlyTo()->int()
234 );
236 $valid = false;
237 $a_form->getItemByPostVar('threshold')->setAlert($this->lng->txt('user_never_logged_in_info_threshold_err_num'));
238 }
239
240 if ($valid) {
241 $this->settings->set(
242 'cron_users_without_login_delete_incl_roles',
243 $this->roleIdWhiteliste
244 );
245 $this->settings->set(
246 'cron_users_without_login_delete_threshold',
247 (string) $this->thresholdInDays
248 );
249 return true;
250 }
251
252 $this->main_tpl->setOnScreenMessage('failure', $this->lng->txt('form_input_not_valid'));
253 return false;
254 }
getItemByPostVar(string $a_post_var)
$valid

References Vendor\Package\$e, $valid, ilPropertyFormGUI\getItemByPostVar(), ILIAS\FileDelivery\http(), ILIAS\Repository\lng(), ILIAS\Repository\refinery(), and ILIAS\Repository\settings().

+ Here is the call graph for this function:

Field Documentation

◆ $http

ILIAS HTTP GlobalHttpState ilCronDeleteNeverLoggedInUserAccounts::$http
private

◆ $lng

ilLanguage ilCronDeleteNeverLoggedInUserAccounts::$lng
private

◆ $main_tpl

ilGlobalTemplateInterface ilCronDeleteNeverLoggedInUserAccounts::$main_tpl
private

◆ $objectDataCache

ilObjectDataCache ilCronDeleteNeverLoggedInUserAccounts::$objectDataCache
private

◆ $rbacreview

ilRbacReview ilCronDeleteNeverLoggedInUserAccounts::$rbacreview
private

◆ $refinery

ILIAS Refinery Factory ilCronDeleteNeverLoggedInUserAccounts::$refinery
private

◆ $roleIdWhiteliste

string ilCronDeleteNeverLoggedInUserAccounts::$roleIdWhiteliste = ''
private

◆ $settings

ilSetting ilCronDeleteNeverLoggedInUserAccounts::$settings
private

◆ $thresholdInDays

int ilCronDeleteNeverLoggedInUserAccounts::$thresholdInDays = self::DEFAULT_CREATION_THRESHOLD
private

◆ DEFAULT_CREATION_THRESHOLD

const ilCronDeleteNeverLoggedInUserAccounts::DEFAULT_CREATION_THRESHOLD = 365
private

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

Referenced by __construct().


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