ILIAS  release_4-3 Revision
 All Data Structures Namespaces Files Functions Variables Groups Pages
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 
13 {
14  const INTERVAL_DAILY = '1';
15  const INTERVAL_WEEKLY = '2';
16  const INTERVAL_MONTHLY = '3';
17  const INTERVAL_QUARTERLY = '4';
18 
20 
21  private $interval = null;
22 
23  private $include_roles = null;
24 
25  private $period = null;
26 
27  private $enabled = false;
28 
29  public function __construct()
30  {
31  global $ilSetting;
32 
33  $this->interval = $ilSetting->get(
34  'cron_inactivated_user_delete_interval',
35  self::getDefaultIntervalKey()
36  );
37 
38  $this->include_roles = $ilSetting->get(
39  'cron_inactivated_user_delete_include_roles', null
40  );
41  if($this->include_roles === null) $this->include_roles = array();
42  else $this->include_roles = explode(',', $this->include_roles);
43 
44  $this->period = $ilSetting->get(
45  'cron_inactivated_user_delete_period',
46  self::DEFAULT_INACTIVITY_PERIOD
47  );
48 
49  $last_run = (int)$ilSetting->get('cron_inactivated_user_delete_last_run', 0);
50 
51  if( $ilSetting->get('cron_inactivated_user_delete', false) )
52  {
53  if( !$last_run || (time() - $last_run) > $this->getCurrentIntervalPeriod() )
54  {
55  $this->enabled = true;
56 
57  $ilSetting->set('cron_inactivated_user_delete_last_run', time());
58  }
59  }
60  }
61 
62  public function run()
63  {
64  if( !$this->enabled ) return;
65 
66  global $rbacreview;
67 
68  $usr_ids = ilObjUser::_getUserIdsByInactivationPeriod($this->period);
69 
70  foreach($usr_ids as $usr_id)
71  {
72  if($usr_id == ANONYMOUS_USER_ID || $usr_id == SYSTEM_USER_ID) continue;
73 
74  $continue = true;
75  foreach($this->include_roles as $role_id)
76  {
77  if( $rbacreview->isAssigned($usr_id, $role_id) )
78  {
79  $continue = false;
80  break;
81  }
82  }
83  if($continue) continue;
84 
85  $user = ilObjectFactory::getInstanceByObjId($usr_id);
86 
87  $user->delete();
88  }
89  }
90 
91  private function getCurrentIntervalPeriod()
92  {
93  $period = 60 * 60;
94 
95  switch( $this->interval )
96  {
97  case self::INTERVAL_QUARTERLY: $period *= 3;
98  case self::INTERVAL_MONTHLY: $period *= 30;
99  case self::INTERVAL_WEEKLY: $period *= 7;
100  case self::INTERVAL_DAILY: $period *= 24;
101  }
102 
103  return $period;
104  }
105 
106  public static function getPossibleIntervalsArray()
107  {
108  global $lng;
109 
110  return array(
111  self::INTERVAL_DAILY => $lng->txt("daily"),
112  self::INTERVAL_WEEKLY => $lng->txt("weekly"),
113  self::INTERVAL_MONTHLY => $lng->txt("monthly"),
114  self::INTERVAL_QUARTERLY => $lng->txt("quarterly")
115  );
116  }
117 
118  public static function getDefaultIntervalKey()
119  {
120  return self::INTERVAL_DAILY;
121  }
122 }
123