|
From: Ruslan U. <rx...@ph...> - 2009-08-10 12:07:45
|
Author: rxu
Date: Mon Aug 10 13:07:01 2009
New Revision: 9946
Log:
Fix bug #47705 - Out of range value for column 'topic_replies_real'
Authorised by: Kellanved
Modified:
branches/phpBB-3_0_0/phpBB/docs/CHANGELOG.html
branches/phpBB-3_0_0/phpBB/includes/mcp/mcp_queue.php
Modified: branches/phpBB-3_0_0/phpBB/docs/CHANGELOG.html
==============================================================================
*** branches/phpBB-3_0_0/phpBB/docs/CHANGELOG.html (original)
--- branches/phpBB-3_0_0/phpBB/docs/CHANGELOG.html Mon Aug 10 13:07:01 2009
***************
*** 168,173 ****
--- 168,174 ----
<li>[Fix] Allow changing forum from select box under certain circumstances. (Bug #37525)</li>
<li>[Fix] Display required fields notice on registration above the custom profile fields. (Bug #39665)</li>
<li>[Fix] Copy poll options properly when copying topic. (Bug #39065)</li>
+ <li>[Fix] Fix error with disapproval of topics having several queued posts only. (Bug #47705 - Patch by rxu)</li>
<li>[Fix] Preserve newlines in template files (one newline had been always dropped after a template variable due to PHP's handling of closing tags)</li>
<li>[Fix] Be less strict with FTP daemons when getting directory filelists. (Bug #46295)</li>
<li>[Fix] Fix set_custom_template for database-stored styles (Bug #40515 - Patch by nickvergessen)</li>
Modified: branches/phpBB-3_0_0/phpBB/includes/mcp/mcp_queue.php
==============================================================================
*** branches/phpBB-3_0_0/phpBB/includes/mcp/mcp_queue.php (original)
--- branches/phpBB-3_0_0/phpBB/includes/mcp/mcp_queue.php Mon Aug 10 13:07:01 2009
***************
*** 859,947 ****
if (confirm_box(true))
{
! // If Topic -> forum_topics_real -= 1
! // If Post -> topic_replies_real -= 1
!
! $num_disapproved = 0;
! $forum_topics_real = $topic_id_list = $forum_id_list = $topic_replies_real_sql = $post_disapprove_sql = $disapprove_log = array();
!
foreach ($post_info as $post_id => $post_data)
{
! $topic_id_list[$post_data['topic_id']] = 1;
!
! if ($post_data['forum_id'])
{
! $forum_id_list[$post_data['forum_id']] = 1;
}
! // Topic or Post. ;)
! /**
! * @todo this probably is a different method than the one used by delete_posts, does this cause counter inconsistency?
! */
! if ($post_data['topic_first_post_id'] == $post_id && $post_data['topic_last_post_id'] == $post_id)
{
! if ($post_data['forum_id'])
{
! if (!isset($forum_topics_real[$post_data['forum_id']]))
! {
! $forum_topics_real[$post_data['forum_id']] = 0;
! }
! $forum_topics_real[$post_data['forum_id']]++;
! $num_disapproved++;
}
-
- $disapprove_log[] = array(
- 'type' => 'topic',
- 'post_subject' => $post_data['post_subject'],
- 'forum_id' => $post_data['forum_id'],
- 'topic_id' => 0, // useless to log a topic id, as it will be deleted
- );
}
else
{
! if (!isset($topic_replies_real_sql[$post_data['topic_id']]))
! {
! $topic_replies_real_sql[$post_data['topic_id']] = 0;
! }
! $topic_replies_real_sql[$post_data['topic_id']]++;
!
! $disapprove_log[] = array(
'type' => 'post',
! 'post_subject' => $post_data['post_subject'],
! 'forum_id' => $post_data['forum_id'],
! 'topic_id' => $post_data['topic_id'],
! );
! }
! $post_disapprove_sql[] = $post_id;
}
! unset($post_data);
! if (sizeof($forum_topics_real))
! {
! foreach ($forum_topics_real as $forum_id => $topics_real)
! {
! $sql = 'UPDATE ' . FORUMS_TABLE . "
! SET forum_topics_real = forum_topics_real - $topics_real
! WHERE forum_id = $forum_id";
! $db->sql_query($sql);
! }
! }
! if (sizeof($topic_replies_real_sql))
! {
! foreach ($topic_replies_real_sql as $topic_id => $num_replies)
! {
! $sql = 'UPDATE ' . TOPICS_TABLE . "
! SET topic_replies_real = topic_replies_real - $num_replies
! WHERE topic_id = $topic_id";
! $db->sql_query($sql);
! }
! }
! if (sizeof($post_disapprove_sql))
{
if (!function_exists('delete_posts'))
{
--- 859,921 ----
if (confirm_box(true))
{
+ $disapprove_log = $disapprove_log_topics = $disapprove_log_posts = array();
+ $topic_replies_real = $post_disapprove_list = array();
! // Build a list of posts to be unapproved and get the related topics real replies count
foreach ($post_info as $post_id => $post_data)
{
! $post_disapprove_list[$post_id] = $post_data['topic_id'];
! if (!isset($topic_replies_real[$post_data['topic_id']]))
{
! $topic_replies_real[$post_data['topic_id']] = $post_data['topic_replies_real'];
}
+ }
! // Now we build the log array
! foreach ($post_disapprove_list as $post_id => $topic_id)
! {
! // If the count of disapproved posts for the topic is greater
! // than topic's real replies count, the whole topic is disapproved/deleted
! if (sizeof(array_keys($post_disapprove_list, $topic_id)) > $topic_replies_real[$topic_id])
{
! // Don't write the log more than once for every topic
! if (!isset($disapprove_log_topics[$topic_id]))
{
! // Build disapproved topics log
! $disapprove_log_topics[$topic_id] = array(
! 'type' => 'topic',
! 'post_subject' => $post_info[$post_id]['topic_title'],
! 'forum_id' => $post_info[$post_id]['forum_id'],
! 'topic_id' => 0, // useless to log a topic id, as it will be deleted
! );
}
}
else
{
! // Build disapproved posts log
! $disapprove_log_posts[] = array(
'type' => 'post',
! 'post_subject' => $post_info[$post_id]['post_subject'],
! 'forum_id' => $post_info[$post_id]['forum_id'],
! 'topic_id' => $post_info[$post_id]['topic_id'],
! );
! }
}
! // Get disapproved posts/topics counts separately
! $num_disapproved_topics = sizeof($disapprove_log_topics);
! $num_disapproved_posts = sizeof($disapprove_log_posts);
! // Build the whole log
! $disapprove_log = array_merge($disapprove_log_topics, $disapprove_log_posts);
! // Unset unneeded arrays
! unset($post_data, $disapprove_log_topics, $disapprove_log_posts);
! // Let's do the job - delete disapproved posts
! if (sizeof($post_disapprove_list))
{
if (!function_exists('delete_posts'))
{
***************
*** 949,970 ****
}
// We do not check for permissions here, because the moderator allowed approval/disapproval should be allowed to delete the disapproved posts
! delete_posts('post_id', $post_disapprove_sql);
foreach ($disapprove_log as $log_data)
{
add_log('mod', $log_data['forum_id'], $log_data['topic_id'], ($log_data['type'] == 'topic') ? 'LOG_TOPIC_DISAPPROVED' : 'LOG_POST_DISAPPROVED', $log_data['post_subject'], $disapprove_reason);
}
}
- unset($post_disapprove_sql, $topic_replies_real_sql);
-
- update_post_information('topic', array_keys($topic_id_list));
-
- if (sizeof($forum_id_list))
- {
- update_post_information('forum', array_keys($forum_id_list));
- }
- unset($topic_id_list, $forum_id_list);
$messenger = new messenger();
--- 923,937 ----
}
// We do not check for permissions here, because the moderator allowed approval/disapproval should be allowed to delete the disapproved posts
! // Note: function delete_posts triggers related forums/topics sync,
! // so we don't need to call update_post_information later and to adjust real topic replies or forum topics count manually
! delete_posts('post_id', array_keys($post_disapprove_list));
foreach ($disapprove_log as $log_data)
{
add_log('mod', $log_data['forum_id'], $log_data['topic_id'], ($log_data['type'] == 'topic') ? 'LOG_TOPIC_DISAPPROVED' : 'LOG_POST_DISAPPROVED', $log_data['post_subject'], $disapprove_reason);
}
}
$messenger = new messenger();
***************
*** 1032,1044 ****
$messenger->save_queue();
! if (sizeof($forum_topics_real))
{
! $success_msg = ($num_disapproved == 1) ? 'TOPIC_DISAPPROVED_SUCCESS' : 'TOPICS_DISAPPROVED_SUCCESS';
}
else
{
! $success_msg = (sizeof($post_id_list) == 1) ? 'POST_DISAPPROVED_SUCCESS' : 'POSTS_DISAPPROVED_SUCCESS';
}
}
else
--- 999,1011 ----
$messenger->save_queue();
! if ($num_disapproved_topics)
{
! $success_msg = ($num_disapproved_topics == 1) ? 'TOPIC_DISAPPROVED_SUCCESS' : 'TOPICS_DISAPPROVED_SUCCESS';
}
else
{
! $success_msg = ($num_disapproved_posts == 1) ? 'POST_DISAPPROVED_SUCCESS' : 'POSTS_DISAPPROVED_SUCCESS';
}
}
else
|