From cdbc4b9717fa5c8bb4d67ba96d3c54aa3ca51cc0 Mon Sep 17 00:00:00 2001 From: Toby Zerner Date: Mon, 29 Feb 2016 18:41:27 +1030 Subject: [PATCH] Fix regressions related to deleting posts - On the front-end, correct the check to see if the discussion has no more posts - On the back-end, run a query to count the posts instead of using the comments_count, because the comments_count does not include other deleted posts --- js/forum/dist/app.js | 2 +- js/forum/src/utils/PostControls.js | 2 +- src/Core/Listener/DiscussionMetadataUpdater.php | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/js/forum/dist/app.js b/js/forum/dist/app.js index 8f1f2dc10..951bf29e2 100644 --- a/js/forum/dist/app.js +++ b/js/forum/dist/app.js @@ -33899,7 +33899,7 @@ System.register('flarum/utils/PostControls', ['flarum/components/EditPostCompose // If this was the last post in the discussion, then we will assume that // the whole discussion was deleted too. - if (!discussion.posts.length) { + if (!discussion.postIds().length) { // If there is a discussion list in the cache, remove this discussion. if (app.cache.discussionList) { app.cache.discussionList.removeDiscussion(discussion); diff --git a/js/forum/src/utils/PostControls.js b/js/forum/src/utils/PostControls.js index 461c9c6ac..56f9e6955 100644 --- a/js/forum/src/utils/PostControls.js +++ b/js/forum/src/utils/PostControls.js @@ -155,7 +155,7 @@ export default { // If this was the last post in the discussion, then we will assume that // the whole discussion was deleted too. - if (!discussion.posts.length) { + if (!discussion.postIds().length) { // If there is a discussion list in the cache, remove this discussion. if (app.cache.discussionList) { app.cache.discussionList.removeDiscussion(discussion); diff --git a/src/Core/Listener/DiscussionMetadataUpdater.php b/src/Core/Listener/DiscussionMetadataUpdater.php index 0b392fa0d..cf1ebb3fc 100755 --- a/src/Core/Listener/DiscussionMetadataUpdater.php +++ b/src/Core/Listener/DiscussionMetadataUpdater.php @@ -54,7 +54,7 @@ class DiscussionMetadataUpdater $discussion = $event->post->discussion; - if ($discussion->comments_count === 0) { + if ($discussion->posts()->count() === 0) { $discussion->delete(); } }