ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.ilCronDeleteInactivatedUserAccounts.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
4 include_once "Services/Cron/classes/class.ilCronJob.php";
5 
15 {
17 
18  private $period = null;
19 
20  private $include_roles = null;
21 
22  public function __construct()
23  {
24  global $DIC;
25 
26  $ilSetting = $DIC['ilSetting'];
27 
28  if (is_object($ilSetting)) {
29  $this->include_roles = $ilSetting->get(
30  'cron_inactivated_user_delete_include_roles',
31  null
32  );
33  if ($this->include_roles === null) {
34  $this->include_roles = array();
35  } else {
36  $this->include_roles = explode(',', $this->include_roles);
37  }
38 
39  $this->period = $ilSetting->get(
40  'cron_inactivated_user_delete_period',
41  self::DEFAULT_INACTIVITY_PERIOD
42  );
43  }
44  }
45 
46  public function getId()
47  {
48  return "user_inactivated";
49  }
50 
51  public function getTitle()
52  {
53  global $DIC;
54 
55  $lng = $DIC['lng'];
56 
57  return $lng->txt("delete_inactivated_user_accounts");
58  }
59 
60  public function getDescription()
61  {
62  global $DIC;
63 
64  $lng = $DIC['lng'];
65 
66  return sprintf(
67  $lng->txt("delete_inactivated_user_accounts_desc"),
69  );
70  }
71 
72  public function getDefaultScheduleType()
73  {
74  return self::SCHEDULE_TYPE_DAILY;
75  }
76 
77  public function getDefaultScheduleValue()
78  {
79  return;
80  }
81 
82  public function hasAutoActivation()
83  {
84  return false;
85  }
86 
87  public function hasFlexibleSchedule()
88  {
89  return true;
90  }
91 
92  public function hasCustomSettings()
93  {
94  return true;
95  }
96 
97  public function run()
98  {
99  global $DIC;
100 
101  $rbacreview = $DIC['rbacreview'];
102 
104 
105  $usr_ids = ilObjUser::_getUserIdsByInactivationPeriod($this->period);
106 
107  $counter = 0;
108  foreach ($usr_ids as $usr_id) {
109  if ($usr_id == ANONYMOUS_USER_ID || $usr_id == SYSTEM_USER_ID) {
110  continue;
111  }
112 
113  $continue = true;
114  foreach ($this->include_roles as $role_id) {
115  if ($rbacreview->isAssigned($usr_id, $role_id)) {
116  $continue = false;
117  break;
118  }
119  }
120  if ($continue) {
121  continue;
122  }
123 
125 
126  $user->delete();
127 
128  $counter++;
129  }
130 
131  if ($counter) {
132  $status = ilCronJobResult::STATUS_OK;
133  }
134  $result = new ilCronJobResult();
135  $result->setStatus($status);
136  return $result;
137  }
138 
140  {
141  global $DIC;
142 
143  $lng = $DIC['lng'];
144  $rbacreview = $DIC['rbacreview'];
145  $ilObjDataCache = $DIC['ilObjDataCache'];
146  $ilSetting = $DIC['ilSetting'];
147 
148  include_once('Services/Form/classes/class.ilMultiSelectInputGUI.php');
149  $sub_mlist = new ilMultiSelectInputGUI(
150  $lng->txt('delete_inactivated_user_accounts_include_roles'),
151  'cron_inactivated_user_delete_include_roles'
152  );
153  $sub_mlist->setInfo($lng->txt('delete_inactivated_user_accounts_include_roles_desc'));
154  $roles = array();
155  foreach ($rbacreview->getGlobalRoles() as $role_id) {
156  if ($role_id != ANONYMOUS_ROLE_ID) {
157  $roles[$role_id] = $ilObjDataCache->lookupTitle($role_id);
158  }
159  }
160  $sub_mlist->setOptions($roles);
161  $setting = $ilSetting->get('cron_inactivated_user_delete_include_roles', null);
162  if ($setting === null) {
163  $setting = array();
164  } else {
165  $setting = explode(',', $setting);
166  }
167  $sub_mlist->setValue($setting);
168  $sub_mlist->setWidth(300);
169  #$sub_mlist->setHeight(100);
170  $a_form->addItem($sub_mlist);
171 
172  $default_setting = self::DEFAULT_INACTIVITY_PERIOD;
173  $sub_text = new ilNumberInputGUI(
174  $lng->txt('delete_inactivated_user_accounts_period'),
175  'cron_inactivated_user_delete_period'
176  );
177  $sub_text->allowDecimals(false);
178  $sub_text->setInfo($lng->txt('delete_inactivated_user_accounts_period_desc'));
179  $sub_text->setValue($ilSetting->get("cron_inactivated_user_delete_period", $default_setting));
180  $sub_text->setSize(4);
181  $sub_text->setMaxLength(4);
182  $sub_text->setRequired(true);
183  $a_form->addItem($sub_text);
184 
185  /*
186  $default_setting = ilCronDeleteInactiveUserAccounts::DEFAULT_SETTING_INCLUDE_ADMINS;
187  $sub_cb = new ilCheckboxInputGUI($lng->txt('delete_inactivated_user_accounts_include_admins'),'cron_inactivated_user_delete_include_admins');
188  $sub_cb->setChecked($ilSetting->get("cron_inactivated_user_delete_include_admins", $default_setting) ? 1 : 0 );
189  //$sub_cb->setOptionTitle($lng->txt('delete_inactivated_user_accounts_include_admins'));
190  $sub_cb->setInfo($lng->txt('delete_inactivated_user_accounts_include_admins_desc'));
191  $a_form->addItem($sub_cb);
192  */
193  }
194 
195  public function saveCustomSettings(ilPropertyFormGUI $a_form)
196  {
197  global $DIC;
198 
199  $ilSetting = $DIC['ilSetting'];
200 
201  $setting = implode(',', $_POST['cron_inactivated_user_delete_include_roles']);
202  if (!strlen($setting)) {
203  $setting = null;
204  }
205  $ilSetting->set('cron_inactivated_user_delete_include_roles', $setting);
206  $ilSetting->set('cron_inactivated_user_delete_period', $_POST['cron_inactivated_user_delete_period']);
207 
208  return true;
209  }
210 }
static _getUserIdsByInactivationPeriod($period)
get ids of all users that have been inactivated since at least the given period
$result
This class represents a property form user interface.
global $DIC
Definition: saml.php:7
Cron job application base class.
addItem($a_item)
Add Item (Property, SectionHeader).
allowDecimals($a_value)
Toggle Decimals.
setInfo($a_info)
Set Information Text.
This class represents a multi selection list property in a property form.
$lng
This class represents a number property in a property form.
$user
Definition: migrateto20.php:57
static getInstanceByObjId($a_obj_id, $stop_on_error=true)
get an instance of an Ilias object by object id
global $ilSetting
Definition: privfeed.php:17
Cron job result data container.
$_POST["username"]