ILIAS  Release_4_1_x_branch Revision 61804
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilCronDeleteInactiveUserAccounts.php
Go to the documentation of this file.
1 <?php
2 /*
3  +-----------------------------------------------------------------------------+
4  | ILIAS open source |
5  +-----------------------------------------------------------------------------+
6  | Copyright (c) 1998-2001 ILIAS open source, University of Cologne |
7  | |
8  | This program is free software; you can redistribute it and/or |
9  | modify it under the terms of the GNU General Public License |
10  | as published by the Free Software Foundation; either version 2 |
11  | of the License, or (at your option) any later version. |
12  | |
13  | This program is distributed in the hope that it will be useful, |
14  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16  | GNU General Public License for more details. |
17  | |
18  | You should have received a copy of the GNU General Public License |
19  | along with this program; if not, write to the Free Software |
20  | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21  +-----------------------------------------------------------------------------+
22 */
23 
24 
35  {
36  const INTERVAL_DAILY = '1';
37  const INTERVAL_WEEKLY = '2';
38  const INTERVAL_MONTHLY = '3';
39  const INTERVAL_QUARTERLY = '4';
40 
42 
43  private $interval = null;
44 
45  private $include_roles = null;
46 
47  private $inactivity_period = null;
48 
49  private $enabled = false;
50 
51  public function __construct()
52  {
53  global $ilSetting;
54 
55  $this->interval = $ilSetting->get(
56  'cron_inactive_user_delete_interval',
57  self::getDefaultIntervalKey()
58  );
59 
60  $this->include_roles = $ilSetting->get(
61  'cron_inactive_user_delete_include_roles', null
62  );
63  if($this->include_roles === null) $this->include_roles = array();
64  else $this->include_roles = explode(',', $this->include_roles);
65 
66  $this->inactivity_period = $ilSetting->get(
67  'cron_inactive_user_delete_period',
68  self::DEFAULT_INACTIVITY_PERIOD
69  );
70 
71  $last_run = (int)$ilSetting->get('cron_inactive_user_delete_last_run', 0);
72 
73  if( !$last_run || (time() - $last_run) > $this->getCurrentIntervalPeriod() )
74  {
75  $this->enabled = true;
76 
77  $ilSetting->set('cron_inactive_user_delete_last_run', time());
78  }
79  }
80 
81  public function run()
82  {
83  if( !$this->enabled ) return;
84 
85  global $rbacreview;
86 
87  $usr_ids = ilObjUser::_getUserIdsByInactivityPeriod($this->inactivity_period);
88 
89  foreach($usr_ids as $usr_id)
90  {
91  if($usr_id == ANONYMOUS_USER_ID || $usr_id == SYSTEM_USER_ID) continue;
92 
93  $continue = true;
94  foreach($this->include_roles as $role_id)
95  {
96  if( $rbacreview->isAssigned($usr_id, $role_id) )
97  {
98  $continue = false;
99  break;
100  }
101  }
102  if($continue) continue;
103 
105 
106  $user->delete();
107  }
108  }
109 
110  private function getCurrentIntervalPeriod()
111  {
112  $period = 60 * 60;
113 
114  switch( $this->interval )
115  {
116  case self::INTERVAL_QUARTERLY: $period *= 3;
117  case self::INTERVAL_MONTHLY: $period *= 30;
118  case self::INTERVAL_WEEKLY: $period *= 7;
119  case self::INTERVAL_DAILY: $period *= 24;
120  }
121 
122  return $period;
123  }
124 
125  public static function getPossibleIntervalsArray()
126  {
127  global $lng;
128 
129  return array(
130  self::INTERVAL_DAILY => $lng->txt("daily"),
131  self::INTERVAL_WEEKLY => $lng->txt("weekly"),
132  self::INTERVAL_MONTHLY => $lng->txt("monthly"),
133  self::INTERVAL_QUARTERLY => $lng->txt("quarterly")
134  );
135  }
136 
137  public static function getDefaultIntervalKey()
138  {
139  return self::INTERVAL_DAILY;
140  }
141  }
142 
143 
144 
145 ?>