From 5d4e2c84c8847e233f90354036c6d9112648e7a8 Mon Sep 17 00:00:00 2001 From: flashwave Date: Sun, 3 Mar 2019 16:26:23 +0100 Subject: [PATCH] Adjustments to make the TRIGGER execute properly. --- public/forum/topic.php | 6 +++--- src/Forum/topic.php | 19 ++++++++----------- templates/forum/macros.twig | 4 ++-- 3 files changed, 13 insertions(+), 16 deletions(-) diff --git a/public/forum/topic.php b/public/forum/topic.php index 0c09f5f3..4fb30e5a 100644 --- a/public/forum/topic.php +++ b/public/forum/topic.php @@ -38,7 +38,7 @@ if (!perms_check($perms, MSZ_FORUM_PERM_VIEW_FORUM)) { $topicIsLocked = !empty($topic['topic_locked']); $topicIsArchived = !empty($topic['topic_archived']); -$topicPostsTotal = (int)($topic['topic_post_count'] + $topic['topic_deleted_post_count']); +$topicPostsTotal = (int)($topic['topic_count_posts'] + $topic['topic_count_posts_deleted']); $topicIsFrozen = $topicIsArchived || $topicIsDeleted; $canDeleteOwn = !$topicIsFrozen && !$topicIsLocked && perms_check($perms, MSZ_FORUM_PERM_DELETE_POST); $canBumpTopic = !$topicIsFrozen && perms_check($perms, MSZ_FORUM_PERM_BUMP_TOPIC); @@ -314,10 +314,10 @@ if (in_array($moderationMode, $validModerationModes, true)) { return; } -$topicPosts = $topic['topic_post_count']; +$topicPosts = $topic['topic_count_posts']; if ($canDeleteAny) { - $topicPosts += $topic['topic_deleted_post_count']; + $topicPosts += $topic['topic_count_posts_deleted']; } $topicPagination = pagination_create($topicPosts, MSZ_FORUM_POSTS_PER_PAGE); diff --git a/src/Forum/topic.php b/src/Forum/topic.php index 3528e788..6ee6dc87 100644 --- a/src/Forum/topic.php +++ b/src/Forum/topic.php @@ -82,13 +82,13 @@ function forum_topic_get(int $topicId, bool $allowDeleted = false): array FROM `msz_forum_posts` WHERE `topic_id` = t.`topic_id` AND `post_deleted` IS NULL - ) as `topic_post_count`, + ) as `topic_count_posts`, ( SELECT COUNT(`post_id`) FROM `msz_forum_posts` WHERE `topic_id` = t.`topic_id` AND `post_deleted` IS NOT NULL - ) as `topic_deleted_post_count` + ) as `topic_count_posts_deleted` FROM `msz_forum_topics` as t LEFT JOIN `msz_forum_categories` as f ON f.`forum_id` = t.`forum_id` @@ -126,10 +126,12 @@ function forum_topic_mark_read(int $userId, int $topicId, int $forumId): void } $markAsRead = db_prepare(' - REPLACE INTO `msz_forum_topics_track` + INSERT INTO `msz_forum_topics_track` (`user_id`, `topic_id`, `forum_id`, `track_last_read`) VALUES (:user_id, :topic_id, :forum_id, NOW()) + ON DUPLICATE KEY UPDATE + `track_last_read` = NOW() '); $markAsRead->bindValue('user_id', $userId); $markAsRead->bindValue('topic_id', $topicId); @@ -145,7 +147,7 @@ function forum_topic_listing(int $forumId, int $userId, int $offset = 0, int $ta SELECT :user_id AS `target_user_id`, t.`topic_id`, t.`topic_title`, t.`topic_locked`, t.`topic_type`, t.`topic_created`, - t.`topic_bumped`, t.`topic_deleted`, + t.`topic_bumped`, t.`topic_deleted`, t.`topic_count_views`, au.`user_id` AS `author_id`, au.`username` AS `author_name`, COALESCE(au.`user_colour`, ar.`role_colour`) AS `author_colour`, lp.`post_id` AS `response_id`, @@ -158,18 +160,13 @@ function forum_topic_listing(int $forumId, int $userId, int $offset = 0, int $ta FROM `msz_forum_posts` WHERE `topic_id` = t.`topic_id` %5$s - ) AS `topic_post_count`, + ) AS `topic_count_posts`, ( SELECT CEIL(COUNT(`post_id`) / %6$d) FROM `msz_forum_posts` WHERE `topic_id` = t.`topic_id` %5$s ) AS `topic_pages`, - ( - SELECT COUNT(`user_id`) - FROM `msz_forum_topics_track` - WHERE `topic_id` = t.`topic_id` - ) AS `topic_view_count`, ( SELECT `target_user_id` > 0 @@ -334,7 +331,7 @@ function forum_topic_can_delete($topicId, ?int $userId = null): int return MSZ_E_FORUM_TOPIC_DELETE_OLD; } - $totalReplies = $topic['topic_post_count'] + $topic['topic_deleted_post_count']; + $totalReplies = $topic['topic_count_posts'] + $topic['topic_count_posts_deleted']; if ($totalReplies > MSZ_E_FORUM_TOPIC_DELETE_POSTS) { return MSZ_E_FORUM_TOPIC_DELETE_POSTS; diff --git a/templates/forum/macros.twig b/templates/forum/macros.twig index 05350a79..bc3c017c 100644 --- a/templates/forum/macros.twig +++ b/templates/forum/macros.twig @@ -330,8 +330,8 @@
-
{{ topic.topic_post_count|number_format }}
-
{{ topic.topic_view_count|number_format }}
+
{{ topic.topic_count_posts|number_format }}
+
{{ topic.topic_count_views|number_format }}