/** * Delete a team and all team memberships. This method will only work if no items are assigned to the team. */ function delete_team() { //todo: Verify that no items are still assigned to this team. if ($this->id == $this->global_team) { $msg = $GLOBALS['app_strings']['LBL_MASSUPDATE_DELETE_GLOBAL_TEAM']; $GLOBALS['log']->fatal($msg); die($msg); } //Check if the associated user is deleted $user = BeanFactory::getBean('Users', $this->associated_user_id); if ($this->private == 1 && (!empty($user->id) && $user->deleted != 1)) { $msg = string_format($GLOBALS['app_strings']['LBL_MASSUPDATE_DELETE_USER_EXISTS'], array(Team::getDisplayName($this->name, $this->name_2), $user->full_name)); $GLOBALS['log']->error($msg); SugarApplication::appendErrorMessage($msg); return false; } // Update team_memberships table and set deleted = 1 $query = "UPDATE team_memberships SET deleted = 1 WHERE team_id='{$this->id}'"; $this->db->query($query, true, "Error deleting memberships while deleting team: "); // Update teams and set deleted = 1 $this->deleted = 1; $this->save(); require_once 'modules/Teams/TeamSetManager.php'; TeamSetManager::flushBackendCache(); //clean up any team sets that use this team id TeamSetManager::removeTeamFromSets($this->id); // Take the item off the recently viewed lists $tracker = BeanFactory::getBean('Trackers'); $tracker->makeInvisibleForAll($this->id); }