public function ensureUserDoesntExist($username, $parentGroupName = null)
{
$user = null;
if ($parentGroupName) {
// find matching Parent Group name
$parentSearchHits = $this->searchUserGroups($parentGroupName, self::USERGROUP_ROOT_LOCATION);
if (!empty($parentSearchHits)) {
foreach ($parentSearchHits as $parentGroupFound) {
$groupId = $parentGroupFound->valueObject->contentInfo->id;
//Search for already existing matching Child user
$user = $this->searchUserByLogin($username, $groupId);
if ($user) {
break;
}
}
}
} else {
try {
$user = $this->userService->loadUserByLogin($username);
} catch (ApiExceptions\NotFoundException $e) {
// nothing to do
}
}
if ($user) {
try {
$this->userService->deleteUser($user);
} catch (ApiExceptions\NotFoundException $e) {
// nothing to do
}
}
}