public function updateGroupFromLDAP(Group $group, $data)
    {
        if (!$this->enabled()) {
            return false;
        }

        // Synchronise specific guaranteed fields.
        $group->Code = $data['samaccountname'];
        $group->Title = $data['samaccountname'];
        if (!empty($data['description'])) {
            $group->Description = $data['description'];
        }
        $group->DN = $data['dn'];
        $group->LastSynced = (string)SS_Datetime::now();
        $group->write();

        // Mappings on this group are automatically maintained to contain just the group's DN.
        // First, scan through existing mappings and remove ones that are not matching (in case the group moved).
        $hasCorrectMapping = false;
        foreach ($group->LDAPGroupMappings() as $mapping) {
            if ($mapping->DN === $data['dn']) {
                // This is the correct mapping we want to retain.
                $hasCorrectMapping = true;
            } else {
                $mapping->delete();
            }
        }

        // Second, if the main mapping was not found, add it in.
        if (!$hasCorrectMapping) {
            $mapping = new LDAPGroupMapping();
            $mapping->DN = $data['dn'];
            $mapping->write();
            $group->LDAPGroupMappings()->add($mapping);
        }
    }
public function updateGroupFromLDAP(Group $group, $data)
    {
        if (!$this->enabled()) {
            return false;
        }

        // Synchronise specific guaranteed fields.
        $group->Code = $data['samaccountname'];
        $group->Title = $data['samaccountname'];
        if (!empty($data['description'])) {
            $group->Description = $data['description'];
        }
        $group->DN = $data['dn'];
        $group->LastSynced = (string)SS_Datetime::now();
        $group->write();

        // Mappings on this group are automatically maintained to contain just the group's DN.
        // First, scan through existing mappings and remove ones that are not matching (in case the group moved).
        $hasCorrectMapping = false;
        foreach ($group->LDAPGroupMappings() as $mapping) {
            if ($mapping->DN === $data['dn']) {
                // This is the correct mapping we want to retain.
                $hasCorrectMapping = true;
            } else {
                $mapping->delete();
            }
        }

        // Second, if the main mapping was not found, add it in.
        if (!$hasCorrectMapping) {
            $mapping = new LDAPGroupMapping();
            $mapping->DN = $data['dn'];
            $mapping->write();
            $group->LDAPGroupMappings()->add($mapping);
        }
    }
public function updateGroupFromLDAP ( Group $ group , $ data ) { if ( ! $ this -> enabled ( ) ) { return false ; } // Synchronise specific guaranteed fields. $ group -> Code = $ data [ 'samaccountname' ] ; $ group -> Title = $ data [ 'samaccountname' ] ; if ( ! empty ( $ data [ 'description' ] ) ) { $ group -> Description = $ data [ 'description' ] ; } $ group -> DN = $ data [ 'dn' ] ; $ group -> LastSynced = ( string ) SS_Datetime :: now ( ) ; $ group -> write ( ) ; // Mappings on this group are automatically maintained to contain just the group's DN. // First, scan through existing mappings and remove ones that are not matching (in case the group moved). $ hasCorrectMapping = false ; foreach ( $ group -> LDAPGroupMappings ( ) as $ mapping ) { if ( $ mapping -> DN === $ data [ 'dn' ] ) { // This is the correct mapping we want to retain. $ hasCorrectMapping = true ; } else { $ mapping -> delete ( ) ; } } // Second, if the main mapping was not found, add it in. if ( ! $ hasCorrectMapping ) { $ mapping = new LDAPGroupMapping ( ) ; $ mapping -> DN = $ data [ 'dn' ] ; $ mapping -> write ( ) ; $ group -> LDAPGroupMappings ( ) -> add ( $ mapping ) ; } }
Sync a specific Group by updating it with LDAP data.

@param Group $group An existing Group or a new Group object
@param array $data LDAP group object data

@return bool
Sync a specific Group by updating it with LDAP data .