ILIAS  release_7 Revision v7.30-3-g800a261c036
ilCronDeleteNeverLoggedInUserAccounts Class Reference

Class ilCronDeleteNeverLoggedInUserAccounts. More...

+ Inheritance diagram for ilCronDeleteNeverLoggedInUserAccounts:
+ Collaboration diagram for ilCronDeleteNeverLoggedInUserAccounts:

Public Member Functions

 __construct ()
 ilCronDeleteNeverLoggedInUserAccounts constructor. More...
 
 getId ()
 
 getTitle ()
 
 getDescription ()
 
 getDefaultScheduleType ()
 
 getDefaultScheduleValue ()
 
 hasAutoActivation ()
 
 hasFlexibleSchedule ()
 
 hasCustomSettings ()
 
 run ()
 
 addCustomSettingsToForm (\ilPropertyFormGUI $a_form)
 
 saveCustomSettings (\ilPropertyFormGUI $a_form)
 
- Public Member Functions inherited from ilCronJob
 isActive ($a_ts_last_run, $a_schedule_type, $a_schedule_value, $a_manual=false)
 Is job currently active? More...
 
 getScheduleType ()
 Get current schedule type (if flexible) More...
 
 getScheduleValue ()
 Get current schedule value (if flexible) More...
 
 setSchedule ($a_type, $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...
 
 getTitle ()
 Get title. More...
 
 getDescription ()
 Get description. More...
 
 isManuallyExecutable ()
 Defines whether or not a cron job can be started manually. More...
 
 hasCustomSettings ()
 Has cron job any custom setting which can be edited? More...
 
 addCustomSettingsToForm (ilPropertyFormGUI $a_form)
 Add custom settings to form. More...
 
 saveCustomSettings (ilPropertyFormGUI $a_form)
 Save custom settings. More...
 
 addToExternalSettingsForm ($a_form_id, array &$a_fields, $a_is_active)
 Add external settings to form. More...
 
 activationWasToggled ($a_currently_active)
 Cron job status was changed. More...
 
 getId ()
 Get id. More...
 
 hasAutoActivation ()
 Is to be activated on "installation". More...
 
 hasFlexibleSchedule ()
 Can the schedule be configured? More...
 
 getDefaultScheduleType ()
 Get schedule type. More...
 
 getDefaultScheduleValue ()
 Get schedule value. More...
 
 run ()
 Run job. More...
 

Data Fields

const DEFAULT_CREATION_THRESHOLD = 365
 
- Data Fields inherited from ilCronJob
const SCHEDULE_TYPE_DAILY = 1
 
const SCHEDULE_TYPE_IN_MINUTES = 2
 
const SCHEDULE_TYPE_IN_HOURS = 3
 
const SCHEDULE_TYPE_IN_DAYS = 4
 
const SCHEDULE_TYPE_WEEKLY = 5
 
const SCHEDULE_TYPE_MONTHLY = 6
 
const SCHEDULE_TYPE_QUARTERLY = 7
 
const SCHEDULE_TYPE_YEARLY = 8
 

Protected Member Functions

 hasDecimals ($number)
 
- Protected Member Functions inherited from ilCronJob
 checkSchedule ($a_ts_last_run, $a_schedule_type, $a_schedule_value)
 

Protected Attributes

 $lng
 
 $settings
 
 $rbacreview
 
 $objectDataCache
 
 $request
 

Private Attributes

 $roleIdWhiteliste = ''
 
 $thresholdInDays = self::DEFAULT_CREATION_THRESHOLD
 

Detailed Description

Constructor & Destructor Documentation

◆ __construct()

ilCronDeleteNeverLoggedInUserAccounts::__construct ( )

ilCronDeleteNeverLoggedInUserAccounts constructor.

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

References $DIC, and settings().

36  {
37  global $DIC;
38 
39  if ($DIC) {
40  if (isset($DIC['ilSetting'])) {
41  $this->settings = $DIC->settings();
42 
43  $this->roleIdWhiteliste = (string) $this->settings->get(
44  'cron_users_without_login_delete_incl_roles',
45  ''
46  );
47 
48  $this->thresholdInDays = (int) $this->settings->get(
49  'cron_users_without_login_delete_threshold',
50  self::DEFAULT_CREATION_THRESHOLD
51  );
52  }
53 
54  if (isset($DIC['lng'])) {
55  $this->lng = $DIC->language();
56  $this->lng->loadLanguageModule('usr');
57  }
58 
59  if (isset($DIC['rbacreview'])) {
60  $this->rbacreview = $DIC->rbac()->review();
61  }
62 
63  if (isset($DIC['ilObjDataCache'])) {
64  $this->objectDataCache = $DIC['ilObjDataCache'];
65  }
66 
67  if (isset($DIC['http'])) {
68  $this->request = $DIC->http()->request();
69  }
70  }
71  }
settings()
Definition: settings.php:2
global $DIC
Definition: goto.php:24
+ Here is the call graph for this function:

Member Function Documentation

◆ addCustomSettingsToForm()

ilCronDeleteNeverLoggedInUserAccounts::addCustomSettingsToForm ( \ilPropertyFormGUI  $a_form)

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

References ilPropertyFormGUI\addItem(), ANONYMOUS_ROLE_ID, and ilFormPropertyGUI\setInfo().

210  {
211  $roleWhiteList = new ilMultiSelectInputGUI(
212  $this->lng->txt('cron_users_without_login_del_role_whitelist'),
213  'role_whitelist'
214  );
215  $roleWhiteList->setInfo($this->lng->txt('cron_users_without_login_del_role_whitelist_info'));
216  $roles = array();
217  foreach ($this->rbacreview->getGlobalRoles() as $role_id) {
218  if ($role_id != ANONYMOUS_ROLE_ID) {
219  $roles[$role_id] = $this->objectDataCache->lookupTitle($role_id);
220  }
221  }
222  $roleWhiteList->setOptions($roles);
223  $roleWhiteList->setValue(array_filter(array_map('intval', explode(',', $this->roleIdWhiteliste))));
224  $roleWhiteList->setWidth(300);
225  $a_form->addItem($roleWhiteList);
226 
227  $threshold = new ilNumberInputGUI(
228  $this->lng->txt('cron_users_without_login_del_create_date_thr'),
229  'threshold'
230  );
231  $threshold->setInfo($this->lng->txt('cron_users_without_login_del_create_date_thr_info'));
232  $threshold->setValue($this->thresholdInDays);
233  $threshold->setSuffix($this->lng->txt('days'));
234  $threshold->setSize(4);
235  $threshold->setMaxLength(4);
236  $threshold->setRequired(true);
237  $a_form->addItem($threshold);
238  }
setInfo($a_info)
Set Information Text.
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:26
+ Here is the call graph for this function:

◆ getDefaultScheduleType()

ilCronDeleteNeverLoggedInUserAccounts::getDefaultScheduleType ( )

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

105  {
106  return self::SCHEDULE_TYPE_DAILY;
107  }

◆ getDefaultScheduleValue()

ilCronDeleteNeverLoggedInUserAccounts::getDefaultScheduleValue ( )

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

113  {
114  return 1;
115  }

◆ getDescription()

ilCronDeleteNeverLoggedInUserAccounts::getDescription ( )

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

References $DIC.

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

◆ getId()

ilCronDeleteNeverLoggedInUserAccounts::getId ( )

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

77  {
78  return 'user_never_logged_in';
79  }

◆ getTitle()

ilCronDeleteNeverLoggedInUserAccounts::getTitle ( )

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

References $DIC.

85  {
86  global $DIC;
87 
88  return $DIC->language()->txt('user_never_logged_in');
89  }
global $DIC
Definition: goto.php:24

◆ hasAutoActivation()

ilCronDeleteNeverLoggedInUserAccounts::hasAutoActivation ( )

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

121  {
122  return false;
123  }

◆ hasCustomSettings()

ilCronDeleteNeverLoggedInUserAccounts::hasCustomSettings ( )

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

137  {
138  return true;
139  }

◆ hasDecimals()

ilCronDeleteNeverLoggedInUserAccounts::hasDecimals (   $number)
protected
Parameters
mixed$number
Returns
bool

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

Referenced by saveCustomSettings().

277  : bool
278  {
279  if (strpos($number, ',') !== false || strpos($number, '.') !== false) {
280  return true;
281  }
282 
283  return false;
284  }
+ Here is the caller graph for this function:

◆ hasFlexibleSchedule()

ilCronDeleteNeverLoggedInUserAccounts::hasFlexibleSchedule ( )

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

129  {
130  return true;
131  }

◆ run()

ilCronDeleteNeverLoggedInUserAccounts::run ( )

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

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

145  {
146  global $DIC;
147 
148  $result = new \ilCronJobResult();
149 
151  $message = 'No user deleted';
152 
154  $this->thresholdInDays ?: self::DEFAULT_CREATION_THRESHOLD
155  );
156 
157  $roleIdWhitelist = array_filter(array_map('intval', explode(',', $this->roleIdWhiteliste)));
158 
159  $counter = 0;
160  foreach ($userIds as $userId) {
161  if ($userId == ANONYMOUS_USER_ID || $userId == SYSTEM_USER_ID) {
162  continue;
163  }
164 
165  $user = ilObjectFactory::getInstanceByObjId($userId, false);
166  if (!$user || !($user instanceof \ilObjUser)) {
167  continue;
168  }
169 
170  $ignoreUser = true;
171 
172  if (count($roleIdWhitelist) > 0) {
173  $assignedRoleIds = array_filter(array_map('intval', (array) $this->rbacreview->assignedRoles($userId)));
174 
175  $respectedRolesToInclude = array_intersect($assignedRoleIds, $roleIdWhitelist);
176  if (count($respectedRolesToInclude) > 0) {
177  $ignoreUser = false;
178  }
179  }
180 
181  if ($ignoreUser) {
182  continue;
183  }
184 
185  $DIC->logger()->usr()->info(sprintf(
186  "Deleting user account with id %s (login: %s)",
187  $user->getId(),
188  $user->getLogin()
189  ));
190  $user->delete();
191 
192  $counter++;
193  }
194 
195  if ($counter) {
196  $status = \ilCronJobResult::STATUS_OK;
197  $message = sprintf('%s user(s) deleted', $counter);
198  }
199 
200  $result->setStatus($status);
201  $result->setMessage($message);
202 
203  return $result;
204  }
const ANONYMOUS_USER_ID
Definition: constants.php:25
$result
const SYSTEM_USER_ID
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: constants.php:24
global $DIC
Definition: goto.php:24
static getInstanceByObjId($a_obj_id, $stop_on_error=true)
get an instance of an Ilias object by object id
$message
Definition: xapiexit.php:14
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 243 of file class.ilCronDeleteNeverLoggedInUserAccounts.php.

