Fix potential error when discussion doesn't exist

Not sure how this could be the case, but can't hurt to add the checks.
addresses #343
This commit is contained in:
Toby Zerner 2015-09-01 10:07:13 +09:30
parent c91f8de1f5
commit 6aafe54ee7

View File

@ -37,10 +37,12 @@ class DiscussionMetadataUpdater
{
$discussion = $event->post->discussion;
$discussion->comments_count++;
$discussion->setLastPost($event->post);
$discussion->refreshParticipantsCount();
$discussion->save();
if ($discussion && $discussion->exists) {
$discussion->comments_count++;
$discussion->setLastPost($event->post);
$discussion->refreshParticipantsCount();
$discussion->save();
}
}
/**
@ -66,10 +68,12 @@ class DiscussionMetadataUpdater
{
$discussion = $event->post->discussion;
$discussion->refreshCommentsCount();
$discussion->refreshParticipantsCount();
$discussion->refreshLastPost();
$discussion->save();
if ($discussion && $discussion->exists) {
$discussion->refreshCommentsCount();
$discussion->refreshParticipantsCount();
$discussion->refreshLastPost();
$discussion->save();
}
}
/**
@ -79,7 +83,7 @@ class DiscussionMetadataUpdater
{
$discussion = $post->discussion;
if ($discussion->exists) {
if ($discussion && $discussion->exists) {
$discussion->refreshCommentsCount();
$discussion->refreshParticipantsCount();