diff --git a/framework/core/src/Core/Handlers/Commands/StartDiscussionCommandHandler.php b/framework/core/src/Core/Handlers/Commands/StartDiscussionCommandHandler.php index b4ce16612..4a9b61906 100644 --- a/framework/core/src/Core/Handlers/Commands/StartDiscussionCommandHandler.php +++ b/framework/core/src/Core/Handlers/Commands/StartDiscussionCommandHandler.php @@ -34,16 +34,19 @@ class StartDiscussionCommandHandler $discussion->save(); - $this->dispatchEventsFor($discussion); - // Now that the discussion has been created, we can add the first post. - // For now we will do this by running the PostReply command, but as this - // will trigger a domain event that is slightly semantically incorrect - // in this situation (PostWasPosted), we may need to reconsider someday. + // We will do this by running the PostReply command. $post = $this->bus->dispatch( new PostReplyCommand($discussion->id, $command->user, $command->data) ); + // Before we dispatch events, refresh our discussion instance's + // attributes as posting the reply will have changed some of them (e.g. + // last_time.) + $discussion->setRawAttributes($post->discussion->getAttributes(), true); + + $this->dispatchEventsFor($discussion); + return $post->discussion; } }