From 720b96051510a5c108d68b94d723bcef918a9e37 Mon Sep 17 00:00:00 2001 From: Toby Zerner Date: Mon, 29 Feb 2016 18:50:27 +1030 Subject: [PATCH] Don't require a previous Post when saving event posts A bit of an edge-case since it shouldn't really be possible to have a discussion with zero posts anymore, but when renaming an empty discussion (or taking any action that will create an "event post"), Flarum would crash. This is due to the MergeableInterface requiring these posts to be saved after a previous post. --- framework/core/src/Core/Post/DiscussionRenamedPost.php | 2 +- framework/core/src/Core/Post/MergeableInterface.php | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/framework/core/src/Core/Post/DiscussionRenamedPost.php b/framework/core/src/Core/Post/DiscussionRenamedPost.php index 29cec3264..fd34e7402 100755 --- a/framework/core/src/Core/Post/DiscussionRenamedPost.php +++ b/framework/core/src/Core/Post/DiscussionRenamedPost.php @@ -28,7 +28,7 @@ class DiscussionRenamedPost extends AbstractEventPost implements MergeableInterf /** * {@inheritdoc} */ - public function saveAfter(Post $previous) + public function saveAfter(Post $previous = null) { // If the previous post is another 'discussion renamed' post, and it's // by the same user, then we can merge this post into it. If we find diff --git a/framework/core/src/Core/Post/MergeableInterface.php b/framework/core/src/Core/Post/MergeableInterface.php index 4feca3e66..0e84d3a23 100644 --- a/framework/core/src/Core/Post/MergeableInterface.php +++ b/framework/core/src/Core/Post/MergeableInterface.php @@ -25,10 +25,10 @@ interface MergeableInterface * Save the model, given that it is going to appear immediately after the * passed model. * - * @param Post $previous + * @param Post|null $previous * @return Post The model resulting after the merge. If the merge is * unsuccessful, this should be the current model instance. Otherwise, * it should be the model that was merged into. */ - public function saveAfter(Post $previous); + public function saveAfter(Post $previous = null); }