public function ldapSync($row) { $ldap_query = $this->ldap->getLDAPParam('eduid') . '=' . $row['ldap_id']; $userSync = $this->getLdapUserSync(); $attributes = $userSync->getSyncAttributes($this->ldap); $time_start = microtime(true); $lri = false; foreach (split(';', $this->ldap->getLDAPParam('people_dn')) as $PeopleDn) { $lri = $this->ldap->search($PeopleDn, $ldap_query, LDAP::SCOPE_ONELEVEL, $attributes); if (count($lri) == 1 && $lri != false) { break; } } $time_end = microtime(true); $this->ldapTime += $time_end - $time_start; if ($this->ldap->getErrno() === LDAP::ERR_SUCCESS && $lri) { $user = new User($row); $modified = false; if (count($lri) == 1) { $lr = $lri->current(); $modified = $userSync->sync($user, $lr); if ($row['ldap_uid'] != $lr->getLogin()) { $this->getLdapUserManager()->updateLdapUid($user, $lr->getLogin()); } } elseif (count($lri) == 0) { // User not found in LDAP directory $modified = true; $user->setStatus('S'); $user->setUnixStatus('D'); } if ($modified) { $this->getUserManager()->updateDb($user); } } }
public function ldapSync($row, $users_are_suspendable = true) { $ldap_query = $this->ldap->getLDAPParam('eduid') . '=' . $row['ldap_id']; $userSync = $this->getLdapUserSync(); $attributes = $userSync->getSyncAttributes($this->ldap); $time_start = microtime(true); $lri = false; $search_depth = LDAP::SCOPE_SUBTREE; if ($this->ldap->getLDAPParam('search_depth') === LDAP::SCOPE_ONELEVEL_TEXT) { $search_depth = LDAP::SCOPE_ONELEVEL; } foreach (split(';', $this->ldap->getLDAPParam('people_dn')) as $PeopleDn) { $lri = $this->ldap->search($PeopleDn, $ldap_query, $search_depth, $attributes); if (count($lri) == 1 && $lri != false) { break; } } $time_end = microtime(true); $this->ldapTime += $time_end - $time_start; if ($this->ldap->getErrno() === LDAP::ERR_SUCCESS && $lri) { $user = new PFUser($row); $modified = false; if (count($lri) == 1) { $lr = $lri->current(); $modified = $userSync->sync($user, $lr); if ($row['ldap_uid'] != $lr->getLogin()) { $this->getLdapUserManager()->updateLdapUid($user, $lr->getLogin()); } } elseif (count($lri) == 0 && $users_are_suspendable) { $this->logger->warn('LDAP user to be suspended: ' . $user->getId() . ' ' . $user->getUserName()); $this->logger->debug(' *** PEOPLEDN: ' . $PeopleDn . ' *** LDAP QUERY: ' . $ldap_query . ' *** ATTRIBUTES: ' . print_r($attributes, true)); // User not found in LDAP directory $modified = true; $user->setStatus('S'); $user->setUnixStatus('D'); } if ($modified) { $em = $this->getEventManager(); $em->processEvent(LDAP_DAILY_SYNCHRO_UPDATE_USER, $user); if ($user->getStatus() == 'S' && $users_are_suspendable) { $this->getUserManager()->updateDb($user); if ($retentionPeriod = $this->ldap->getLDAPParam('daily_sync_retention_period')) { $projectManager = $this->getProjectManager(); $this->getLdapSyncNotificationManager($projectManager, $retentionPeriod)->processNotification($user); $this->getCleanUpManager()->addUserDeletionForecastDate($user); } } else { if ($user->getStatus() != 'S') { $this->getUserManager()->updateDb($user); } } } } $this->remindAdminsBeforeCleanUp(); }