/** * Delete a discussion. Update and/or delete all related data. * * Events: DeleteDiscussion. * * @since 2.0.0 * @access public * * @param int $DiscussionID Unique ID of discussion to delete. * @return bool Always returns TRUE. */ public function delete($DiscussionID, $Options = array()) { // Retrieve the users who have bookmarked this discussion. $BookmarkData = $this->GetBookmarkUsers($DiscussionID); $Data = $this->SQL->select('*')->from('Discussion')->where('DiscussionID', $DiscussionID)->get()->firstRow(DATASET_TYPE_ARRAY); $UserID = false; $CategoryID = false; if ($Data) { $UserID = $Data['InsertUserID']; $CategoryID = $Data['CategoryID']; } // Prep and fire event $this->EventArguments['DiscussionID'] = $DiscussionID; $this->EventArguments['Discussion'] = $Data; $this->fireEvent('DeleteDiscussion'); // Execute deletion of discussion and related bits $this->SQL->delete('Draft', array('DiscussionID' => $DiscussionID)); $Log = val('Log', $Options, true); $LogOptions = val('LogOptions', $Options, array()); if ($Log === true) { $Log = 'Delete'; } LogModel::BeginTransaction(); // Log all of the comment deletes. $Comments = $this->SQL->getWhere('Comment', array('DiscussionID' => $DiscussionID))->resultArray(); if (count($Comments) > 0 && count($Comments) < 50) { // A smaller number of comments should just be stored with the record. $Data['_Data']['Comment'] = $Comments; LogModel::insert($Log, 'Discussion', $Data, $LogOptions); } else { LogModel::insert($Log, 'Discussion', $Data, $LogOptions); foreach ($Comments as $Comment) { LogModel::insert($Log, 'Comment', $Comment, $LogOptions); } } LogModel::EndTransaction(); $this->SQL->delete('Comment', array('DiscussionID' => $DiscussionID)); $this->SQL->delete('Discussion', array('DiscussionID' => $DiscussionID)); $this->SQL->delete('UserDiscussion', array('DiscussionID' => $DiscussionID)); $this->UpdateDiscussionCount($CategoryID); // Get the user's discussion count. $this->UpdateUserDiscussionCount($UserID); // Update bookmark counts for users who had bookmarked this discussion foreach ($BookmarkData->result() as $User) { $this->SetUserBookmarkCount($User->UserID); } return true; }