LdapTools\Object\LdapObjectManager::getObjectRestoreLocation PHP Method

getObjectRestoreLocation() protected method

It's possible a new location was not explicitly given and the attribute that contains the last know location was not queried for when the object was originally found. In that case attempt to retrieve the last known location from a separate LDAP query.
protected getObjectRestoreLocation ( LdapObject $ldapObject, string | null $location ) : string
$ldapObject LdapObject
$location string | null
return string
    protected function getObjectRestoreLocation(LdapObject $ldapObject, $location)
    {
        // If a location was defined, use that.
        if ($location) {
            $newLocation = $location;
            // Check the attribute for the last known location first...
        } elseif ($ldapObject->has('lastKnownLocation')) {
            $newLocation = $ldapObject->get('lastKnownLocation');
            // All else failed, so query it from the DN...
        } else {
            try {
                $newLocation = (new LdapQueryBuilder($this->connection, $this->schemaFactory))->select('lastKnownParent')->from(LdapObjectType::DELETED)->where(['dn' => $ldapObject->get('dn')])->getLdapQuery()->getSingleScalarOrNullResult();
            } catch (Exception $e) {
                $newLocation = null;
            }
        }
        // Either this was not a deleted object or it no longer exists?
        if (is_null($newLocation)) {
            throw new InvalidArgumentException(sprintf('No restore location specified and cannot find the last known location for "%s".', $ldapObject->get('dn')));
        }
        return $newLocation;
    }