Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Sources/Actions/Admin/Boards.php
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,7 @@ public function editBoard(): void
'is_new' => true,
'name' => Lang::getTxt('mboards_new_board_name', file: 'ManageBoards'),
'description' => '',
'count_posts' => true,
'posts_count' => true,
'posts' => 0,
'topics' => 0,
'theme' => 0,
Expand Down
40 changes: 22 additions & 18 deletions Sources/Actions/Admin/Maintenance.php
Original file line number Diff line number Diff line change
Expand Up @@ -1455,9 +1455,12 @@ public function recountPosts(): void
'SELECT COUNT(DISTINCT m.id_member)
FROM {db_prefix}messages AS m
JOIN {db_prefix}boards AS b on m.id_board = b.id_board
WHERE m.id_member != 0
AND b.count_posts = 0',
WHERE m.id_member != {int:zero}
AND b.posts_count = {int:one}
AND m.approved = {int:one}',
[
'zero' => 0,
'one' => 1,
],
);

Expand All @@ -1474,7 +1477,8 @@ public function recountPosts(): void
FROM {db_prefix}messages AS m
INNER JOIN {db_prefix}boards AS b ON m.id_board = b.id_board
WHERE m.id_member != {int:zero}
AND b.count_posts = {int:zero}
AND b.posts_count = {int:one}
AND m.approved = {int:one}
' . (!empty(Config::$modSettings['recycle_enable']) ? ' AND b.id_board != {int:recycle}' : '') . '
GROUP BY m.id_member
LIMIT {int:start}, {int:number}',
Expand All @@ -1483,6 +1487,7 @@ public function recountPosts(): void
'number' => $increment,
'recycle' => Config::$modSettings['recycle_board'],
'zero' => 0,
'one' => 1,
],
);
$total_rows = Db::$db->num_rows($request);
Expand All @@ -1492,11 +1497,8 @@ public function recountPosts(): void
Db::$db->query(
'UPDATE {db_prefix}members
SET posts = {int:posts}
WHERE id_member = {int:row}',
[
'row' => $row['id_member'],
'posts' => $row['posts'],
],
WHERE id_member = {int:id_member}',
$row,
);
}
Db::$db->free_result($request);
Expand All @@ -1517,27 +1519,29 @@ public function recountPosts(): void

// final steps ... made more difficult since we don't yet support sub-selects on joins
// place all members who have posts in the message table in a temp table
Db::$db->query('DROP TABLE IF EXISTS {db_prefix}tmp_maint_recountposts');

$createTemporary = Db::$db->query(
'CREATE TEMPORARY TABLE {db_prefix}tmp_maint_recountposts (
id_member mediumint(8) unsigned NOT NULL default {string:string_zero},
PRIMARY KEY (id_member)
)
'CREATE TEMPORARY TABLE {db_prefix}tmp_maint_recountposts AS
SELECT m.id_member
FROM {db_prefix}messages AS m
INNER JOIN {db_prefix}boards AS b ON m.id_board = b.id_board
WHERE m.id_member != {int:zero}
AND b.count_posts = {int:zero}
AND b.posts_count = {int:one}
AND m.approved = {int:one}
' . (!empty(Config::$modSettings['recycle_enable']) ? ' AND b.id_board != {int:recycle}' : '') . '
GROUP BY m.id_member',
[
'zero' => 0,
'string_zero' => '0',
'one' => 1,
'db_error_skip' => true,
'recycle' => !empty(Config::$modSettings['recycle_board']) ? Config::$modSettings['recycle_board'] : 0,
],
) !== false;

