예제 #1
0
 public function beforeDelete()
 {
     if (parent::beforeDelete()) {
         //delete: Messages(to/from), Ban History, UpVotes, LogTopic
         YBoardMessage::deleteAll(['or', 'sendfrom' => $this->id, 'sendto' => $this->id]);
         // Post(Polls and Votes)
         YBoardVote::deleteAll(['user_id' => $this->id]);
         YBoardUpvoted::deleteAll(['member_id' => $this->id]);
         YBoardPoll::deleteAll(['user_id' => $this->id]);
         YBoardPost::deleteAll(['user_id' => $this->id]);
         //log topic
         YBoardLogTopic::deleteAll(['member_id' => $this->id]);
         //ban
         YBoardBan::deleteAll(['user_id' => $this->id]);
         return true;
     } else {
         return false;
     }
 }
 /**
  * Delete a post
  */
 public function actionDelete($id)
 {
     if (!Yii::$app->user->can('app.forum.moderator.delete-post')) {
         throw new ForbiddenHttpException(YBoard::t('yboard', 'You have no enough permission to access this page! If you think its a mistake, please consider reporting to us.'));
     }
     if (isset($_GET['id'])) {
         $id = $_GET['id'];
     }
     $post = YBoardPost::findOne($id);
     if ($post === null) {
         throw new NotFoundHttpException(YBoard::t('yboard', 'The requested post does not exist.'));
     }
     $forum = YBoardForum::findOne(YBoardTopic::findOne($post->topic_id)->forum_id);
     if ($post->original_post == 1) {
         $postDeleted = 0;
         $modelsToDelete = YBoardPost::find()->where(['topic_id' => $post->topic_id])->all();
         foreach ($modelsToDelete as $modelDel) {
             $pid = $modelDel->post_id;
             if ($modelDel->delete()) {
                 $postDeleted = $postDeleted - 1;
                 YBoardMessage::deleteAll(['post_id' => $pid]);
                 //delete all reports
             }
         }
         //decrement counts
         $forum->updateCounters(['num_topics' => $postDeleted]);
         YBoardLogTopic::deleteAll(['topic_id' => $post->topic_id]);
         //delete record in log
         $topic = YBoardTopic::findOne($post->topic_id)->delete();
     } else {
         $forum->updateCounters(['num_posts' => -1]);
         $post->delete();
         //Delete reports on the deleted post
         YBoardMessage::deleteAll(['post_id' => $id]);
     }
     // if AJAX request (triggered by deletion via admin grid view), we should not redirect the browser
     if (!isset($_GET['ajax'])) {
         $this->redirect(isset($_POST['returnUrl']) ? $_POST['returnUrl'] : ['approval']);
     } else {
         echo json_encode(['success' => true]);
     }
 }