From 6ca48e016f474f87be6996deb61c3bc07f922776 Mon Sep 17 00:00:00 2001 From: Toby Zerner Date: Fri, 19 Jun 2015 09:07:39 +0930 Subject: [PATCH] Run discussion events after first post is created --- .../Commands/StartDiscussionCommandHandler.php | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) 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; } }