From 14b1a0dc4f010bb5810d3751749e123eb344163f Mon Sep 17 00:00:00 2001 From: Toby Zerner Date: Thu, 7 May 2015 06:38:40 +0930 Subject: [PATCH] Change mergeInto return signature; only merge posts if same user --- .../src/Core/Models/DiscussionRenamedPost.php | 15 ++++++++++----- framework/core/src/Core/Models/MergeableTrait.php | 8 ++++---- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/framework/core/src/Core/Models/DiscussionRenamedPost.php b/framework/core/src/Core/Models/DiscussionRenamedPost.php index f02ee934c..0efdc55cd 100755 --- a/framework/core/src/Core/Models/DiscussionRenamedPost.php +++ b/framework/core/src/Core/Models/DiscussionRenamedPost.php @@ -13,16 +13,21 @@ class DiscussionRenamedPost extends ActivityPost * Merge the post into another post of the same type. * * @param \Flarum\Core\Models\DiscussionRenamedPost $previous - * @return boolean true if the post was merged, false if it was deleted. + * @return \Flarum\Core\Models\Model|null The final model, or null if the + * previous post was deleted. */ protected function mergeInto(Model $previous) { - if ($previous->content[0] == $this->content[1]) { - return false; + if ($this->user_id === $previous->user_id) { + if ($previous->content[0] == $this->content[1]) { + return; + } + + $previous->content = static::buildContent($previous->content[0], $this->content[1]); + return $previous; } - $previous->content = static::buildContent($previous->content[0], $this->content[1]); - return true; + return $this; } /** diff --git a/framework/core/src/Core/Models/MergeableTrait.php b/framework/core/src/Core/Models/MergeableTrait.php index 7d11defeb..04ddc79f8 100644 --- a/framework/core/src/Core/Models/MergeableTrait.php +++ b/framework/core/src/Core/Models/MergeableTrait.php @@ -5,13 +5,13 @@ trait MergeableTrait public function saveAfter(Model $previous) { if ($previous instanceof static) { - if ($this->mergeInto($previous)) { - $previous->save(); + if ($merged = $this->mergeInto($previous)) { + $merged->save(); + return $merged; } else { $previous->delete(); + return $previous; } - - return $previous; } $this->save();