• Main Page
  • Related Pages
  • Modules
  • Namespaces
  • Data Structures
  • Files
  • File List
  • Globals

Services/LDAP/classes/class.ilLDAPCronSynchronization.php

Go to the documentation of this file.
00001 <?php
00002 /*
00003         +-----------------------------------------------------------------------------+
00004         | ILIAS open source                                                           |
00005         +-----------------------------------------------------------------------------+
00006         | Copyright (c) 1998-2006 ILIAS open source, University of Cologne            |
00007         |                                                                             |
00008         | This program is free software; you can redistribute it and/or               |
00009         | modify it under the terms of the GNU General Public License                 |
00010         | as published by the Free Software Foundation; either version 2              |
00011         | of the License, or (at your option) any later version.                      |
00012         |                                                                             |
00013         | This program is distributed in the hope that it will be useful,             |
00014         | but WITHOUT ANY WARRANTY; without even the implied warranty of              |
00015         | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               |
00016         | GNU General Public License for more details.                                |
00017         |                                                                             |
00018         | You should have received a copy of the GNU General Public License           |
00019         | along with this program; if not, write to the Free Software                 |
00020         | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA. |
00021         +-----------------------------------------------------------------------------+
00022 */
00023 
00032 include_once('Services/LDAP/classes/class.ilLDAPServer.php');
00033 include_once('Services/LDAP/classes/class.ilLDAPQuery.php');
00034 include_once('Services/LDAP/classes/class.ilLDAPAttributeToUser.php');
00035 
00036 
00037 class ilLDAPCronSynchronization
00038 {
00039         private $current_server = null;
00040         private $ldap_query = null;
00041         private $log = null;
00042         
00043         public function __construct()
00044         {
00045                 global $ilLog;
00046                 
00047                 $this->log = $ilLog;
00048         }
00049         
00057         public function start()
00058         {
00059                 foreach(ilLDAPServer::_getCronServerIds() as $server_id)
00060                 {
00061                         try
00062                         {
00063                                 $this->current_server = new ilLDAPServer($server_id);
00064                                 $this->current_server->doConnectionCheck();
00065                                 $this->log->write("LDAP: starting user synchronization for ".$this->current_server->getName());
00066                                 
00067                                 $this->ldap_query = new ilLDAPQuery($this->current_server);
00068                                 $this->ldap_query->bind(IL_LDAP_BIND_DEFAULT);
00069                                 
00070                                 if(is_array($users = $this->ldap_query->fetchUsers()))
00071                                 {
00072                                         // Deactivate ldap users that are not in the list
00073                                         $this->deactivateUsers($users);
00074                                 }
00075                         
00076                                 if(count($users))
00077                                 {       
00078                                         $this->log->write("LDAP: Starting update/creation of users ...");
00079                                         $this->ldap_to_ilias = new ilLDAPAttributeToUser($this->current_server);
00080                                         $this->ldap_to_ilias->setUserData($users);
00081                                         $this->ldap_to_ilias->refresh();
00082                                         $this->log->write("LDAP: Finished update/creation");
00083                                 }
00084                                 else
00085                                 {
00086                                         $this->log->write("LDAP: No users for update/create. Aborting.");
00087                                 }
00088                         }
00089                         catch(ilLDAPQueryException $exc)
00090                         {
00091                                 $this->log->write($exc->getMessage());
00092                         }
00093                 }
00094         }
00095         
00102         private function deactivateUsers($a_ldap_users)
00103         {
00104                 include_once './Services/User/classes/class.ilObjUser.php';
00105                 
00106                 foreach($ext = ilObjUser::_getExternalAccountsByAuthMode('ldap',true) as $usr_id => $external_account)
00107                 {
00108                         if(!array_key_exists($external_account,$a_ldap_users))
00109                         {
00110                                 $inactive[] = $usr_id;
00111                         }
00112                 }
00113                 if(count($inactive))
00114                 {
00115                         ilObjUser::_toggleActiveStatusOfUsers($inactive,false);
00116                         $this->log->write('LDAP: Found '.count($inactive).' inactive users.');
00117                 }
00118                 else
00119                 {
00120                         $this->log->write('LDAP: No inactive users found');
00121                 }
00122         }
00123 }
00124 
00125 
00126 ?>

Generated on Fri Dec 13 2013 17:56:57 for ILIAS Release_3_9_x_branch .rev 46835 by  doxygen 1.7.1