ILIAS  Release_4_4_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilCronDeleteInactiveUserAccounts.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_inactive_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_inactive_user_delete_period',
36  self::DEFAULT_INACTIVITY_PERIOD
37  );
38  }
39  }
40 
41  public function getId()
42  {
43  return "user_inactive";
44  }
45 
46  public function getTitle()
47  {
48  global $lng;
49 
50  return $lng->txt("delete_inactive_user_accounts");
51  }
52 
53  public function getDescription()
54  {
55  global $lng;
56 
57  return $lng->txt("delete_inactive_user_accounts_desc");
58  }
59 
60  public function getDefaultScheduleType()
61  {
63  }
64 
65  public function getDefaultScheduleValue()
66  {
67  return;
68  }
69 
70  public function hasAutoActivation()
71  {
72  return false;
73  }
74 
75  public function hasFlexibleSchedule()
76  {
77  return true;
78  }
79 
80  public function hasCustomSettings()
81  {
82  return true;
83  }
84 
85  public function run()
86  {
87  global $rbacreview;
88 
90 
91  $usr_ids = ilObjUser::_getUserIdsByInactivityPeriod($this->period);
92 
93  $counter = 0;
94  foreach($usr_ids as $usr_id)
95  {
96  if($usr_id == ANONYMOUS_USER_ID || $usr_id == SYSTEM_USER_ID) continue;
97 
98  $continue = true;
99  foreach($this->include_roles as $role_id)
100  {
101  if( $rbacreview->isAssigned($usr_id, $role_id) )
102  {
103  $continue = false;
104  break;
105  }
106  }
107  if($continue) continue;
108 
109  $user = ilObjectFactory::getInstanceByObjId($usr_id);
110 
111  $user->delete();
112 
113  $counter++;
114  }
115 
116  if($counter)
117  {
118  $status = ilCronJobResult::STATUS_OK;
119  }
120  $result = new ilCronJobResult();
121  $result->setStatus($status);
122  return $result;
123  }
124 
126  {
127  global $lng, $rbacreview, $ilObjDataCache, $ilSetting;
128 
129  include_once('Services/Form/classes/class.ilMultiSelectInputGUI.php');
130  $sub_mlist = new ilMultiSelectInputGUI(
131  $lng->txt('delete_inactive_user_accounts_include_roles'),
132  'cron_inactive_user_delete_include_roles'
133  );
134  $sub_mlist->setInfo($lng->txt('delete_inactive_user_accounts_include_roles_desc'));
135  $roles = array();
136  foreach($rbacreview->getGlobalRoles() as $role_id)
137  {
138  if( $role_id != ANONYMOUS_ROLE_ID )
139  $roles[$role_id] = $ilObjDataCache->lookupTitle($role_id);
140  }
141  $sub_mlist->setOptions($roles);
142  $setting = $ilSetting->get('cron_inactive_user_delete_include_roles', null);
143  if($setting === null) $setting = array();
144  else $setting = explode(',', $setting);
145  $sub_mlist->setValue($setting);
146  $sub_mlist->setWidth(300);
147  #$sub_mlist->setHeight(100);
148  $a_form->addItem($sub_mlist);
149 
150  $default_setting = self::DEFAULT_INACTIVITY_PERIOD;
151  $sub_text = new ilNumberInputGUI(
152  $lng->txt('delete_inactive_user_accounts_period'),
153  'cron_inactive_user_delete_period'
154  );
155  $sub_text->setInfo($lng->txt('delete_inactive_user_accounts_period_desc'));
156  $sub_text->setValue($ilSetting->get("cron_inactive_user_delete_period", $default_setting));
157  $sub_text->setSize(4);
158  $sub_text->setMaxLength(4);
159  $sub_text->setRequired(true);
160  $a_form->addItem($sub_text);
161 
162  /*
163  $default_setting = ilCronDeleteInactiveUserAccounts::DEFAULT_SETTING_INCLUDE_ADMINS;
164  $sub_cb = new ilCheckboxInputGUI($lng->txt('delete_inactive_user_accounts_include_admins'),'cron_inactive_user_delete_include_admins');
165  $sub_cb->setChecked($ilSetting->get("cron_inactive_user_delete_include_admins", $default_setting) ? 1 : 0 );
166  //$sub_cb->setOptionTitle($lng->txt('delete_inactive_user_accounts_include_admins'));
167  $sub_cb->setInfo($lng->txt('delete_inactive_user_accounts_include_admins_desc'));
168  $a_form->addItem($sub_cb);
169  */
170  }
171 
172  public function saveCustomSettings(ilPropertyFormGUI $a_form)
173  {
174  global $ilSetting;
175 
176  $setting = implode(',', $_POST['cron_inactive_user_delete_include_roles']);
177  if( !strlen($setting) ) $setting = null;
178  $ilSetting->set('cron_inactive_user_delete_include_roles', $setting);
179  $ilSetting->set('cron_inactive_user_delete_period', $_POST['cron_inactive_user_delete_period']);
180 
181  return true;
182  }
183 }
184