From e62119964bebebf37757b59c53e1cf3302aa2d7d Mon Sep 17 00:00:00 2001 From: Toby Zerner Date: Tue, 24 Mar 2015 15:06:57 +1030 Subject: [PATCH] All post types get numbers MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Decided this is necessary because some notifications will need to link to posts which are not comments (e.g. a “renamed” post) --- src/Core/Models/CommentPost.php | 16 ---------------- src/Core/Models/Post.php | 9 ++++++++- 2 files changed, 8 insertions(+), 17 deletions(-) diff --git a/src/Core/Models/CommentPost.php b/src/Core/Models/CommentPost.php index 40baf1f7a..cb81e62e8 100755 --- a/src/Core/Models/CommentPost.php +++ b/src/Core/Models/CommentPost.php @@ -15,22 +15,6 @@ class CommentPost extends Post */ 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. * diff --git a/src/Core/Models/Post.php b/src/Core/Models/Post.php index f8f3c0eed..c387331aa 100755 --- a/src/Core/Models/Post.php +++ b/src/Core/Models/Post.php @@ -47,7 +47,9 @@ class Post extends Model 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 */ @@ -55,6 +57,11 @@ class Post extends Model { parent::boot(); + static::creating(function ($post) { + $post->number = ++$post->discussion->number_index; + $post->discussion->save(); + }); + static::deleted(function ($post) { $post->raise(new PostWasDeleted($post)); });