ILIAS  release_8 Revision v8.23
ilCronDeleteInactivatedUserAccounts Class Reference
+ Inheritance diagram for ilCronDeleteInactivatedUserAccounts:
+ Collaboration diagram for ilCronDeleteInactivatedUserAccounts:

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, ?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_INACTIVITY_PERIOD = 365
 
int $period
 
array $include_roles
 
ilSetting $settings
 
ilLanguage $lng
 
ilRbacReview $rbacReview
 
ilObjectDataCache $objectDataCache
 
ILIAS HTTP GlobalHttpState $http
 
ILIAS Refinery Factory $refinery
 

Additional Inherited Members

- Data Fields inherited from ilCronJob
const SCHEDULE_TYPE_DAILY = 1
 This will be replaced with an ENUM in ILIAS 9 More...
 
const SCHEDULE_TYPE_IN_MINUTES = 2
 This will be replaced with an ENUM in ILIAS 9 More...
 
const SCHEDULE_TYPE_IN_HOURS = 3
 This will be replaced with an ENUM in ILIAS 9 More...
 
const SCHEDULE_TYPE_IN_DAYS = 4
 This will be replaced with an ENUM in ILIAS 9 More...
 
const SCHEDULE_TYPE_WEEKLY = 5
 This will be replaced with an ENUM in ILIAS 9 More...
 
const SCHEDULE_TYPE_MONTHLY = 6
 This will be replaced with an ENUM in ILIAS 9 More...
 
const SCHEDULE_TYPE_QUARTERLY = 7
 This will be replaced with an ENUM in ILIAS 9 More...
 
const SCHEDULE_TYPE_YEARLY = 8
 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()

ilCronDeleteInactivatedUserAccounts::__construct ( )

Definition at line 41 of file class.ilCronDeleteInactivatedUserAccounts.php.

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

42  {
43  global $DIC;
44 
45  if ($DIC) {
46  if (isset($DIC['http'])) {
47  $this->http = $DIC->http();
48  }
49 
50  if (isset($DIC['lng'])) {
51  $this->lng = $DIC->language();
52  }
53 
54  if (isset($DIC['refinery'])) {
55  $this->refinery = $DIC->refinery();
56  }
57 
58  if (isset($DIC['ilObjDataCache'])) {
59  $this->objectDataCache = $DIC['ilObjDataCache'];
60  }
61 
62  if (isset($DIC['rbacreview'])) {
63  $this->rbacReview = $DIC->rbac()->review();
64  }
65 
66  $rbacreview = $DIC->rbac()->review();
67  $ilObjDataCache = $DIC['ilObjDataCache'];
68 
69  if ($DIC['ilSetting']) {
70  $this->settings = $DIC->settings();
71 
72  $include_roles = $this->settings->get(
73  'cron_inactivated_user_delete_include_roles',
74  null
75  );
76  if ($include_roles === null) {
77  $this->include_roles = [];
78  } else {
79  $this->include_roles = array_filter(array_map('intval', explode(',', $include_roles)));
80  }
81 
82  $this->period = (int) $this->settings->get(
83  'cron_inactivated_user_delete_period',
84  (string) self::DEFAULT_INACTIVITY_PERIOD
85  );
86  }
87  }
88  }
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()

ilCronDeleteInactivatedUserAccounts::addCustomSettingsToForm ( ilPropertyFormGUI  $a_form)

Definition at line 177 of file class.ilCronDeleteInactivatedUserAccounts.php.

References ilPropertyFormGUI\addItem(), ilNumberInputGUI\allowDecimals(), ANONYMOUS_ROLE_ID, ILIAS\Repository\lng(), ilFormPropertyGUI\setInfo(), and ILIAS\Repository\settings().

