Go to the documentation of this file.00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
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
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 ?>