Update start_post_id when starting a discussion

This commit is contained in:
Toby Zerner 2015-06-25 09:48:28 +09:30
parent 649fbf3377
commit 046c6e2168
2 changed files with 22 additions and 0 deletions

View File

@ -44,9 +44,12 @@ class StartDiscussionCommandHandler
// attributes as posting the reply will have changed some of them (e.g.
// last_time.)
$discussion->setRawAttributes($post->discussion->getAttributes(), true);
$discussion->setStartPost($post);
$this->dispatchEventsFor($discussion);
$discussion->save();
return $post->discussion;
}
}

View File

@ -134,6 +134,21 @@ class Discussion extends Model
return $this;
}
/**
* Set the discussion's start post details.
*
* @param \Flarum\Core\Models\Post $post
* @return $this
*/
public function setStartPost(Post $post)
{
$this->start_time = $post->time;
$this->start_user_id = $post->user_id;
$this->start_post_id = $post->id;
return $this;
}
/**
* Set the discussion's last post details.
*
@ -350,6 +365,10 @@ class Discussion extends Model
*/
public function stateFor(User $user)
{
// If the state is already eager-loaded, we'll return that.
// Unfortunately we can't check to see if the user ID is the same,
// because the user may not have a state entry, in which case the loaded
// relation will be null.
if ($this->isRelationLoaded('state')) {
return $this->relations['state'];
}