ILIAS  release_10 Revision v10.1-43-ga1241a92c2f
ilCronDeleteNeverLoggedInUserAccounts Class Reference
+ Inheritance diagram for ilCronDeleteNeverLoggedInUserAccounts:
+ Collaboration diagram for ilCronDeleteNeverLoggedInUserAccounts:

Public Member Functions

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

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 ilCronJob
CronJobScheduleType $schedule_type = null
 
int $schedule_value = null
 
Closure $date_time_provider = null
 

Detailed Description

Constructor & Destructor Documentation

◆ __construct()

ilCronDeleteNeverLoggedInUserAccounts::__construct ( )

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

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

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

Member Function Documentation

◆ addCustomSettingsToForm()

ilCronDeleteNeverLoggedInUserAccounts::addCustomSettingsToForm ( ilPropertyFormGUI  $a_form)

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

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

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

◆ getDefaultScheduleType()

ilCronDeleteNeverLoggedInUserAccounts::getDefaultScheduleType ( )

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

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

◆ getDefaultScheduleValue()

ilCronDeleteNeverLoggedInUserAccounts::getDefaultScheduleValue ( )

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

106  : int
107  {
108  return 1;
109  }

◆ getDescription()

ilCronDeleteNeverLoggedInUserAccounts::getDescription ( )

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

References $DIC.

94  : string
95  {
96  global $DIC;
97 
98  return $DIC->language()->txt('user_never_logged_in_info');
99  }
global $DIC
Definition: shib_login.php:25

◆ getId()

ilCronDeleteNeverLoggedInUserAccounts::getId ( )

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

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

◆ getTitle()

ilCronDeleteNeverLoggedInUserAccounts::getTitle ( )

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

References $DIC.

87  : string
88  {
89  global $DIC;
90 
91  return $DIC->language()->txt('user_never_logged_in');
92  }
global $DIC
Definition: shib_login.php:25

◆ hasAutoActivation()

ilCronDeleteNeverLoggedInUserAccounts::hasAutoActivation ( )

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

111  : bool
112  {
113  return false;
114  }

◆ hasCustomSettings()

ilCronDeleteNeverLoggedInUserAccounts::hasCustomSettings ( )

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

121  : bool
122  {
123  return true;
124  }

◆ hasFlexibleSchedule()

ilCronDeleteNeverLoggedInUserAccounts::hasFlexibleSchedule ( )

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

116  : bool
117  {
118  return true;
119  }

◆ run()

ilCronDeleteNeverLoggedInUserAccounts::run ( )

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

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

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

◆ saveCustomSettings()

ilCronDeleteNeverLoggedInUserAccounts::saveCustomSettings ( ilPropertyFormGUI  $a_form)

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

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

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

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