Adjustments to make the TRIGGER execute properly.
This commit is contained in:
parent
d1b9996764
commit
5d4e2c84c8
3 changed files with 13 additions and 16 deletions
|
@ -38,7 +38,7 @@ if (!perms_check($perms, MSZ_FORUM_PERM_VIEW_FORUM)) {
|
||||||
|
|
||||||
$topicIsLocked = !empty($topic['topic_locked']);
|
$topicIsLocked = !empty($topic['topic_locked']);
|
||||||
$topicIsArchived = !empty($topic['topic_archived']);
|
$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;
|
$topicIsFrozen = $topicIsArchived || $topicIsDeleted;
|
||||||
$canDeleteOwn = !$topicIsFrozen && !$topicIsLocked && perms_check($perms, MSZ_FORUM_PERM_DELETE_POST);
|
$canDeleteOwn = !$topicIsFrozen && !$topicIsLocked && perms_check($perms, MSZ_FORUM_PERM_DELETE_POST);
|
||||||
$canBumpTopic = !$topicIsFrozen && perms_check($perms, MSZ_FORUM_PERM_BUMP_TOPIC);
|
$canBumpTopic = !$topicIsFrozen && perms_check($perms, MSZ_FORUM_PERM_BUMP_TOPIC);
|
||||||
|
@ -314,10 +314,10 @@ if (in_array($moderationMode, $validModerationModes, true)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$topicPosts = $topic['topic_post_count'];
|
$topicPosts = $topic['topic_count_posts'];
|
||||||
|
|
||||||
if ($canDeleteAny) {
|
if ($canDeleteAny) {
|
||||||
$topicPosts += $topic['topic_deleted_post_count'];
|
$topicPosts += $topic['topic_count_posts_deleted'];
|
||||||
}
|
}
|
||||||
|
|
||||||
$topicPagination = pagination_create($topicPosts, MSZ_FORUM_POSTS_PER_PAGE);
|
$topicPagination = pagination_create($topicPosts, MSZ_FORUM_POSTS_PER_PAGE);
|
||||||
|
|
|
@ -82,13 +82,13 @@ function forum_topic_get(int $topicId, bool $allowDeleted = false): array
|
||||||
FROM `msz_forum_posts`
|
FROM `msz_forum_posts`
|
||||||
WHERE `topic_id` = t.`topic_id`
|
WHERE `topic_id` = t.`topic_id`
|
||||||
AND `post_deleted` IS NULL
|
AND `post_deleted` IS NULL
|
||||||
) as `topic_post_count`,
|
) as `topic_count_posts`,
|
||||||
(
|
(
|
||||||
SELECT COUNT(`post_id`)
|
SELECT COUNT(`post_id`)
|
||||||
FROM `msz_forum_posts`
|
FROM `msz_forum_posts`
|
||||||
WHERE `topic_id` = t.`topic_id`
|
WHERE `topic_id` = t.`topic_id`
|
||||||
AND `post_deleted` IS NOT NULL
|
AND `post_deleted` IS NOT NULL
|
||||||
) as `topic_deleted_post_count`
|
) as `topic_count_posts_deleted`
|
||||||
FROM `msz_forum_topics` as t
|
FROM `msz_forum_topics` as t
|
||||||
LEFT JOIN `msz_forum_categories` as f
|
LEFT JOIN `msz_forum_categories` as f
|
||||||
ON f.`forum_id` = t.`forum_id`
|
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('
|
$markAsRead = db_prepare('
|
||||||
REPLACE INTO `msz_forum_topics_track`
|
INSERT INTO `msz_forum_topics_track`
|
||||||
(`user_id`, `topic_id`, `forum_id`, `track_last_read`)
|
(`user_id`, `topic_id`, `forum_id`, `track_last_read`)
|
||||||
VALUES
|
VALUES
|
||||||
(:user_id, :topic_id, :forum_id, NOW())
|
(:user_id, :topic_id, :forum_id, NOW())
|
||||||
|
ON DUPLICATE KEY UPDATE
|
||||||
|
`track_last_read` = NOW()
|
||||||
');
|
');
|
||||||
$markAsRead->bindValue('user_id', $userId);
|
$markAsRead->bindValue('user_id', $userId);
|
||||||
$markAsRead->bindValue('topic_id', $topicId);
|
$markAsRead->bindValue('topic_id', $topicId);
|
||||||
|
@ -145,7 +147,7 @@ function forum_topic_listing(int $forumId, int $userId, int $offset = 0, int $ta
|
||||||
SELECT
|
SELECT
|
||||||
:user_id AS `target_user_id`,
|
:user_id AS `target_user_id`,
|
||||||
t.`topic_id`, t.`topic_title`, t.`topic_locked`, t.`topic_type`, t.`topic_created`,
|
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`,
|
au.`user_id` AS `author_id`, au.`username` AS `author_name`,
|
||||||
COALESCE(au.`user_colour`, ar.`role_colour`) AS `author_colour`,
|
COALESCE(au.`user_colour`, ar.`role_colour`) AS `author_colour`,
|
||||||
lp.`post_id` AS `response_id`,
|
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`
|
FROM `msz_forum_posts`
|
||||||
WHERE `topic_id` = t.`topic_id`
|
WHERE `topic_id` = t.`topic_id`
|
||||||
%5$s
|
%5$s
|
||||||
) AS `topic_post_count`,
|
) AS `topic_count_posts`,
|
||||||
(
|
(
|
||||||
SELECT CEIL(COUNT(`post_id`) / %6$d)
|
SELECT CEIL(COUNT(`post_id`) / %6$d)
|
||||||
FROM `msz_forum_posts`
|
FROM `msz_forum_posts`
|
||||||
WHERE `topic_id` = t.`topic_id`
|
WHERE `topic_id` = t.`topic_id`
|
||||||
%5$s
|
%5$s
|
||||||
) AS `topic_pages`,
|
) AS `topic_pages`,
|
||||||
(
|
|
||||||
SELECT COUNT(`user_id`)
|
|
||||||
FROM `msz_forum_topics_track`
|
|
||||||
WHERE `topic_id` = t.`topic_id`
|
|
||||||
) AS `topic_view_count`,
|
|
||||||
(
|
(
|
||||||
SELECT
|
SELECT
|
||||||
`target_user_id` > 0
|
`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;
|
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) {
|
if ($totalReplies > MSZ_E_FORUM_TOPIC_DELETE_POSTS) {
|
||||||
return MSZ_E_FORUM_TOPIC_DELETE_POSTS;
|
return MSZ_E_FORUM_TOPIC_DELETE_POSTS;
|
||||||
|
|
|
@ -330,8 +330,8 @@
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="forum__topic__stats">
|
<div class="forum__topic__stats">
|
||||||
<div class="forum__topic__stat" title="Posts">{{ topic.topic_post_count|number_format }}</div>
|
<div class="forum__topic__stat" title="Posts">{{ topic.topic_count_posts|number_format }}</div>
|
||||||
<div class="forum__topic__stat" title="Views">{{ topic.topic_view_count|number_format }}</div>
|
<div class="forum__topic__stat" title="Views">{{ topic.topic_count_views|number_format }}</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="forum__topic__activity">
|
<div class="forum__topic__activity">
|
||||||
|
|
Loading…
Add table
Reference in a new issue