/** * Sends all pending changes to the LDAP server * * @param \Zend\LDAP\LDAP $ldap * @return \Zend\LDAP\Node\Node Provides a fluid interface * @throws \Zend\LDAP\Exception */ public function update(LDAP\LDAP $ldap = null) { if ($ldap !== null) { $this->attachLDAP($ldap); } $ldap = $this->getLDAP(); if (!$ldap instanceof LDAP\LDAP) { throw new LDAP\Exception(null, 'No LDAP connection available'); } if ($this->willBeDeleted()) { if ($ldap->exists($this->_dn)) { $ldap->delete($this->_dn); } return $this; } if ($this->isNew()) { $data = $this->getData(); $ldap->add($this->_getDn(), $data); $this->_loadData($data, true); return $this; } $changedData = $this->getChangedData(); if ($this->willBeMoved()) { $recursive = $this->hasChildren(); $ldap->rename($this->_dn, $this->_newDn, $recursive, false); foreach ($this->_newDn->getRdn() as $key => $value) { if (array_key_exists($key, $changedData)) { unset($changedData[$key]); } } $this->_dn = $this->_newDn; $this->_newDn = null; } if (count($changedData) > 0) { $ldap->update($this->_getDn(), $changedData); } $this->_originalData = $this->_currentData; return $this; }