if ($createTemporary) {
Db::$db->add_index('{db_prefix}tmp_maint_recountposts', ['type' => 'primary', 'columns' => ['id_member']]);

// outer join the members table on the temporary table finding the members that have a post count but no posts in the message table
$request = Db::$db->query(
'SELECT mem.id_member, mem.posts
Expand All @@ -1556,9 +1560,9 @@ public function recountPosts(): void
Db::$db->query(
'UPDATE {db_prefix}members
SET posts = {int:zero}
WHERE id_member = {int:row}',
WHERE id_member = {int:id_member}',
[
'row' => $row['id_member'],
'id_member' => $row['id_member'],
'zero' => 0,
],
);
Expand Down Expand Up @@ -2077,14 +2081,14 @@ public static function reattributePosts(int $memID, ?string $email = null, ?stri
$request = Db::$db->query(
'SELECT COUNT(*)
FROM {db_prefix}messages AS m
INNER JOIN {db_prefix}boards AS b ON (b.id_board = m.id_board AND b.count_posts = {int:count_posts})
INNER JOIN {db_prefix}boards AS b ON (b.id_board = m.id_board AND b.posts_count = {int:posts_count})
WHERE m.id_member = {int:guest_id}
AND m.approved = {int:is_approved}' . (!empty($recycle_board) ? '
AND m.id_board != {int:recycled_board}' : '') . (empty($email) ? '' : '
AND m.poster_email = {string:email_address}') . (empty($membername) ? '' : '
AND m.poster_name = {string:member_name}'),
[
'count_posts' => 0,
'posts_count' => 1,
'guest_id' => 0,
'email_address' => $email,
'member_name' => $membername,
Expand Down
4 changes: 2 additions & 2 deletions Sources/Actions/Admin/Reports.php
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ public function boards(): void
'redirect' => Lang::getTxt('board_redirect', file: 'Reports'),
'num_topics' => Lang::getTxt('board_num_topics', file: 'Reports'),
'num_posts' => Lang::getTxt('board_num_posts', file: 'Reports'),
'count_posts' => Lang::getTxt('board_count_posts', file: 'Reports'),
'posts_count' => Lang::getTxt('board_count_posts', file: 'Reports'),
'theme' => Lang::getTxt('board_theme', file: 'Reports'),
'override_theme' => Lang::getTxt('board_override_theme', file: 'Reports'),
'profile' => Lang::getTxt('board_profile', file: 'Reports'),
Expand Down Expand Up @@ -302,7 +302,7 @@ public function boards(): void
'redirect' => $board->redirect,
'num_posts' => $board->posts,
'num_topics' => $board->topics,
'count_posts' => Lang::getTxt(empty($board->count_posts) ? 'yes' : 'no', file: 'General'),
'posts_count' => Lang::getTxt($board->posts_count ? 'yes' : 'no', file: 'General'),
'theme' => Utils::$context['themes'][$board->theme] ?? Lang::getTxt('none', file: 'General'),
'profile' => Utils::$context['profiles'][$board->profile]['name'],
'override_theme' => Lang::getTxt($board->override_theme ? 'yes' : 'no', file: 'General'),
Expand Down
4 changes: 2 additions & 2 deletions Sources/Actions/Profile/StatPanel.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,14 +112,14 @@ public function execute(): void
FROM {db_prefix}messages AS m
INNER JOIN {db_prefix}boards AS b ON (b.id_board = m.id_board)
WHERE m.id_member = {int:current_member}
AND b.count_posts = {int:count_enabled}
AND b.posts_count = {int:count_enabled}
AND {query_see_board}
GROUP BY b.id_board
ORDER BY message_count DESC
LIMIT 10',
[
'current_member' => Profile::$member->id,
'count_enabled' => 0,
'count_enabled' => 1,
],
);

Expand Down
24 changes: 12 additions & 12 deletions Sources/Actions/QuickModeration.php
Original file line number Diff line number Diff line change
Expand Up @@ -671,7 +671,7 @@ protected function doMove(): void
$countPosts = [];

$request = Db::$db->query(
'SELECT t.id_topic, t.id_board, b.count_posts
'SELECT t.id_topic, t.id_board, b.posts_count
FROM {db_prefix}topics AS t
LEFT JOIN {db_prefix}boards AS b ON (t.id_board = b.id_board)
WHERE t.id_topic IN ({array_int:move_topic_ids})' . (!empty(Board::$info->id) && !User::$me->allowedTo('move_any') ? '
Expand All @@ -692,7 +692,7 @@ protected function doMove(): void
}

// Does this topic's board count the posts or not?
$countPosts[(int) $row['id_topic']] = empty($row['count_posts']);
$countPosts[(int) $row['id_topic']] = !empty($row['posts_count']);

if (!isset($moveTos[$to])) {
$moveTos[$to] = [];
Expand All @@ -716,7 +716,7 @@ protected function doMove(): void
if (!empty($moveTos)) {
$topicRecounts = [];
$request = Db::$db->query(
'SELECT id_board, count_posts
'SELECT id_board, posts_count
FROM {db_prefix}boards
WHERE id_board IN ({array_int:move_boards})',
[
Expand All @@ -725,7 +725,7 @@ protected function doMove(): void
);

while ($row = Db::$db->fetch_assoc($request)) {
$cp = empty($row['count_posts']);
$cp = !empty($row['posts_count']);

// Go through all the topics that are being moved to this board.
foreach ($moveTos[(int) $row['id_board']] as $topic) {
Expand All @@ -740,7 +740,7 @@ protected function doMove(): void
Db::$db->free_result($request);

if (!empty($topicRecounts)) {
$members = [];
$adjustments = [];

// Get all the members who have posted in the moved topics.
$request = Db::$db->query(
Expand All @@ -754,22 +754,22 @@ protected function doMove(): void
);

while ($row = Db::$db->fetch_assoc($request)) {
if (!isset($members[$row['id_member']])) {
$members[(int) $row['id_member']] = 0;
if (!isset($adjustments[$row['id_member']])) {
$adjustments[(int) $row['id_member']] = 0;
}

if ($topicRecounts[(int) $row['id_topic']] === '+') {
$members[(int) $row['id_member']]++;
$adjustments[(int) $row['id_member']]++;
} else {
$members[(int) $row['id_member']]--;
$adjustments[(int) $row['id_member']]--;
}

$members[(int) $row['id_member']] = max(0, $members[(int) $row['id_member']]);
}
Db::$db->free_result($request);

// And now update the member's post counts.
foreach ($members as $id => $post_adj) {
$members = [];

foreach ($adjustments as $id => $post_adj) {
$members[$id] = current(User::load($id, dataset: UserDataset::Minimal));

if ($members[$id] instanceof User) {
Expand Down
21 changes: 5 additions & 16 deletions Sources/Actions/TopicMove2.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public function execute(): void

// Make sure they can see the board they are trying to move to (and get whether posts count in the target board).
$request = Db::$db->query(
'SELECT b.count_posts, b.name, m.subject
'SELECT b.posts_count, b.name, m.subject
FROM {db_prefix}boards AS b
INNER JOIN {db_prefix}topics AS t ON (t.id_topic = {int:current_topic})
INNER JOIN {db_prefix}messages AS m ON (m.id_msg = t.id_first_msg)
Expand Down Expand Up @@ -221,25 +221,14 @@ public function execute(): void

$posterOptions = [
'id' => User::$me->id,
'update_post_count' => empty($pcounter),
'update_post_count' => (bool) Board::$info->posts_count,
];

Msg::create($msgOptions, $topicOptions, $posterOptions);
}

$request = Db::$db->query(
'SELECT count_posts
FROM {db_prefix}boards
WHERE id_board = {int:current_board}
LIMIT 1',
[
'current_board' => Board::$info->id,
],
);
list($pcounter_from) = Db::$db->fetch_row($request);
Db::$db->free_result($request);

if ($pcounter_from != $pcounter) {
// If one of the boards counts posts and the other doesn't, we have more work to do.
if (Board::$info->posts_count != $pcounter) {
$posters = [];

$request = Db::$db->query(
Expand All @@ -259,7 +248,7 @@ public function execute(): void
}

// The board we're moving from counted posts, but not to.
if (empty($pcounter_from)) {
if (Board::$info->posts_count) {
$posters[$row['id_member']]--;
}
// The reverse: from didn't, to did.
Expand Down
16 changes: 8 additions & 8 deletions Sources/Actions/TopicRestore.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public function execute(): void
// Get the id_previous_board and id_previous_topic.
$request = Db::$db->query(
'SELECT m.id_topic, m.id_msg, m.id_board, m.subject, m.id_member, t.id_previous_board, t.id_previous_topic,
t.id_first_msg, b.count_posts, COALESCE(pt.id_board, 0) AS possible_prev_board
t.id_first_msg, b.posts_count, COALESCE(pt.id_board, 0) AS possible_prev_board
FROM {db_prefix}messages AS m
INNER JOIN {db_prefix}topics AS t ON (t.id_topic = m.id_topic)
INNER JOIN {db_prefix}boards AS b ON (b.id_board = m.id_board)
Expand Down Expand Up @@ -106,7 +106,7 @@ public function execute(): void
if (empty($actioned_messages[$row['id_previous_topic']])) {
$actioned_messages[$row['id_previous_topic']] = [
'msgs' => [],
'count_posts' => $row['count_posts'],
'posts_count' => $row['posts_count'],
'subject' => $row['subject'],
'previous_board' => $row['id_previous_board'],
'possible_prev_board' => $row['possible_prev_board'],
Expand Down Expand Up @@ -212,17 +212,17 @@ public function execute(): void

// Lets see if the board that we are returning to has post count enabled.
$request2 = Db::$db->query(
'SELECT count_posts
'SELECT posts_count
FROM {db_prefix}boards
WHERE id_board = {int:board}',
[
'board' => $row['id_previous_board'],
],
);
list($count_posts) = Db::$db->fetch_row($request2);
list($posts_count) = Db::$db->fetch_row($request2);
Db::$db->free_result($request2);

if (empty($count_posts)) {
if (!empty($posts_count)) {
$members = [];

// Lets get the members that need their post count restored.
Expand Down Expand Up @@ -313,19 +313,19 @@ protected static function mergePosts(array|int $msgs, int $from_topic, int $targ

// Get some target topic and board stats.
$request = Db::$db->query(
'SELECT t.id_board, t.id_first_msg, t.num_replies, t.unapproved_posts, b.count_posts
'SELECT t.id_board, t.id_first_msg, t.num_replies, t.unapproved_posts, b.posts_count
FROM {db_prefix}topics AS t
INNER JOIN {db_prefix}boards AS b ON (b.id_board = t.id_board)
WHERE t.id_topic = {int:target_topic}',
[
'target_topic' => $target_topic,
],
);
list($target_board, $target_first_msg, $target_replies, $target_unapproved_posts, $count_posts) = Db::$db->fetch_row($request);
list($target_board, $target_first_msg, $target_replies, $target_unapproved_posts, $posts_count) = Db::$db->fetch_row($request);
Db::$db->free_result($request);

// Lets see if the board that we are returning to has post count enabled.
if (empty($count_posts)) {
if (!empty($posts_count)) {
// Lets get the members that need their post count restored.
$members = User::loadCustom(
query_customizations: [
Expand Down
Loading