ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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 $ilSetting;
25 
26  if(is_object($ilSetting))
27  {
28  $this->include_roles = $ilSetting->get(
29  'cron_inactivated_user_delete_include_roles', null
30  );
31  if($this->include_roles === null) $this->include_roles = array();
32  else $this->include_roles = explode(',', $this->include_roles);
33 
34  $this->period = $ilSetting->get(
35  'cron_inactivated_user_delete_period',
36  self::DEFAULT_INACTIVITY_PERIOD
37  );
38  }
39  }
40 
41  public function getId()
42  {
43  return "user_inactivated";
44  }
45 
46  public function getTitle()
47  {
48  global $lng;
49 
50  return $lng->txt("delete_inactivated_user_accounts");
51  }
52 
53  public function getDescription()
54  {
55  global $lng;
56 
57  return sprintf(
58  $lng->txt("delete_inactivated_user_accounts_desc"),
60  );
61  }
62 
63  public function getDefaultScheduleType()
64  {
65  return self::SCHEDULE_TYPE_DAILY;
66  }
67 
68  public function getDefaultScheduleValue()
69  {
70  return;
71  }
72 
73  public function hasAutoActivation()
74  {
75  return false;
76  }
77 
78  public function hasFlexibleSchedule()
79  {
80  return true;
81  }
82 
83  public function hasCustomSettings()
84  {
85  return true;
86  }
87 
88  public function run()
89  {
90  global $rbacreview;
91 
93 
94  $usr_ids = ilObjUser::_getUserIdsByInactivationPeriod($this->period);
95 
96  $counter = 0;
97  foreach($usr_ids as $usr_id)
98  {
99  if($usr_id == ANONYMOUS_USER_ID || $usr_id == SYSTEM_USER_ID) continue;
100 
101  $continue = true;
102  foreach($this->include_roles as $role_id)
103  {
104  if( $rbacreview->isAssigned($usr_id, $role_id) )
105  {
106  $continue = false;
107  break;
108  }
109  }
110  if($continue) continue;
111 
112  $user = ilObjectFactory::getInstanceByObjId($usr_id);
113 
114  $user->delete();
115 
116  $counter++;
117  }
118 
119  if($counter)
120  {
121  $status = ilCronJobResult::STATUS_OK;
122  }
123  $result = new ilCronJobResult();
124  $result->setStatus($status);
125  return $result;
126  }
127 
129  {
130  global $lng, $rbacreview, $ilObjDataCache, $ilSetting;
131 
132  include_once('Services/Form/classes/class.ilMultiSelectInputGUI.php');
133  $sub_mlist = new ilMultiSelectInputGUI(
134  $lng->txt('delete_inactivated_user_accounts_include_roles'),
135  'cron_inactivated_user_delete_include_roles'
136  );
137  $sub_mlist->setInfo($lng->txt('delete_inactivated_user_accounts_include_roles_desc'));
138  $roles = array();
139  foreach($rbacreview->getGlobalRoles() as $role_id)
140  {
141  if( $role_id != ANONYMOUS_ROLE_ID )
142  $roles[$role_id] = $ilObjDataCache->lookupTitle($role_id);
143  }
144  $sub_mlist->setOptions($roles);
145  $setting = $ilSetting->get('cron_inactivated_user_delete_include_roles', null);
146  if($setting === null) $setting = array();
147  else $setting = explode(',', $setting);
148  $sub_mlist->setValue($setting);
149  $sub_mlist->setWidth(300);
150  #$sub_mlist->setHeight(100);
151  $a_form->addItem($sub_mlist);
152 
153  $default_setting = self::DEFAULT_INACTIVITY_PERIOD;
154  $sub_text = new ilNumberInputGUI(
155  $lng->txt('delete_inactivated_user_accounts_period'),
156  'cron_inactivated_user_delete_period'
157  );
158  $sub_text->allowDecimals(false);
159  $sub_text->setInfo($lng->txt('delete_inactivated_user_accounts_period_desc'));
160  $sub_text->setValue($ilSetting->get("cron_inactivated_user_delete_period", $default_setting));
161  $sub_text->setSize(4);
162  $sub_text->setMaxLength(4);
163  $sub_text->setRequired(true);
164  $a_form->addItem($sub_text);
165 
166  /*
167  $default_setting = ilCronDeleteInactiveUserAccounts::DEFAULT_SETTING_INCLUDE_ADMINS;
168  $sub_cb = new ilCheckboxInputGUI($lng->txt('delete_inactivated_user_accounts_include_admins'),'cron_inactivated_user_delete_include_admins');
169  $sub_cb->setChecked($ilSetting->get("cron_inactivated_user_delete_include_admins", $default_setting) ? 1 : 0 );
170  //$sub_cb->setOptionTitle($lng->txt('delete_inactivated_user_accounts_include_admins'));
171  $sub_cb->setInfo($lng->txt('delete_inactivated_user_accounts_include_admins_desc'));
172  $a_form->addItem($sub_cb);
173  */
174  }
175 
176  public function saveCustomSettings(ilPropertyFormGUI $a_form)
177  {
178  global $ilSetting;
179 
180  $setting = implode(',', $_POST['cron_inactivated_user_delete_include_roles']);
181  if( !strlen($setting) ) $setting = null;
182  $ilSetting->set('cron_inactivated_user_delete_include_roles', $setting);
183  $ilSetting->set('cron_inactivated_user_delete_period', $_POST['cron_inactivated_user_delete_period']);
184 
185  return true;
186  }
187 }
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.
Cron job application base class.
addItem($a_item)
Add Item (Property, SectionHeader).
allowDecimals($a_value)
Toggle Decimals.
setInfo($a_info)
Set Information Text.
$counter
This class represents a multi selection list property in a property form.
This class represents a number property in a property form.
static getInstanceByObjId($a_obj_id, $stop_on_error=true)
get an instance of an Ilias object by object id
Create styles array
The data for the language used.
global $ilSetting
Definition: privfeed.php:17
global $lng
Definition: privfeed.php:17
Cron job result data container.
$_POST["username"]