177  : void
178  {
179  $sub_mlist = new ilMultiSelectInputGUI(
180  $this->lng->txt('delete_inactivated_user_accounts_include_roles'),
181  'cron_inactivated_user_delete_include_roles'
182  );
183  $sub_mlist->setInfo($this->lng->txt('delete_inactivated_user_accounts_include_roles_desc'));
184  $roles = [];
185  foreach ($this->rbacReview->getGlobalRoles() as $role_id) {
186  if ($role_id !== ANONYMOUS_ROLE_ID) {
187  $roles[$role_id] = $this->objectDataCache->lookupTitle($role_id);
188  }
189  }
190  $sub_mlist->setOptions($roles);
191  $setting = $this->settings->get('cron_inactivated_user_delete_include_roles', null);
192  if ($setting === null) {
193  $setting = [];
194  } else {
195  $setting = explode(',', $setting);
196  }
197  $sub_mlist->setValue($setting);
198  $sub_mlist->setWidth(300);
199  $a_form->addItem($sub_mlist);
200 
201  $sub_text = new ilNumberInputGUI(
202  $this->lng->txt('delete_inactivated_user_accounts_period'),
203  'cron_inactivated_user_delete_period'
204  );
205  $sub_text->allowDecimals(false);
206  $sub_text->setInfo($this->lng->txt('delete_inactivated_user_accounts_period_desc'));
207  $sub_text->setValue(
208  $this->settings->get(
209  'cron_inactivated_user_delete_period',
210  (string) self::DEFAULT_INACTIVITY_PERIOD
211  )
212  );
213  $sub_text->setSize(4);
214  $sub_text->setMaxLength(4);
215  $sub_text->setRequired(true);
216  $a_form->addItem($sub_text);
217  }
allowDecimals(bool $a_value)
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
+ Here is the call graph for this function:

◆ getDefaultScheduleType()

ilCronDeleteInactivatedUserAccounts::getDefaultScheduleType ( )

Definition at line 108 of file class.ilCronDeleteInactivatedUserAccounts.php.

108  : int
109  {
110  return self::SCHEDULE_TYPE_DAILY;
111  }

◆ getDefaultScheduleValue()

ilCronDeleteInactivatedUserAccounts::getDefaultScheduleValue ( )

Definition at line 113 of file class.ilCronDeleteInactivatedUserAccounts.php.

113  : ?int
114  {
115  return null;
116  }

◆ getDescription()

ilCronDeleteInactivatedUserAccounts::getDescription ( )

Definition at line 100 of file class.ilCronDeleteInactivatedUserAccounts.php.

References $period, and ILIAS\Repository\lng().

100  : string
101  {
102  return sprintf(
103  $this->lng->txt("delete_inactivated_user_accounts_desc"),
105  );
106  }
+ Here is the call graph for this function:

◆ getId()

ilCronDeleteInactivatedUserAccounts::getId ( )

Definition at line 90 of file class.ilCronDeleteInactivatedUserAccounts.php.

90  : string
91  {
92  return "user_inactivated";
93  }

◆ getTitle()

ilCronDeleteInactivatedUserAccounts::getTitle ( )

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

References ILIAS\Repository\lng().

95  : string
96  {
97  return $this->lng->txt("delete_inactivated_user_accounts");
98  }
+ Here is the call graph for this function:

◆ hasAutoActivation()

ilCronDeleteInactivatedUserAccounts::hasAutoActivation ( )

Definition at line 118 of file class.ilCronDeleteInactivatedUserAccounts.php.

118  : bool
119  {
120  return false;
121  }

◆ hasCustomSettings()

ilCronDeleteInactivatedUserAccounts::hasCustomSettings ( )

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

128  : bool
129  {
130  return true;
131  }

◆ hasFlexibleSchedule()

ilCronDeleteInactivatedUserAccounts::hasFlexibleSchedule ( )

Definition at line 123 of file class.ilCronDeleteInactivatedUserAccounts.php.

123  : bool
124  {
125  return true;
126  }

◆ run()

ilCronDeleteInactivatedUserAccounts::run ( )