References $valid, ilPropertyFormGUI\getItemByPostVar(), hasDecimals(), ilUtil\sendFailure(), and settings().

244  {
245  $valid = true;
246 
247  $roleIdWhitelist = $this->request->getParsedBody()['role_whitelist'] ?? [];
248  $this->roleIdWhiteliste = implode(',', array_map('intval', (is_array($roleIdWhitelist) ? $roleIdWhitelist : [])));
249 
250  $this->thresholdInDays = $this->request->getParsedBody()['threshold'] ?? '';
251 
252  if (!is_numeric($this->thresholdInDays) || $this->hasDecimals($this->thresholdInDays)) {
253  $valid = false;
254  $a_form->getItemByPostVar('threshold')->setAlert($this->lng->txt('user_never_logged_in_info_threshold_err_num'));
255  }
256 
257  if ($valid) {
258  $this->settings->set(
259  'cron_users_without_login_delete_incl_roles',
260  (string) $this->roleIdWhiteliste
261  );
262  $this->settings->set(
263  'cron_users_without_login_delete_threshold',
264  (int) $this->thresholdInDays
265  );
266  return true;
267  } else {
268  \ilUtil::sendFailure($this->lng->txt('form_input_not_valid'));
269  return false;
270  }
271  }
settings()
Definition: settings.php:2
$valid
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
+ Here is the call graph for this function:

Field Documentation

◆ $lng

ilCronDeleteNeverLoggedInUserAccounts::$lng
protected

◆ $objectDataCache

ilCronDeleteNeverLoggedInUserAccounts::$objectDataCache
protected

◆ $rbacreview

ilCronDeleteNeverLoggedInUserAccounts::$rbacreview
protected

◆ $request

ilCronDeleteNeverLoggedInUserAccounts::$request
protected

◆ $roleIdWhiteliste

ilCronDeleteNeverLoggedInUserAccounts::$roleIdWhiteliste = ''
private

◆ $settings

ilCronDeleteNeverLoggedInUserAccounts::$settings
protected

◆ $thresholdInDays

ilCronDeleteNeverLoggedInUserAccounts::$thresholdInDays = self::DEFAULT_CREATION_THRESHOLD
private

◆ DEFAULT_CREATION_THRESHOLD

const ilCronDeleteNeverLoggedInUserAccounts::DEFAULT_CREATION_THRESHOLD = 365

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