mirror of
https://github.com/flarum/core.git
synced 2025-08-02 14:37:49 +02:00
All post types get numbers
Decided this is necessary because some notifications will need to link to posts which are not comments (e.g. a “renamed” post)
This commit is contained in:
@@ -15,22 +15,6 @@ class CommentPost extends Post
|
|||||||
*/
|
*/
|
||||||
protected static $formatter;
|
protected static $formatter;
|
||||||
|
|
||||||
/**
|
|
||||||
* Add an event listener to set the post's number, and update the
|
|
||||||
* discussion's number index, when inserting a post.
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public static function boot()
|
|
||||||
{
|
|
||||||
parent::boot();
|
|
||||||
|
|
||||||
static::creating(function ($post) {
|
|
||||||
$post->number = ++$post->discussion->number_index;
|
|
||||||
$post->discussion->save();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new instance in reply to a discussion.
|
* Create a new instance in reply to a discussion.
|
||||||
*
|
*
|
||||||
|
@@ -47,7 +47,9 @@ class Post extends Model
|
|||||||
protected static $types = [];
|
protected static $types = [];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Raise an event when a post is deleted.
|
* Raise an event when a post is deleted. Add an event listener to set the
|
||||||
|
* post's number, and update the discussion's number index, when inserting
|
||||||
|
* a post.
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
@@ -55,6 +57,11 @@ class Post extends Model
|
|||||||
{
|
{
|
||||||
parent::boot();
|
parent::boot();
|
||||||
|
|
||||||
|
static::creating(function ($post) {
|
||||||
|
$post->number = ++$post->discussion->number_index;
|
||||||
|
$post->discussion->save();
|
||||||
|
});
|
||||||
|
|
||||||
static::deleted(function ($post) {
|
static::deleted(function ($post) {
|
||||||
$post->raise(new PostWasDeleted($post));
|
$post->raise(new PostWasDeleted($post));
|
||||||
});
|
});
|
||||||
|
Reference in New Issue
Block a user