LdapTools\Object\LdapObjectManager::restore PHP Method

restore() public method

This may require a strategy design at some point, as this is AD specific currently. Unsure as to how other directory services handle deleted object restores. The basic logic for AD to do this is... 1. Reset the 'isDeleted' attribute. 2. Set the DN so the object ends up in a location other than the "Deleted Objects" container.
public restore ( LdapObject $ldapObject, null | string $location = null )
$ldapObject LdapObject
$location null | string The DN of a container/OU where the restored object should go.
    public function restore(LdapObject $ldapObject, $location = null)
    {
        $event = new LdapObjectRestoreEvent(Event::LDAP_OBJECT_BEFORE_RESTORE, $ldapObject, $location);
        $this->dispatcher->dispatch($event);
        $location = $event->getContainer();
        $this->validateObject($ldapObject);
        $originalDn = $ldapObject->get('dn');
        $ldapObject->reset('isDeleted');
        // Some additional logic may be needed to get the actual restore location...
        $newLocation = $this->getObjectRestoreLocation($ldapObject, $location);
        // The DN contains the full RDN (including the preceding attribute name). The original RDN is before the \0A.
        $rdn = explode('\\0A', $ldapObject->get('dn'), 2)[0];
        $ldapObject->set('dn', "{$rdn},{$newLocation}");
        $this->executeBatchOperation($ldapObject, $originalDn);
        $this->dispatcher->dispatch(new LdapObjectRestoreEvent(Event::LDAP_OBJECT_AFTER_RESTORE, $ldapObject, $location));
    }