/** * Write an entry * * @param peer.ldap.LDAPEntry entry * @throws lang.IllegalArgumentException in case the parameter is not an LDAPEntry object */ public function write(LDAPEntry $entry) { $this->stream->write(sprintf("dn: %s\n", $entry->getDN())); foreach (array_keys($entry->attributes) as $key) { if ('dn' == $key) { continue; } for ($i = 0, $s = sizeof($entry->attributes[$key]); $i < $s; $i++) { $this->stream->write(sprintf("%s: %s\n", $key, $entry->attributes[$key][$i])); } } $this->stream->write("\n"); }
/** * Gets next entry * * @return peer.ldap.LDAPEntry or NULL if nothing was found * @throws peer.ldap.LDAPException in case of a read error */ public function next() { // If we have reached the number of results reported by ldap_count_entries() // - see constructor, return FALSE without trying to read further. Trying // to read "past the end" results in LDAP error #84 (decoding error) in some // client/server constellations, which is then incorrectly reported as an error. if ($this->iteration[1] >= $this->size) { return null; } // Fetch the next entry. Return FALSE if it was the last one (where really, // we shouldn't be getting here) $entry = ldap_next_entry($this->conn, $this->iteration[0]); if (!$entry) { if ($e = ldap_errno($this->conn)) { throw new LDAPException('Could not fetch next result entry.', $e); } return null; // EOF } // Keep track how many etnries we have fetched so we stop once we // have reached this number - see above for explanation. $this->iteration = [$entry, ++$this->iteration[1]]; return LDAPEntry::create(ldap_get_dn($this->conn, $entry), ldap_get_attributes($this->conn, $entry)); }
include '../../../configuration.inc'; include './migrationConfig.inc'; $pdo = new PDO(MIGRATION_DSN, MIGRATION_USER, MIGRATION_PASS); $result = $pdo->query('select username,authenticationMethod,firstname,lastname from users u,people p where p.id=u.person_id'); foreach ($result->fetchAll(PDO::FETCH_ASSOC) as $row) { try { $person = new Person($row['username']); } catch (Exception $e) { // print_r($e); $person = new Person(); $person->setUsername($row['username']); $person->setAuthenticationMethod($row['authenticationMethod']); $person->addRole('Staff'); if ($row['authenticationMethod'] == 'LDAP') { try { $ldap = new LDAPEntry($person->getUsername()); $person->setFirstname($ldap->getFirstname()); $person->setLastname($ldap->getLastname()); $person->setEmail($ldap->getEmail()); // $person->setDepartment($ldap->getDepartment()); } catch (Exception $e) { // print_r($e); $person->setEmail($row['username'] . '@bloomington.in.gov'); } } else { $person->setFirstname($row['firstname']); $person->setLastname($row['lastname']); } try { $person->save(); } catch (Exception $e) {
/** * Add an attribute to an entry * * @param peer.ldap.LDAPEntry entry * @param string name * @param var value * @return bool */ public function replaceAttribute(LDAPEntry $entry, $name, $value) { if (FALSE == ($res = ldap_mod_replace($this->_hdl, $entry->getDN(), array($name => $value)))) { throw new LDAPException('Add attribute for "' . $entry->getDN() . '" failed', ldap_errno($this->_hdl)); } return $res; }
/** * Gets next entry - ideal for loops such as: * <code> * while ($entry= $l->getNextEntry()) { * // doit * } * </code> * * @return peer.ldap.LDAPEntry or FALSE if none exists by this offset * @throws peer.ldap.LDAPException in case of a read error */ public function getNextEntry() { // Check if we were called without getFirstEntry() being called first // Tolerate this situation by simply returning whatever getFirstEntry() // returns. if (NULL === $this->entry) { return $this->getFirstEntry(); } // If we have reached the number of results reported by ldap_count_entries() // - see constructor, return FALSE without trying to read further. Trying // to read "past the end" results in LDAP error #84 (decoding error) in some // client/server constellations, which is then incorrectly reported as an error. if ($this->entry[1] >= $this->size) { return FALSE; } // Fetch the next entry. Return FALSE if it was the last one (where really, // we shouldn't be getting here) $this->entry[0] = ldap_next_entry($this->_hdl, $this->entry[0]); if (FALSE === $this->entry[0]) { if (!($e = ldap_errno($this->_hdl))) { return FALSE; } throw new LDAPException('Could not fetch next result entry.', $e); } // Keep track how many etnries we have fetched so we stop once we // have reached this number - see above for explanation. $this->entry[1]++; return LDAPEntry::fromResource($this->_hdl, $this->entry[0]); }