/** * Remove the contest and all it's linked data from the database. * * @since 0.1 * * @return boolean Success indicator */ public function removeAllFromDB() { if (!ContestSettings::get('contestDeletionEnabled')) { // Shouldn't get here (UI should prevent it) throw new MWException('Contest deletion is disabled', 'contestdeletiondisabled'); } $condition = array('contest_id' => $this->getId()); $success = ContestChallenge::s()->delete($condition); if ($success) { $contestantIds = array(); foreach (ContestContestant::s()->select('id', $condition) as $contestant) { $contestantIds[] = $contestant->getId(); } if (count($contestantIds) > 0) { $success = ContestComment::s()->delete(array('contestant_id' => $contestantIds)) && $success; $success = ContestVote::s()->delete(array('contestant_id' => $contestantIds)) && $success; } $success = ContestContestant::s()->delete($condition) && $success; } if ($success) { $success = parent::removeFromDB(); } return $success; }