Merge branch 'develop-olympus' into develop

* develop-olympus:
  [ticket/9874] view_log() performs unneeded count query over all log entries.
  [ticket/7834] Topic time didn't update when first post was deleted
  [ticket/9997] Fixed an inconsistency in the Moderator Control Panel
  [ticket/9872] Removed some useless code that broke delete_posts
This commit is contained in:
Oleg Pudeyev 2011-02-24 20:59:19 -05:00
commit ee0db1a1d5
7 changed files with 22 additions and 56 deletions

View file

@ -529,7 +529,7 @@ class acp_main
); );
$log_data = array(); $log_data = array();
$log_count = 0; $log_count = false;
if ($auth->acl_get('a_viewlogs')) if ($auth->acl_get('a_viewlogs'))
{ {

View file

@ -2506,6 +2506,7 @@ function cache_moderators()
/** /**
* View log * View log
* If $log_count is set to false, we will skip counting all entries in the database.
*/ */
function view_log($mode, &$log, &$log_count, $limit = 0, $offset = 0, $forum_id = 0, $topic_id = 0, $user_id = 0, $limit_days = 0, $sort_by = 'l.log_time DESC', $keywords = '') function view_log($mode, &$log, &$log_count, $limit = 0, $offset = 0, $forum_id = 0, $topic_id = 0, $user_id = 0, $limit_days = 0, $sort_by = 'l.log_time DESC', $keywords = '')
{ {
@ -2761,16 +2762,19 @@ function view_log($mode, &$log, &$log_count, $limit = 0, $offset = 0, $forum_id
} }
} }
$sql = 'SELECT COUNT(l.log_id) AS total_entries if ($log_count !== false)
FROM ' . LOG_TABLE . ' l, ' . USERS_TABLE . " u {
WHERE l.log_type = $log_type $sql = 'SELECT COUNT(l.log_id) AS total_entries
AND l.user_id = u.user_id FROM ' . LOG_TABLE . ' l, ' . USERS_TABLE . " u
AND l.log_time >= $limit_days WHERE l.log_type = $log_type
$sql_keywords AND l.user_id = u.user_id
$sql_forum"; AND l.log_time >= $limit_days
$result = $db->sql_query($sql); $sql_keywords
$log_count = (int) $db->sql_fetchfield('total_entries'); $sql_forum";
$db->sql_freeresult($result); $result = $db->sql_query($sql);
$log_count = (int) $db->sql_fetchfield('total_entries');
$db->sql_freeresult($result);
}
return; return;
} }

View file

@ -1480,7 +1480,7 @@ function delete_post($forum_id, $topic_id, $post_id, &$data)
break; break;
case 'delete_first_post': case 'delete_first_post':
$sql = 'SELECT p.post_id, p.poster_id, p.post_username, u.username, u.user_colour $sql = 'SELECT p.post_id, p.poster_id, p.post_time, p.post_username, u.username, u.user_colour
FROM ' . POSTS_TABLE . ' p, ' . USERS_TABLE . " u FROM ' . POSTS_TABLE . ' p, ' . USERS_TABLE . " u
WHERE p.topic_id = $topic_id WHERE p.topic_id = $topic_id
AND p.poster_id = u.user_id AND p.poster_id = u.user_id
@ -1494,7 +1494,7 @@ function delete_post($forum_id, $topic_id, $post_id, &$data)
$sql_data[FORUMS_TABLE] = ($data['post_approved']) ? 'forum_posts = forum_posts - 1' : ''; $sql_data[FORUMS_TABLE] = ($data['post_approved']) ? 'forum_posts = forum_posts - 1' : '';
} }
$sql_data[TOPICS_TABLE] = 'topic_poster = ' . intval($row['poster_id']) . ', topic_first_post_id = ' . intval($row['post_id']) . ", topic_first_poster_colour = '" . $db->sql_escape($row['user_colour']) . "', topic_first_poster_name = '" . (($row['poster_id'] == ANONYMOUS) ? $db->sql_escape($row['post_username']) : $db->sql_escape($row['username'])) . "'"; $sql_data[TOPICS_TABLE] = 'topic_poster = ' . intval($row['poster_id']) . ', topic_first_post_id = ' . intval($row['post_id']) . ", topic_first_poster_colour = '" . $db->sql_escape($row['user_colour']) . "', topic_first_poster_name = '" . (($row['poster_id'] == ANONYMOUS) ? $db->sql_escape($row['post_username']) : $db->sql_escape($row['username'])) . "', topic_time = " . (int) $row['post_time'];
// Decrementing topic_replies here is fine because this case only happens if there is more than one post within the topic - basically removing one "reply" // Decrementing topic_replies here is fine because this case only happens if there is more than one post within the topic - basically removing one "reply"
$sql_data[TOPICS_TABLE] .= ', topic_replies_real = topic_replies_real - 1' . (($data['post_approved']) ? ', topic_replies = topic_replies - 1' : ''); $sql_data[TOPICS_TABLE] .= ', topic_replies_real = topic_replies_real - 1' . (($data['post_approved']) ? ', topic_replies = topic_replies - 1' : '');

