Ejemplo n.º 1
0
 /**
  * 伪删除
  * @param $id
  * @return \yii\web\Response
  * @throws NotFoundHttpException
  */
 public function actionDelete($id)
 {
     $model = PostComment::findComment($id);
     if (!$model->isCurrent()) {
         throw new NotFoundHttpException();
     }
     // 事物 暂时数据库类型不支持 无效
     $transaction = \Yii::$app->db->beginTransaction();
     $updateComment = $model->updateCounters(['status' => -1]);
     $updateNotify = Notification::updateAll(['status' => 0], ['comment_id' => $model->id]);
     $updateTopic = Topic::updateAllCounters(['comment_count' => -1], ['id' => $model->post_id]);
     if ($updateNotify && $updateComment && $updateTopic) {
         $transaction->commit();
     } else {
         $transaction->rollback();
     }
     return $this->redirect(['/topic/default/view', 'id' => $model->post_id]);
 }
Ejemplo n.º 2
0
 /**
  * 伪删除
  * @param $id
  * @return \yii\web\Response
  * @throws NotFoundHttpException
  */
 public function actionDelete($id)
 {
     $model = Topic::findTopic($id);
     if (!$model->isCurrent()) {
         throw new NotFoundHttpException();
     }
     if ($model->comment_count) {
         $this->flash("「{$model->title}」此文章已有评论,属于共有财产,不能删除", 'warning');
     } else {
         $model->updateAttributes(['status' => 0]);
         Notification::updateAll(['status' => 0], ['post_id' => $model->id]);
         $revoke = Html::a('撤消', ['/topic/default/revoke', 'id' => $model->id]);
         $this->flash("「{$model->title}」文章删除成功。 反悔了?{$revoke}", 'success');
     }
     return $this->redirect(['index']);
 }
Ejemplo n.º 3
0
 /**
  * 删除帖子
  * @param Post $post
  */
 public static function delete(Post $post)
 {
     $post->setAttributes(['status' => Post::STATUS_DELETED]);
     $post->save();
     Notification::updateAll(['status' => Post::STATUS_DELETED], ['post_id' => $post->id]);
 }