src/LdapTools/AttributeConverter/ConvertPrimaryGroup.php
protected function validateAndGetGroupSID($name)
    {
        $query = new LdapQueryBuilder($this->getLdapConnection());
        $query->select('objectSid')->where(['objectClass' => 'group', 'cn' => $name]);

        // Only validate group group membership on modification.
        if ($this->getOperationType() == AttributeConverterInterface::TYPE_MODIFY) {
            $query->andWhere(['member' => $this->getDn()]);
        }
        try {
            return $query->andWhere($query->filter()->bitwiseAnd('groupType', GroupType::SecurityEnabled))
                 ->getLdapQuery()
                 ->getSingleScalarResult();
        } catch (EmptyResultException $e) {
            throw new AttributeConverterException(sprintf(
                'Either the group "%s" doesn\'t exist, the user with DN "%s" is not a member of the group, the group'
                .' is not a security group, or this group is already their primary group.',
                $name,
                $this->getDn()
            ));
        }
    }
protected function validateAndGetGroupSID($name)
    {
        $query = new LdapQueryBuilder($this->getLdapConnection());
        $query->select('objectSid')->where(['objectClass' => 'group', 'cn' => $name]);

        // Only validate group group membership on modification.
        if ($this->getOperationType() == AttributeConverterInterface::TYPE_MODIFY) {
            $query->andWhere(['member' => $this->getDn()]);
        }
        try {
            return $query->andWhere($query->filter()->bitwiseAnd('groupType', GroupType::SecurityEnabled))
                 ->getLdapQuery()
                 ->getSingleScalarResult();
        } catch (EmptyResultException $e) {
            throw new AttributeConverterException(sprintf(
                'Either the group "%s" doesn\'t exist, the user with DN "%s" is not a member of the group, the group'
                .' is not a security group, or this group is already their primary group.',
                $name,
                $this->getDn()
            ));
        }
    }
protected function validateAndGetGroupSID ( $ name ) { $ query = new LdapQueryBuilder ( $ this -> getLdapConnection ( ) ) ; $ query -> select ( 'objectSid' ) -> where ( [ 'objectClass' => 'group' , 'cn' => $ name ] ) ; // Only validate group group membership on modification. if ( $ this -> getOperationType ( ) == AttributeConverterInterface :: TYPE_MODIFY ) { $ query -> andWhere ( [ 'member' => $ this -> getDn ( ) ] ) ; } try { return $ query -> andWhere ( $ query -> filter ( ) -> bitwiseAnd ( 'groupType' , GroupType :: SecurityEnabled ) ) -> getLdapQuery ( ) -> getSingleScalarResult ( ) ; } catch ( EmptyResultException $ e ) { throw new AttributeConverterException ( sprintf ( 'Either the group "%s" doesn\'t exist, the user with DN "%s" is not a member of the group, the group' . ' is not a security group, or this group is already their primary group.' , $ name , $ this -> getDn ( ) ) ) ; } }
Make sure that the group exists and that the user is already a member of it. If not, at least give an informative
message.

@param string $name The group name.
@return string The text SID of the group.
@throws AttributeConverterException
Make sure that the group exists and that the user is already a member of it . If not at least give an informative message .