/** * Moves an object from one container/OU to another in LDAP. * * @param LdapObject $ldapObject * @param string $container */ public function move(LdapObject $ldapObject, $container) { $event = new LdapObjectMoveEvent(Event::LDAP_OBJECT_BEFORE_MOVE, $ldapObject, $container); $this->dispatcher->dispatch($event); $container = $event->getContainer(); $this->validateObject($ldapObject); $operation = new RenameOperation($ldapObject->get('dn'), LdapUtilities::getRdnFromDn($ldapObject->get('dn')), $container, true); $this->connection->execute($operation); // Update the object to reference the new DN after the move... $newDn = LdapUtilities::getRdnFromDn($ldapObject->get('dn')) . ',' . $container; $ldapObject->refresh(['dn' => $newDn]); $ldapObject->getBatchCollection()->setDn($newDn); $this->dispatcher->dispatch(new LdapObjectMoveEvent(Event::LDAP_OBJECT_AFTER_MOVE, $ldapObject, $container)); }
/** * {@inheritdoc} */ public function toOperation() { // If this is a move operation to a new OU and we have a DN already, then we can figure out the RDN. if (is_null($this->newRdn) && !is_null($this->newSuperior)) { $rdn = LdapUtilities::getRdnFromDn($this->dn); } else { $rdn = $this->newRdn; } return new RenameOperation($this->dn, $rdn, $this->newSuperior, $this->deleteOldRdn); }