/** * Check for LDAP servers and synchronize them * * @access public * @param * */ public function start() { foreach (ilLDAPServer::_getCronServerIds() as $server_id) { try { $this->current_server = new ilLDAPServer($server_id); $this->current_server->doConnectionCheck(); $this->log->write("LDAP: starting user synchronization for " . $this->current_server->getName()); $this->ldap_query = new ilLDAPQuery($this->current_server); $this->ldap_query->bind(IL_LDAP_BIND_DEFAULT); if (is_array($users = $this->ldap_query->fetchUsers())) { // Deactivate ldap users that are not in the list $this->deactivateUsers($this->current_server, $users); } if (count($users)) { $this->log->write("LDAP: Starting update/creation of users ..."); $this->ldap_to_ilias = new ilLDAPAttributeToUser($this->current_server); $this->ldap_to_ilias->setNewUserAuthMode($this->current_server->getAuthenticationMappingKey()); #$GLOBALS['ilLog']->write(print_r($users,true)); $this->ldap_to_ilias->setUserData($users); $this->ldap_to_ilias->refresh(); $this->log->write("LDAP: Finished update/creation"); } else { $this->log->write("LDAP: No users for update/create. Aborting."); } } catch (ilLDAPQueryException $exc) { $this->log->write($exc->getMessage()); } } }
public function run() { global $ilLog; $status = ilCronJobResult::STATUS_NO_ACTION; $messages = array(); foreach (ilLDAPServer::_getCronServerIds() as $server_id) { try { $this->current_server = new ilLDAPServer($server_id); $this->current_server->doConnectionCheck(); $ilLog->write("LDAP: starting user synchronization for " . $this->current_server->getName()); $this->ldap_query = new ilLDAPQuery($this->current_server); $this->ldap_query->bind(IL_LDAP_BIND_DEFAULT); if (is_array($users = $this->ldap_query->fetchUsers())) { // Deactivate ldap users that are not in the list $this->deactivateUsers($this->current_server, $users); } if (count($users)) { $ilLog->write("LDAP: Starting update/creation of users ..."); include_once './Services/User/classes/class.ilUserCreationContext.php'; ilUserCreationContext::getInstance()->addContext(ilUserCreationContext::CONTEXT_LDAP); $this->ldap_to_ilias = new ilLDAPAttributeToUser($this->current_server); $this->ldap_to_ilias->setNewUserAuthMode($this->current_server->getAuthenticationMappingKey()); #$ilLog->write(print_r($users,true)); $this->ldap_to_ilias->setUserData($users); $this->ldap_to_ilias->refresh(); $ilLog->write("LDAP: Finished update/creation"); $this->counter++; } else { $ilLog->write("LDAP: No users for update/create. Aborting."); } } catch (ilLDAPQueryException $exc) { $mess = $exc->getMessage(); $ilLog->write($mess); $messages[] = $mess; } } if ($this->counter) { $status = ilCronJobResult::STATUS_OK; } $result = new ilCronJobResult(); if (sizeof($messages)) { $result->setMessage(implode("\n", $messages)); } $result->setStatus($status); return $result; }