eZ\Bundle\EzPublishCoreBundle\Features\Context\UserContext::ensureUserDoesntExist PHP Method

ensureUserDoesntExist() public method

Make sure a User with name $username does not exist (in parent group).
public ensureUserDoesntExist ( string $username, string $parentGroupName = null )
$username string User name
$parentGroupName string (optional) name of the parent group to check
    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
            }
        }
    }