Пример #1
0
 public function afterSave($insert, $changedAttributes)
 {
     parent::afterSave($insert, $changedAttributes);
     if (isset(Yii::$app->params['setting']) && Yii::$app->params['setting']['xunsearch']) {
         if ($insert) {
             $search = new Search();
             $search->topic_id = $this->id;
             $search->status = self::STATUS_ACTIVE;
         } else {
             $search = Search::findOne($this->id);
             if (!$search) {
                 // 如果立即修改 会因为在 xunsearch 找不到而不能 save
                 return false;
             }
             $search->status = $this->status;
         }
         $search->title = $this->title;
         $search->content = $this->content;
         $search->updated_at = $this->updated_at;
         $search->save();
     }
 }
Пример #2
0
 public function append()
 {
     if ($this->validate()) {
         $this->updated_at = time();
         if ($this->save()) {
             $topicContent = new TopicContent();
             if ($topicContent->load(Yii::$app->request->post())) {
                 $search = Search::findOne($this->id);
                 if (!empty($search)) {
                     $search->content .= $topicContent->content;
                     $search->save();
                 }
                 $topicContent->topic_id = $this->id;
                 $topicContent->is_append = 1;
                 $topicContent->created = time();
                 return $topicContent->save();
             }
         }
     }
     return false;
 }
Пример #3
0
 public function afterSave($insert, $changedAttributes)
 {
     parent::afterSave($insert, $changedAttributes);
     if ($insert) {
         $search = new Search();
         $search->topic_id = $this->id;
         $search->status = self::STATUS_ACTIVE;
     } else {
         //            Yii::$app->cache->set('topic' . $this->id, $this, 0);
         $search = Search::findOne($this->id);
         //            $search = false;
         if (!$search) {
             // 如果立即修改 会因为在 xunsearch 找不到而不能 save
             return false;
         }
         $search->status = $this->status;
     }
     $search->title = $this->title;
     $search->content = $this->content;
     $search->updated_at = $this->updated_at;
     $search->save();
 }
Пример #4
0
 public function afterSave($insert, $changedAttributes)
 {
     parent::afterSave($insert, $changedAttributes);
     if (isset(Yii::$app->params['setting']) && Yii::$app->params['setting']['xunsearch']) {
         if ($insert) {
             $search = new Search();
             $search->topic_id = $this->id;
             $search->status = self::STATUS_ACTIVE;
         } else {
             $search = Search::findOne($this->id);
             if (!$search) {
                 // 如果立即修改 会因为在 xunsearch 找不到而不能 save
                 return false;
             }
             $search->status = $this->status;
         }
         $search->title = $this->title;
         $search->content = $this->content;
         $search->updated_at = $this->updated_at;
         $search->save();
     }
     (new NotificationService())->newPostNotify(\Yii::$app->user->identity, $this, $this->atUsers);
     if ($insert) {
         // 保存 meta data
         (new UserMeta())->saveNewMeta('topic', $this->id, 'follow');
         // 更新个人总统计
         UserInfo::updateAllCounters(['post_count' => 1], ['user_id' => $this->user_id]);
     }
 }
Пример #5
0
 /**
  * Deletes an existing Topic model.
  * If deletion is successful, the browser will be redirected to the 'index' page.
  * @param integer $id
  * @return mixed
  */
 public function actionDelete($id)
 {
     $this->findModel($id)->delete();
     $search = Search::findOne($id);
     $search->delete();
     return $this->redirect(['index']);
 }
Пример #6
0
 /**
  * Deletes an existing Topic model.
  * If deletion is successful, the browser will be redirected to the 'index' page.
  * @param integer $id
  * @return mixed
  */
 public function actionDelete($id)
 {
     $this->findModel($id)->delete();
     Yii::$app->cache->get('topic' . $id);
     $search = Search::findOne($id);
     $search->delete();
     return $this->redirect(['index']);
 }