Definition at line 133 of file class.ilCronDeleteInactivatedUserAccounts.php.

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

134  {
135  global $DIC;
136 
137  $rbacreview = $DIC->rbac()->review();
138 
140 
141  $usr_ids = ilObjUser::_getUserIdsByInactivationPeriod($this->period);
142 
143  $counter = 0;
144  foreach ($usr_ids as $usr_id) {
145  if ($usr_id === ANONYMOUS_USER_ID || $usr_id === SYSTEM_USER_ID) {
146  continue;
147  }
148 
149  $continue = true;
150  foreach ($this->include_roles as $role_id) {
151  if ($rbacreview->isAssigned($usr_id, $role_id)) {
152  $continue = false;
153  break;
154  }
155  }
156 
157  if ($continue) {
158  continue;
159  }
160 
161  $user = ilObjectFactory::getInstanceByObjId($usr_id);
162  $user->delete();
163 
164  $counter++;
165  }
166 
167  if ($counter > 0) {
168  $status = ilCronJobResult::STATUS_OK;
169  }
170 
171  $result = new ilCronJobResult();
172  $result->setStatus($status);
173 
174  return $result;
175  }
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
static _getUserIdsByInactivationPeriod(int $period)
get ids of all users that have been inactivated since at least the given period
static getInstanceByObjId(?int $obj_id, bool $stop_on_error=true)
get an instance of an Ilias object by object id
+ Here is the call graph for this function:

◆ saveCustomSettings()

ilCronDeleteInactivatedUserAccounts::saveCustomSettings ( ilPropertyFormGUI  $a_form)

Definition at line 219 of file class.ilCronDeleteInactivatedUserAccounts.php.

References ILIAS\FileDelivery\http(), ILIAS\Repository\refinery(), and ILIAS\Repository\settings().

219  : bool
220  {
221  $roles = implode(',', $this->http->wrapper()->post()->retrieve(
222  'cron_inactivated_user_delete_include_roles',
223  $this->refinery->byTrying([
224  $this->refinery->kindlyTo()->listOf($this->refinery->kindlyTo()->int()),
225  $this->refinery->always([])
226  ])
227  ));
228 
229  $period = $this->http->wrapper()->post()->retrieve(
230  'cron_inactivated_user_delete_period',
231  $this->refinery->byTrying([
232  $this->refinery->kindlyTo()->int(),
233  $this->refinery->always(null)
234  ])
235  );
236 
237  $this->settings->set('cron_inactivated_user_delete_include_roles', $roles);
238  $this->settings->set('cron_inactivated_user_delete_period', (string) ($period ?? self::DEFAULT_INACTIVITY_PERIOD));
239 
240  return true;
241  }
static http()
Fetches the global http state from ILIAS.
+ Here is the call graph for this function:

Field Documentation

◆ $http

ILIAS HTTP GlobalHttpState ilCronDeleteInactivatedUserAccounts::$http
private

◆ $include_roles

array ilCronDeleteInactivatedUserAccounts::$include_roles
private

◆ $lng

ilLanguage ilCronDeleteInactivatedUserAccounts::$lng
private

◆ $objectDataCache

ilObjectDataCache ilCronDeleteInactivatedUserAccounts::$objectDataCache
private

◆ $period

int ilCronDeleteInactivatedUserAccounts::$period
private

Definition at line 31 of file class.ilCronDeleteInactivatedUserAccounts.php.

Referenced by getDescription().

◆ $rbacReview

ilRbacReview ilCronDeleteInactivatedUserAccounts::$rbacReview
private

◆ $refinery

ILIAS Refinery Factory ilCronDeleteInactivatedUserAccounts::$refinery
private

◆ $settings

ilSetting ilCronDeleteInactivatedUserAccounts::$settings
private

◆ DEFAULT_INACTIVITY_PERIOD

const ilCronDeleteInactivatedUserAccounts::DEFAULT_INACTIVITY_PERIOD = 365
private

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