frontend\modules\topic\models\Topic::afterSave PHP Method

afterSave() public method

public afterSave ( $insert, $changedAttributes )
    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]);
        }
    }