src/PHPDish/Bundle/PostBundle/Service/CommentManager.php
public function saveComment(CommentInterface $comment)
    {
        $new = !$comment->getId();
        $parsedBody = $this->bodyProcessor->process($comment->getOriginalBody());

        $comment->setUpdatedAt(Carbon::now())
            ->setBody($parsedBody);

        //新增评论，维护post的数据
        if ($new) {
            $comment->getPost()->addCommentCount(1)
                ->setLastCommentAt(Carbon::now())
                ->setLastCommentUser($comment->getUser());
        }

        $this->entityManager->persist($comment);
        $this->entityManager->flush();

        //如果评论中有艾特用户则触发事件
        $mentionParser = $this->bodyProcessor->getMentionParser();
        if ($new && $mentionParser->getMentionedUsers()) {
            $this->eventDispatcher->dispatch(Events::USER_MENTIONED_COMMENT, new CommentMentionUserEvent(
                $comment,
                $mentionParser->getMentionedUsers()
            ));
        }

        return true;
    }
public function saveComment(CommentInterface $comment)
    {
        $new = !$comment->getId();
        $parsedBody = $this->bodyProcessor->process($comment->getOriginalBody());

        $comment->setUpdatedAt(Carbon::now())
            ->setBody($parsedBody);

        //新增评论，维护post的数据
        if ($new) {
            $comment->getPost()->addCommentCount(1)
                ->setLastCommentAt(Carbon::now())
                ->setLastCommentUser($comment->getUser());
        }

        $this->entityManager->persist($comment);
        $this->entityManager->flush();

        //如果评论中有艾特用户则触发事件
        $mentionParser = $this->bodyProcessor->getMentionParser();
        if ($new && $mentionParser->getMentionedUsers()) {
            $this->eventDispatcher->dispatch(Events::USER_MENTIONED_COMMENT, new CommentMentionUserEvent(
                $comment,
                $mentionParser->getMentionedUsers()
            ));
        }

        return true;
    }
{@inheritdoc}