/** * Special method for LDAP auth * sync LDAP groups to Scalr groups * * @param $groups */ public function applyLdapGroups($groups) { // get current teams $currentTeamIds = array(); foreach ($this->getTeams() as $t) { $currentTeamIds[$t['id']] = $t['name']; } if (count($groups)) { // create all links between LDAP user and teams ( == LDAP group) $groups[] = $this->getAccountId(); $teams = $this->db->GetCol('SELECT id FROM account_teams WHERE name IN(' . join(',', array_fill(0, count($groups) - 1, '?')) . ') AND account_id = ?', $groups); // team exists in DB, so we can save link foreach ($teams as $id) { $team = new Scalr_Account_Team(); $team->loadById($id); if (!$team->isTeamUser($this->id)) { $team->addUser($this->id); } unset($currentTeamIds[$id]); } } // remove old teams foreach ($currentTeamIds as $id => $name) { $team = new Scalr_Account_Team(); $team->loadById($id); $team->removeUser($this->id); } }