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;
}