View file

@ -482,44 +482,6 @@ function user_delete($mode, $user_id, $post_username = false)
include($phpbb_root_path . 'includes/functions_admin.' . $phpEx); include($phpbb_root_path . 'includes/functions_admin.' . $phpEx);
} }
$sql = 'SELECT topic_id, COUNT(post_id) AS total_posts
FROM ' . POSTS_TABLE . "
WHERE poster_id = $user_id
GROUP BY topic_id";
$result = $db->sql_query($sql);
$topic_id_ary = array();
while ($row = $db->sql_fetchrow($result))
{
$topic_id_ary[$row['topic_id']] = $row['total_posts'];
}
$db->sql_freeresult($result);
if (sizeof($topic_id_ary))
{
$sql = 'SELECT topic_id, topic_replies, topic_replies_real
FROM ' . TOPICS_TABLE . '
WHERE ' . $db->sql_in_set('topic_id', array_keys($topic_id_ary));
$result = $db->sql_query($sql);
$del_topic_ary = array();
while ($row = $db->sql_fetchrow($result))
{
if (max($row['topic_replies'], $row['topic_replies_real']) + 1 == $topic_id_ary[$row['topic_id']])
{
$del_topic_ary[] = $row['topic_id'];
}
}
$db->sql_freeresult($result);
if (sizeof($del_topic_ary))
{
$sql = 'DELETE FROM ' . TOPICS_TABLE . '
WHERE ' . $db->sql_in_set('topic_id', $del_topic_ary);
$db->sql_query($sql);
}
}
// Delete posts, attachments, etc. // Delete posts, attachments, etc.
delete_posts('poster_id', $user_id); delete_posts('poster_id', $user_id);

View file

@ -350,7 +350,7 @@ function mcp_front_view($id, $mode, $action)
// Add forum_id 0 for global announcements // Add forum_id 0 for global announcements
$forum_list[] = 0; $forum_list[] = 0;
$log_count = 0; $log_count = false;
$log = array(); $log = array();
view_log('mod', $log, $log_count, 5, 0, $forum_list); view_log('mod', $log, $log_count, 5, 0, $forum_list);

View file

@ -227,10 +227,10 @@ function mcp_post_details($id, $mode, $action)
// Get User Notes // Get User Notes
$log_data = array(); $log_data = array();
$log_count = 0; $log_count = false;
view_log('user', $log_data, $log_count, $config['posts_per_page'], 0, 0, 0, $post_info['user_id']); view_log('user', $log_data, $log_count, $config['posts_per_page'], 0, 0, 0, $post_info['user_id']);
if ($log_count) if (!empty($log_data))
{ {
$template->assign_var('S_USER_NOTES', true); $template->assign_var('S_USER_NOTES', true);

View file

@ -72,8 +72,8 @@
<form method="post" id="mcp_approve" action="{U_APPROVE_ACTION}"> <form method="post" id="mcp_approve" action="{U_APPROVE_ACTION}">
<p class="rules"> <p class="rules">
<input class="button1" type="submit" value="{L_APPROVE}" name="action[approve]" /> &nbsp; <input class="button2" type="submit" value="{L_DISAPPROVE}" name="action[disapprove]" /> &nbsp;
<input class="button2" type="submit" value="{L_DISAPPROVE}" name="action[disapprove]" /> <input class="button1" type="submit" value="{L_APPROVE}" name="action[approve]" />
<input type="hidden" name="post_id_list[]" value="{POST_ID}" /> <input type="hidden" name="post_id_list[]" value="{POST_ID}" />
{S_FORM_TOKEN} {S_FORM_TOKEN}
</p> </p>