ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
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
 
ilLanguage $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 38 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().

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

Member Function Documentation

◆ addCustomSettingsToForm()

ilCronDeleteNeverLoggedInUserAccounts::addCustomSettingsToForm ( ilPropertyFormGUI  $a_form)

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

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

187  : void
188  {
189  $roleWhiteList = new ilMultiSelectInputGUI(
190  $this->lng->txt('cron_users_without_login_del_role_whitelist'),
191  'role_whitelist'
192  );
193  $roleWhiteList->setInfo($this->lng->txt('cron_users_without_login_del_role_whitelist_info'));
194  $roles = [];
195  foreach ($this->rbacreview->getGlobalRoles() as $role_id) {
196  if ($role_id !== ANONYMOUS_ROLE_ID) {
197  $roles[$role_id] = $this->objectDataCache->lookupTitle($role_id);
198  }
199  }
200  $roleWhiteList->setOptions($roles);
201  $roleWhiteList->setValue(array_filter(array_map('intval', explode(',', $this->roleIdWhiteliste))));
202  $roleWhiteList->setWidth(300);
203  $a_form->addItem($roleWhiteList);
204 
205  $threshold = new ilNumberInputGUI(
206  $this->lng->txt('cron_users_without_login_del_create_date_thr'),
207  'threshold'
208  );
209  $threshold->allowDecimals(false);
210  $threshold->setInfo($this->lng->txt('cron_users_without_login_del_create_date_thr_info'));
211  $threshold->setValue((string) $this->thresholdInDays);
212  $threshold->setSuffix($this->lng->txt('days'));
213  $threshold->setSize(4);
214  $threshold->setMaxLength(4);
215  $threshold->setRequired(true);
216  $a_form->addItem($threshold);
217  }
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 100 of file class.ilCronDeleteNeverLoggedInUserAccounts.php.

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

◆ getDefaultScheduleValue()

ilCronDeleteNeverLoggedInUserAccounts::getDefaultScheduleValue ( )

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

105  : int
106  {
107  return 1;
108  }

◆ getDescription()

ilCronDeleteNeverLoggedInUserAccounts::getDescription ( )

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

References $DIC.

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

◆ getId()

ilCronDeleteNeverLoggedInUserAccounts::getId ( )

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

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

◆ getTitle()

ilCronDeleteNeverLoggedInUserAccounts::getTitle ( )

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

References $DIC.

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

◆ hasAutoActivation()

ilCronDeleteNeverLoggedInUserAccounts::hasAutoActivation ( )

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

110  : bool
111  {
112  return false;
113  }

◆ hasCustomSettings()

ilCronDeleteNeverLoggedInUserAccounts::hasCustomSettings ( )

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

120  : bool
121  {
122  return true;
123  }

◆ hasFlexibleSchedule()

ilCronDeleteNeverLoggedInUserAccounts::hasFlexibleSchedule ( )

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

115  : bool
116  {
117  return true;
118  }

◆ run()

ilCronDeleteNeverLoggedInUserAccounts::run ( )

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

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

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

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

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

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