ILIAS  Release_3_10_x_branch Revision 61812
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilLDAPCronSynchronization.php
Go to the documentation of this file.
1 <?php
2 /*
3  +-----------------------------------------------------------------------------+
4  | ILIAS open source |
5  +-----------------------------------------------------------------------------+
6  | Copyright (c) 1998-2006 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 
32 include_once('Services/LDAP/classes/class.ilLDAPServer.php');
33 include_once('Services/LDAP/classes/class.ilLDAPQuery.php');
34 include_once('Services/LDAP/classes/class.ilLDAPAttributeToUser.php');
35 
36 
38 {
39  private $current_server = null;
40  private $ldap_query = null;
41  private $log = null;
42 
43  public function __construct()
44  {
45  global $ilLog;
46 
47  $this->log = $ilLog;
48  }
49 
57  public function start()
58  {
59  foreach(ilLDAPServer::_getCronServerIds() as $server_id)
60  {
61  try
62  {
63  $this->current_server = new ilLDAPServer($server_id);
64  $this->current_server->doConnectionCheck();
65  $this->log->write("LDAP: starting user synchronization for ".$this->current_server->getName());
66 
67  $this->ldap_query = new ilLDAPQuery($this->current_server);
68  $this->ldap_query->bind(IL_LDAP_BIND_DEFAULT);
69 
70  if(is_array($users = $this->ldap_query->fetchUsers()))
71  {
72  // Deactivate ldap users that are not in the list
73  $this->deactivateUsers($users);
74  }
75 
76  if(count($users))
77  {
78  $this->log->write("LDAP: Starting update/creation of users ...");
79  $this->ldap_to_ilias = new ilLDAPAttributeToUser($this->current_server);
80  $this->ldap_to_ilias->setUserData($users);
81  $this->ldap_to_ilias->refresh();
82  $this->log->write("LDAP: Finished update/creation");
83  }
84  else
85  {
86  $this->log->write("LDAP: No users for update/create. Aborting.");
87  }
88  }
89  catch(ilLDAPQueryException $exc)
90  {
91  $this->log->write($exc->getMessage());
92  }
93  }
94  }
95 
102  private function deactivateUsers($a_ldap_users)
103  {
104  include_once './Services/User/classes/class.ilObjUser.php';
105 
106  foreach($ext = ilObjUser::_getExternalAccountsByAuthMode('ldap',true) as $usr_id => $external_account)
107  {
108  if(!array_key_exists($external_account,$a_ldap_users))
109  {
110  $inactive[] = $usr_id;
111  }
112  }
113  if(count($inactive))
114  {
115  ilObjUser::_toggleActiveStatusOfUsers($inactive,false);
116  $this->log->write('LDAP: Found '.count($inactive).' inactive users.');
117  }
118  else
119  {
120  $this->log->write('LDAP: No inactive users found');
121  }
122  }
123 }
124 
125 
126 ?>