protected function createUser($username, $email, $password, $parentGroup = null, $fields = array())
    {
        $userCreateStruct = $this->userService->newUserCreateStruct(
            $username,
            $email,
            $password,
            self::DEFAULT_LANGUAGE
        );
        $userCreateStruct->setField('first_name', $username);
        $userCreateStruct->setField('last_name', $username);

        foreach ($fields as $fieldName => $fieldValue) {
            $userCreateStruct->setField($fieldName, $fieldValue);
        }

        try {
            $existingUser = $this->userService->loadUserByLogin($username);
            $this->userService->deleteUser($existingUser);
        } catch (NotFoundException $e) {
            // do nothing
        }

        if (!$parentGroup) {
            $parentGroup = $this->userService->loadUserGroup(self::USERGROUP_ROOT_CONTENT_ID);
        }

        $user = $this->userService->createUser($userCreateStruct, array($parentGroup));

        return $user;
    }
protected function createUser($username, $email, $password, $parentGroup = null, $fields = array())
    {
        $userCreateStruct = $this->userService->newUserCreateStruct(
            $username,
            $email,
            $password,
            self::DEFAULT_LANGUAGE
        );
        $userCreateStruct->setField('first_name', $username);
        $userCreateStruct->setField('last_name', $username);

        foreach ($fields as $fieldName => $fieldValue) {
            $userCreateStruct->setField($fieldName, $fieldValue);
        }

        try {
            $existingUser = $this->userService->loadUserByLogin($username);
            $this->userService->deleteUser($existingUser);
        } catch (NotFoundException $e) {
            // do nothing
        }

        if (!$parentGroup) {
            $parentGroup = $this->userService->loadUserGroup(self::USERGROUP_ROOT_CONTENT_ID);
        }

        $user = $this->userService->createUser($userCreateStruct, array($parentGroup));

        return $user;
    }
protected function createUser ( $ username , $ email , $ password , $ parentGroup = null , $ fields = array ( ) ) { $ userCreateStruct = $ this -> userService -> newUserCreateStruct ( $ username , $ email , $ password , self :: DEFAULT_LANGUAGE ) ; $ userCreateStruct -> setField ( 'first_name' , $ username ) ; $ userCreateStruct -> setField ( 'last_name' , $ username ) ; foreach ( $ fields as $ fieldName => $ fieldValue ) { $ userCreateStruct -> setField ( $ fieldName , $ fieldValue ) ; } try { $ existingUser = $ this -> userService -> loadUserByLogin ( $ username ) ; $ this -> userService -> deleteUser ( $ existingUser ) ; } catch ( NotFoundException $ e ) { // do nothing } if ( ! $ parentGroup ) { $ parentGroup = $ this -> userService -> loadUserGroup ( self :: USERGROUP_ROOT_CONTENT_ID ) ; } $ user = $ this -> userService -> createUser ( $ userCreateStruct , array ( $ parentGroup ) ) ; return $ user ; }
Create user inside given User Group; DELETES existing User if login already exists!

@param $username username of the user to create
@param $email email address of user to create
@param $password account password for user to create
@param $parentGroup pathstring wherein to create user

@return eZ\Publish\API\Repository\Values\User\User
Create user inside given User Group ; DELETES existing User if login already exists!