//-------------------------------------------- // Hard delete a thread. //-------------------------------------------- function hardDelete() { //-------------------------------------------- // Hard delete a thread.. (really delete it) //-------------------------------------------- $finder = &$this->getFinder('threads'); $finder->delete($this->getId()); //-------------------------------------------- // Delete all of this threads revisions. //-------------------------------------------- $finder = &$this->getFinder('thread_revisions'); $finder->deleteBy("thread_id", $this->getId()); //-------------------------------------------- // Delete all of this threads authors //-------------------------------------------- $finder = &$this->getFinder('thread_users'); $finder->deleteBy("thread_id", $this->getId()); //-------------------------------------------- // Delete all of this threads tags. //-------------------------------------------- $finder = &$this->getFinder('thread_tags'); $finder->deleteBy("thread_id", $this->getId()); //-------------------------------------------- // Delete all bookmark tags on this thread. //-------------------------------------------- $finder = &$this->getFinder('thread_user_tags'); $finder->deleteBy("thread_id", $this->getId()); //-------------------------------------------- // Delete all karma records relating to this thread. //-------------------------------------------- $finder = &$this->getFinder('post_karma'); $finder->deleteBy("thread_id", $this->getId()); //-------------------------------------------- // Delete all of the comments of this thread and // change the comment counts of the posters of // those comments. //-------------------------------------------- $finder = &$this->getFinder('comments'); $comments = &$finder->findAllBy("thread_id", $this->getId()); $user_ids = array(); $comment_ids = ""; $user_ids_single = ""; //-------------------------------------------- // Loop through the comments, derive their id's // and the id's of their posters. //-------------------------------------------- if($comments !== NULL) { while($comments->next()) { $comment = &$comments->current(); $comment_ids .= "'". $comment->getId() ."',"; //-------------------------------------------- // This user isn't a guest so let's make sure // that we will update their comment count. //-------------------------------------------- if($comment->get('user_id') != K4_GUEST_ID) { if(!isset($user_ids[$comment->get('user_id')])) { $user_ids[$comment->get('user_id')] = 0; } $user_ids[$comment->get('user_id')]++; } } $comment_ids = substr_utf($comment_ids, 0, strlen_utf($comment_ids) - 1); //-------------------------------------------- // Delete the comments. //-------------------------------------------- $finder = &$this->getFinder('comments'); $finder->deleteWhere("comment_id IN(". $comment_ids .")", array()); } if(count($user_ids) > 0) { foreach($user_ids as $user_id => $num_comments) { if($num_comments == 1) { //-------------------------------------------- // Add this user's id to the list of ids to be // mass updated. //-------------------------------------------- $user_ids_single .= "'". $user_id ."',"; } else { //-------------------------------------------- // Update this users post count if s/he has // made > 1 comment in this thread. //-------------------------------------------- $this->_dba->executeUpdate("UPDATE k4_users SET num_comments=num_comments-{$num_comments} WHERE user_id=?", array($user_id)); } } //-------------------------------------------- // Update multiple users post counts. //-------------------------------------------- if($user_ids_single != "") { $user_ids_single = substr_utf($user_ids_single, 0, strlen_utf($user_ids_single) - 1); $this->_dba->executeUpdate("UPDATE k4_users SET num_comments=num_comments-1 WHERE user_id IN({$user_ids_single})", array()); } } //-------------------------------------------- // Update the posters thread count. //-------------------------------------------- if($this->get('user_id') != K4_GUEST_ID) { $finder = &$this->getFinder('users'); $user = &$finder->find($this->get('user_id')); $user->set('thread_count', $user->get('thread_count')-1); } //-------------------------------------------- // This thread is NOT coming back :P //-------------------------------------------- return TRUE; }