ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
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 ILIAS\Cron\CronJob
 setDateTimeProvider (?\Closure $date_time_provider)
 
 isDue (?\DateTimeImmutable $last_run, ?JobScheduleType $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 (?JobScheduleType $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 ()
 
 usesLegacyForms ()
 
 getCustomConfigurationInput (\ILIAS\UI\Factory $ui_factory, \ILIAS\Refinery\Factory $factory, \ilLanguage $lng)
 
 addCustomSettingsToForm (\ilPropertyFormGUI $a_form)
 
 saveCustomConfiguration (mixed $form_data)
 
 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
 
Language $lng
 
ilSetting $settings
 
ilRbacReview $rbacreview
 
ilObjectDataCache $objectDataCache
 
ILIAS HTTP GlobalHttpState $http
 
ILIAS Refinery Factory $refinery
 
ilGlobalTemplateInterface $main_tpl
 

Additional Inherited Members

- Protected Attributes inherited from ILIAS\Cron\CronJob
JobScheduleType $schedule_type = null
 
int $schedule_value = null
 
Closure $date_time_provider = null
 

Detailed Description

Constructor & Destructor Documentation

◆ __construct()

ilCronDeleteNeverLoggedInUserAccounts::__construct ( )

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

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

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

+ Here is the call graph for this function:

Member Function Documentation

◆ addCustomSettingsToForm()

ilCronDeleteNeverLoggedInUserAccounts::addCustomSettingsToForm ( ilPropertyFormGUI  $a_form)

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

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

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

+ Here is the call graph for this function:

◆ getDefaultScheduleType()

ilCronDeleteNeverLoggedInUserAccounts::getDefaultScheduleType ( )

Reimplemented from ILIAS\Cron\CronJob.

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

103 {
104 return JobScheduleType::DAILY;
105 }

◆ getDefaultScheduleValue()

ilCronDeleteNeverLoggedInUserAccounts::getDefaultScheduleValue ( )

Reimplemented from ILIAS\Cron\CronJob.

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

107 : int
108 {
109 return 1;
110 }

◆ getDescription()

ilCronDeleteNeverLoggedInUserAccounts::getDescription ( )

Reimplemented from ILIAS\Cron\CronJob.

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

95 : string
96 {
97 global $DIC;
98
99 return $DIC->language()->txt('user_never_logged_in_info');
100 }

References $DIC.

◆ getId()

ilCronDeleteNeverLoggedInUserAccounts::getId ( )

Reimplemented from ILIAS\Cron\CronJob.

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

83 : string
84 {
85 return 'user_never_logged_in';
86 }

◆ getTitle()

ilCronDeleteNeverLoggedInUserAccounts::getTitle ( )

Reimplemented from ILIAS\Cron\CronJob.

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

88 : string
89 {
90 global $DIC;
91
92 return $DIC->language()->txt('user_never_logged_in');
93 }

References $DIC.

◆ hasAutoActivation()

ilCronDeleteNeverLoggedInUserAccounts::hasAutoActivation ( )

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

Reimplemented from ILIAS\Cron\CronJob.

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

112 : bool
113 {
114 return false;
115 }

◆ hasCustomSettings()

ilCronDeleteNeverLoggedInUserAccounts::hasCustomSettings ( )

Reimplemented from ILIAS\Cron\CronJob.

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

122 : bool
123 {
124 return true;
125 }

◆ hasFlexibleSchedule()

ilCronDeleteNeverLoggedInUserAccounts::hasFlexibleSchedule ( )

Reimplemented from ILIAS\Cron\CronJob.

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

117 : bool
118 {
119 return true;
120 }

◆ run()

ilCronDeleteNeverLoggedInUserAccounts::run ( )

Reimplemented from ILIAS\Cron\CronJob.

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

127 : JobResult
128 {
129 global $DIC;
130
131 $result = new JobResult();
132
133 $status = JobResult::STATUS_NO_ACTION;
134 $message = 'No user deleted';
135
137 $this->thresholdInDays ?: self::DEFAULT_CREATION_THRESHOLD
138 );
139
140 $roleIdWhitelist = array_filter(array_map('intval', explode(',', $this->roleIdWhiteliste)));
141
142 $counter = 0;
143 foreach ($userIds as $userId) {
144 if ($userId === ANONYMOUS_USER_ID || $userId === SYSTEM_USER_ID) {
145 continue;
146 }
147
148 $user = ilObjectFactory::getInstanceByObjId($userId, false);
149 if (!($user instanceof ilObjUser)) {
150 continue;
151 }
152
153 $ignoreUser = true;
154
155 if (count($roleIdWhitelist) > 0) {
156 $assignedRoleIds = array_filter(array_map('intval', $this->rbacreview->assignedRoles($userId)));
157
158 $respectedRolesToInclude = array_intersect($assignedRoleIds, $roleIdWhitelist);
159 if (count($respectedRolesToInclude) > 0) {
160 $ignoreUser = false;
161 }
162 }
163
164 if ($ignoreUser) {
165 continue;
166 }
167
168 $DIC->logger()->user()->info(sprintf(
169 "Deleting user account with id %s (login: %s)",
170 $user->getId(),
171 $user->getLogin()
172 ));
173 $user->delete();
174
175 $counter++;
176 }
177
178 if ($counter) {
179 $status = JobResult::STATUS_OK;
180 $message = sprintf('%s user(s) deleted', $counter);
181 }
182
183 $result->setStatus($status);
184 $result->setMessage($message);
185
186 return $result;
187 }
User class.
static getUserIdsNeverLoggedIn(int $thresholdInDays)
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
$counter
$message
Definition: xapiexit.php:31

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

+ Here is the call graph for this function:

◆ saveCustomSettings()

ilCronDeleteNeverLoggedInUserAccounts::saveCustomSettings ( ilPropertyFormGUI  $a_form)

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

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

Language 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 28 of file class.ilCronDeleteNeverLoggedInUserAccounts.php.

Referenced by __construct().


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