ILIAS  release_4-3 Revision
 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($this->current_server,$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->setNewUserAuthMode($this->current_server->getAuthenticationMappingKey());
81  #$GLOBALS['ilLog']->write(print_r($users,true));
82  $this->ldap_to_ilias->setUserData($users);
83  $this->ldap_to_ilias->refresh();
84  $this->log->write("LDAP: Finished update/creation");
85  }
86  else
87  {
88  $this->log->write("LDAP: No users for update/create. Aborting.");
89  }
90  }
91  catch(ilLDAPQueryException $exc)
92  {
93  $this->log->write($exc->getMessage());
94  }
95  }
96  }
97 
104  private function deactivateUsers(ilLDAPServer $server,$a_ldap_users)
105  {
106  include_once './Services/User/classes/class.ilObjUser.php';
107 
108  foreach($ext = ilObjUser::_getExternalAccountsByAuthMode($server->getAuthenticationMappingKey(),true) as $usr_id => $external_account)
109  {
110  if(!array_key_exists($external_account,$a_ldap_users))
111  {
112  $inactive[] = $usr_id;
113  }
114  }
115  if(count($inactive))
116  {
117  ilObjUser::_toggleActiveStatusOfUsers($inactive,false);
118  $this->log->write('LDAP: Found '.count($inactive).' inactive users.');
119  }
120  else
121  {
122  $this->log->write('LDAP: No inactive users found');
123  }
124  }
125 }
126 
127 
128 ?>