/** * Add a new entryobject to a directory. * * Use add to add a new Net_LDAP2_Entry object to the directory. * This also links the entry to the connection used for the add, * if it was a fresh entry ({@link Net_LDAP2_Entry::createFresh()}) * * @param Net_LDAP2_Entry $entry Net_LDAP2_Entry * * @return Net_LDAP2_Error|true Net_LDAP2_Error object or true */ public function add($entry) { if (!$entry instanceof Net_LDAP2_Entry) { return PEAR::raiseError('Parameter to Net_LDAP2::add() must be a Net_LDAP2_Entry object.'); } // Continue attempting the add operation in a loop until we // get a success, a definitive failure, or the world ends. $foo = 0; while (true) { $link = $this->getLink(); if ($link === false) { // We do not have a successful connection yet. The call to // getLink() would have kept trying if we wanted one. Go // home now. return PEAR::raiseError("Could not add entry " . $entry->dn() . " no valid LDAP connection could be found."); } if (@ldap_add($link, $entry->dn(), $entry->getValues())) { // entry successfully added, we should update its $ldap reference // in case it is not set so far (fresh entry) if (!$entry->getLDAP() instanceof Net_LDAP2) { $entry->setLDAP($this); } // store, that the entry is present inside the directory $entry->markAsNew(false); return true; } else { // We have a failure. What type? We may be able to reconnect // and try again. $error_code = @ldap_errno($link); $error_name = Net_LDAP2::errorMessage($error_code); if ($error_name === 'LDAP_OPERATIONS_ERROR' && $this->_config['auto_reconnect']) { // The server has become disconnected before trying the // operation. We should try again, possibly with a different // server. $this->_link = false; $this->performReconnect(); } else { // Errors other than the above catched are just passed // back to the user so he may react upon them. return PEAR::raiseError("Could not add entry " . $entry->dn() . " " . $error_name, $error_code); } } } }