mirror of
https://github.com/flarum/framework.git
synced 2024-12-04 16:23:37 +08:00
Change mergeInto return signature; only merge posts if same user
This commit is contained in:
parent
fd2708485a
commit
14b1a0dc4f
|
@ -13,16 +13,21 @@ class DiscussionRenamedPost extends ActivityPost
|
||||||
* Merge the post into another post of the same type.
|
* Merge the post into another post of the same type.
|
||||||
*
|
*
|
||||||
* @param \Flarum\Core\Models\DiscussionRenamedPost $previous
|
* @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)
|
protected function mergeInto(Model $previous)
|
||||||
{
|
{
|
||||||
|
if ($this->user_id === $previous->user_id) {
|
||||||
if ($previous->content[0] == $this->content[1]) {
|
if ($previous->content[0] == $this->content[1]) {
|
||||||
return false;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$previous->content = static::buildContent($previous->content[0], $this->content[1]);
|
$previous->content = static::buildContent($previous->content[0], $this->content[1]);
|
||||||
return true;
|
return $previous;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -5,14 +5,14 @@ trait MergeableTrait
|
||||||
public function saveAfter(Model $previous)
|
public function saveAfter(Model $previous)
|
||||||
{
|
{
|
||||||
if ($previous instanceof static) {
|
if ($previous instanceof static) {
|
||||||
if ($this->mergeInto($previous)) {
|
if ($merged = $this->mergeInto($previous)) {
|
||||||
$previous->save();
|
$merged->save();
|
||||||
|
return $merged;
|
||||||
} else {
|
} else {
|
||||||
$previous->delete();
|
$previous->delete();
|
||||||
}
|
|
||||||
|
|
||||||
return $previous;
|
return $previous;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$this->save();
|
$this->save();
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user