protected function maintainInactiveTeams() { // 6 months long inactive teams will be marked as deleted during maintenance // inactive is defined as the team did not match and no member logged in during last 6 months $six_months_in_past = strtotime('-6 months'); $six_months_in_past = strftime('%Y-%m-%d %H:%M:%S', $six_months_in_past); $teamIds = team::getInactiveTeamIds(); foreach ($teamIds as $teamid) { // check if team matched during last 6 months $team = new team($teamid); if (($lastMatch = $team->getNewestMatchTimestamp()) && $lastMatch < $six_months_in_past) { $uids = $team->getUserIds(); // check if user logged in during last 6 months $memberLoggedInRecently = false; foreach ($uids as $userid) { $user = new user($userid); if (($lastLogin = $user->getLastLoginTimestampStr()) && $lastLogin > $six_months_in_past) { $memberLoggedInRecently = true; } } // team did not match and none of its users logged in during last 6 months if (!$memberLoggedInRecently) { foreach ($uids as $userid) { $user = new user($userid); $user->removeTeamMembership($teamid); $user->update(); } $team->setStatus('deleted'); $team->update(); } } } }