[feature/soft-delete] Fix sync() and some more functions to use the new fields

PHPBB3-9567
This commit is contained in:
Joas Schilling 2012-10-22 14:21:44 +02:00
parent 9945561b4b
commit 168dd29f24
5 changed files with 61 additions and 30 deletions

View file

@ -552,9 +552,12 @@ function get_schema_struct()
'forum_topics_per_page' => array('TINT:4', 0), 'forum_topics_per_page' => array('TINT:4', 0),
'forum_type' => array('TINT:4', 0), 'forum_type' => array('TINT:4', 0),
'forum_status' => array('TINT:4', 0), 'forum_status' => array('TINT:4', 0),
'forum_posts' => array('UINT', 0), 'forum_posts' => array('UINT', 0),
'forum_topics' => array('UINT', 0), 'forum_posts_unapproved' => array('UINT', 0),
'forum_topics_real' => array('UINT', 0), 'forum_posts_softdeleted' => array('UINT', 0),
'forum_topics' => array('UINT', 0),
'forum_topics_unapproved' => array('UINT', 0),
'forum_topics_softdeleted' => array('UINT', 0),
'forum_last_post_id' => array('UINT', 0), 'forum_last_post_id' => array('UINT', 0),
'forum_last_poster_id' => array('UINT', 0), 'forum_last_poster_id' => array('UINT', 0),
'forum_last_post_subject' => array('STEXT_UNI', ''), 'forum_last_post_subject' => array('STEXT_UNI', ''),
@ -1114,8 +1117,9 @@ function get_schema_struct()
'topic_time' => array('TIMESTAMP', 0), 'topic_time' => array('TIMESTAMP', 0),
'topic_time_limit' => array('TIMESTAMP', 0), 'topic_time_limit' => array('TIMESTAMP', 0),
'topic_views' => array('UINT', 0), 'topic_views' => array('UINT', 0),
'topic_replies' => array('UINT', 0), 'topic_posts' => array('UINT', 0),
'topic_replies_real' => array('UINT', 0), 'topic_posts_unapproved' => array('UINT', 0),
'topic_posts_softdeleted' => array('UINT', 0),
'topic_status' => array('TINT:3', 0), 'topic_status' => array('TINT:3', 0),
'topic_type' => array('TINT:3', 0), 'topic_type' => array('TINT:3', 0),
'topic_first_post_id' => array('UINT', 0), 'topic_first_post_id' => array('UINT', 0),

View file

@ -726,7 +726,7 @@ class phpbb_feed_topic_base extends phpbb_feed_base
. ' ' . $this->separator_stats . ' ' . $user->format_date($row[$this->get('published')]) . ' ' . $this->separator_stats . ' ' . $user->format_date($row[$this->get('published')])
. ' ' . $this->separator_stats . ' ' . $user->lang['REPLIES'] . ' ' . phpbb_content_visibility::get_count('topic_posts', $row, $row['forum_id']) - 1 . ' ' . $this->separator_stats . ' ' . $user->lang['REPLIES'] . ' ' . phpbb_content_visibility::get_count('topic_posts', $row, $row['forum_id']) - 1
. ' ' . $this->separator_stats . ' ' . $user->lang['VIEWS'] . ' ' . $row['topic_views'] . ' ' . $this->separator_stats . ' ' . $user->lang['VIEWS'] . ' ' . $row['topic_views']
. (($this->is_moderator_approve_forum($row['forum_id']) && ($row['topic_replies_real'] != $row['topic_replies'])) ? ' ' . $this->separator_stats . ' ' . $user->lang['POSTS_UNAPPROVED'] : ''); . (($this->is_moderator_approve_forum($row['forum_id']) && $row['topic_posts_unapproved']) ? ' ' . $this->separator_stats . ' ' . $user->lang['POSTS_UNAPPROVED'] : '');
} }
} }
} }
@ -1179,7 +1179,7 @@ class phpbb_feed_news extends phpbb_feed_topic_base
$this->sql = array( $this->sql = array(
'SELECT' => 'f.forum_id, f.forum_name, 'SELECT' => 'f.forum_id, f.forum_name,
t.topic_id, t.topic_title, t.topic_poster, t.topic_first_poster_name, t.topic_replies, t.topic_replies_real, t.topic_views, t.topic_time, t.topic_last_post_time, t.topic_id, t.topic_title, t.topic_poster, t.topic_first_poster_name, t.topic_posts, t.topic_posts_unapproved, t.topic_posts_softdeleted, t.topic_views, t.topic_time, t.topic_last_post_time,
p.post_id, p.post_time, p.post_edit_time, p.post_text, p.bbcode_bitfield, p.bbcode_uid, p.enable_bbcode, p.enable_smilies, p.enable_magic_url', p.post_id, p.post_time, p.post_edit_time, p.post_text, p.bbcode_bitfield, p.bbcode_uid, p.enable_bbcode, p.enable_smilies, p.enable_magic_url',
'FROM' => array( 'FROM' => array(
TOPICS_TABLE => 't', TOPICS_TABLE => 't',
@ -1249,7 +1249,7 @@ class phpbb_feed_topics extends phpbb_feed_topic_base
$this->sql = array( $this->sql = array(
'SELECT' => 'f.forum_id, f.forum_name, 'SELECT' => 'f.forum_id, f.forum_name,
t.topic_id, t.topic_title, t.topic_poster, t.topic_first_poster_name, t.topic_replies, t.topic_replies_real, t.topic_views, t.topic_time, t.topic_last_post_time, t.topic_id, t.topic_title, t.topic_poster, t.topic_first_poster_name, t.topic_posts, t.topic_posts_unapproved, t.topic_posts_softdeleted, t.topic_views, t.topic_time, t.topic_last_post_time,
p.post_id, p.post_time, p.post_edit_time, p.post_text, p.bbcode_bitfield, p.bbcode_uid, p.enable_bbcode, p.enable_smilies, p.enable_magic_url', p.post_id, p.post_time, p.post_edit_time, p.post_text, p.bbcode_bitfield, p.bbcode_uid, p.enable_bbcode, p.enable_smilies, p.enable_magic_url',
'FROM' => array( 'FROM' => array(
TOPICS_TABLE => 't', TOPICS_TABLE => 't',
@ -1342,7 +1342,7 @@ class phpbb_feed_topics_active extends phpbb_feed_topic_base
$this->sql = array( $this->sql = array(
'SELECT' => 'f.forum_id, f.forum_name, 'SELECT' => 'f.forum_id, f.forum_name,
t.topic_id, t.topic_title, t.topic_replies, t.topic_replies_real, t.topic_views, t.topic_id, t.topic_title, t.topic_posts, t.topic_posts_unapproved, t.topic_posts_softdeleted, t.topic_views,
t.topic_last_poster_id, t.topic_last_poster_name, t.topic_last_post_time, t.topic_last_poster_id, t.topic_last_poster_name, t.topic_last_post_time,
p.post_id, p.post_time, p.post_edit_time, p.post_text, p.bbcode_bitfield, p.bbcode_uid, p.enable_bbcode, p.enable_smilies, p.enable_magic_url', p.post_id, p.post_time, p.post_edit_time, p.post_text, p.bbcode_bitfield, p.bbcode_uid, p.enable_bbcode, p.enable_smilies, p.enable_magic_url',
'FROM' => array( 'FROM' => array(

View file

@ -621,29 +621,31 @@ class acp_users
$topic_id_ary = $move_topic_ary = $move_post_ary = $new_topic_id_ary = array(); $topic_id_ary = $move_topic_ary = $move_post_ary = $new_topic_id_ary = array();
$forum_id_ary = array($new_forum_id); $forum_id_ary = array($new_forum_id);
$sql = 'SELECT topic_id, COUNT(post_id) AS total_posts $sql = 'SELECT topic_id, post_visibility, COUNT(post_id) AS total_posts
FROM ' . POSTS_TABLE . " FROM ' . POSTS_TABLE . "
WHERE poster_id = $user_id WHERE poster_id = $user_id
AND forum_id <> $new_forum_id AND forum_id <> $new_forum_id
GROUP BY topic_id"; GROUP BY topic_id, post_visibility";
$result = $db->sql_query($sql); $result = $db->sql_query($sql);
while ($row = $db->sql_fetchrow($result)) while ($row = $db->sql_fetchrow($result))
{ {
$topic_id_ary[$row['topic_id']] = $row['total_posts']; $topic_id_ary[$row['topic_id']][$row['post_visibility']] = $row['total_posts'];
} }
$db->sql_freeresult($result); $db->sql_freeresult($result);
if (sizeof($topic_id_ary)) if (sizeof($topic_id_ary))
{ {
$sql = 'SELECT topic_id, forum_id, topic_title, topic_replies, topic_replies_real, topic_attachment $sql = 'SELECT topic_id, forum_id, topic_title, topic_posts, topic_posts_unapproved, topic_posts_softdeleted, topic_attachment
FROM ' . TOPICS_TABLE . ' FROM ' . TOPICS_TABLE . '
WHERE ' . $db->sql_in_set('topic_id', array_keys($topic_id_ary)); WHERE ' . $db->sql_in_set('topic_id', array_keys($topic_id_ary));
$result = $db->sql_query($sql); $result = $db->sql_query($sql);
while ($row = $db->sql_fetchrow($result)) while ($row = $db->sql_fetchrow($result))
{ {
if (max($row['topic_replies'], $row['topic_replies_real']) + 1 == $topic_id_ary[$row['topic_id']]) if ($topic_id_ary[$row['topic_id']][ITEM_APPROVED] == $row['topic_posts']
&& $topic_id_ary[$row['topic_id']][ITEM_UNAPPROVED] == $row['topic_posts_unapproved']
&& $topic_id_ary[$row['topic_id']][ITEM_DELETED] == $row['topic_posts_softdeleted'])
{ {
$move_topic_ary[] = $row['topic_id']; $move_topic_ary[] = $row['topic_id'];
} }

View file

@ -523,7 +523,7 @@ class phpbb_content_visibility
// Do we need to grab some topic informations? // Do we need to grab some topic informations?
if (!sizeof($topic_row)) if (!sizeof($topic_row))
{ {
$sql = 'SELECT topic_type, topic_replies, topic_replies_real, topic_visibility $sql = 'SELECT topic_type, topic_posts, topic_posts_unapproved, topic_posts_softdeleted, topic_visibility
FROM ' . TOPICS_TABLE . ' FROM ' . TOPICS_TABLE . '
WHERE topic_id = ' . $topic_id; WHERE topic_id = ' . $topic_id;
$result = $db->sql_query($sql); $result = $db->sql_query($sql);
@ -533,10 +533,12 @@ class phpbb_content_visibility
// If this is an edited topic or the first post the topic gets completely disapproved later on... // If this is an edited topic or the first post the topic gets completely disapproved later on...
$sql_data[FORUMS_TABLE] = (($sql_data[FORUMS_TABLE]) ? $sql_data[FORUMS_TABLE] . ', ' : '') . 'forum_topics = forum_topics - 1'; $sql_data[FORUMS_TABLE] = (($sql_data[FORUMS_TABLE]) ? $sql_data[FORUMS_TABLE] . ', ' : '') . 'forum_topics = forum_topics - 1';
$sql_data[FORUMS_TABLE] .= ', forum_posts = forum_posts - ' . ($topic_row['topic_replies'] + 1); $sql_data[FORUMS_TABLE] .= ', forum_posts = forum_posts - ' . $topic_row['topic_posts'];
$sql_data[FORUMS_TABLE] .= ', forum_posts_unapproved = forum_posts_unapproved - ' . $topic_row['topic_posts_unapproved'];
$sql_data[FORUMS_TABLE] .= ', forum_posts_softdeleted = forum_posts_softdeleted - ' . $topic_row['topic_posts_softdeleted'];
set_config_count('num_topics', -1, true); set_config_count('num_topics', -1, true);
set_config_count('num_posts', ($topic_row['topic_replies'] + 1) * (-1), true); set_config_count('num_posts', $topic_row['topic_posts'] * (-1), true);
// Get user post count information // Get user post count information
$sql = 'SELECT poster_id, COUNT(post_id) AS num_posts $sql = 'SELECT poster_id, COUNT(post_id) AS num_posts

View file

@ -1670,8 +1670,11 @@ function sync($mode, $where_type = '', $where_ids = '', $resync_parents = false,
if ($sync_extra) if ($sync_extra)
{ {
$forum_data[$forum_id]['posts'] = 0; $forum_data[$forum_id]['posts'] = 0;
$forum_data[$forum_id]['posts_unapproved'] = 0;
$forum_data[$forum_id]['posts_softdeleted'] = 0;
$forum_data[$forum_id]['topics'] = 0; $forum_data[$forum_id]['topics'] = 0;
$forum_data[$forum_id]['topics_real'] = 0; $forum_data[$forum_id]['topics_unapproved'] = 0;
$forum_data[$forum_id]['topics_softdeleted'] = 0;
} }
$forum_data[$forum_id]['last_post_id'] = 0; $forum_data[$forum_id]['last_post_id'] = 0;
$forum_data[$forum_id]['last_post_subject'] = ''; $forum_data[$forum_id]['last_post_subject'] = '';
@ -1692,7 +1695,7 @@ function sync($mode, $where_type = '', $where_ids = '', $resync_parents = false,
// 2: Get topic counts for each forum (optional) // 2: Get topic counts for each forum (optional)
if ($sync_extra) if ($sync_extra)
{ {
$sql = 'SELECT forum_id, topic_visibility, COUNT(topic_id) AS forum_topics $sql = 'SELECT forum_id, topic_visibility, COUNT(topic_id) AS total_topics
FROM ' . TOPICS_TABLE . ' FROM ' . TOPICS_TABLE . '
WHERE ' . $db->sql_in_set('forum_id', $forum_ids) . ' WHERE ' . $db->sql_in_set('forum_id', $forum_ids) . '
GROUP BY forum_id, topic_visibility'; GROUP BY forum_id, topic_visibility';
@ -1701,11 +1704,18 @@ function sync($mode, $where_type = '', $where_ids = '', $resync_parents = false,
while ($row = $db->sql_fetchrow($result)) while ($row = $db->sql_fetchrow($result))
{ {
$forum_id = (int) $row['forum_id']; $forum_id = (int) $row['forum_id'];
$forum_data[$forum_id]['topics_real'] += $row['forum_topics'];
if ($row['topic_visibility'] == ITEM_APPROVED) if ($row['topic_visibility'] == ITEM_APPROVED)
{ {
$forum_data[$forum_id]['topics'] = $row['forum_topics']; $forum_data[$forum_id]['topics'] = $row['total_topics'];
}
else if ($row['topic_visibility'] == ITEM_UNAPPROVED)
{
$forum_data[$forum_id]['topics_unapproved'] = $row['total_topics'];
}
else if ($row['topic_visibility'] == ITEM_DELETED)
{
$forum_data[$forum_id]['topics_softdeleted'] = $row['total_topics'];
} }
} }
$db->sql_freeresult($result); $db->sql_freeresult($result);
@ -1716,7 +1726,7 @@ function sync($mode, $where_type = '', $where_ids = '', $resync_parents = false,
{ {
if (sizeof($forum_ids) == 1) if (sizeof($forum_ids) == 1)
{ {
$sql = 'SELECT SUM(t.topic_replies + 1) AS forum_posts $sql = 'SELECT SUM(t.topic_posts) AS forum_posts, SUM(t.topic_posts_unapproved) AS forum_posts_unapproved, SUM(t.topic_posts_softdeleted) AS forum_posts_softdeleted
FROM ' . TOPICS_TABLE . ' t FROM ' . TOPICS_TABLE . ' t
WHERE ' . $db->sql_in_set('t.forum_id', $forum_ids) . ' WHERE ' . $db->sql_in_set('t.forum_id', $forum_ids) . '
AND t.topic_visibility = ' . ITEM_APPROVED . ' AND t.topic_visibility = ' . ITEM_APPROVED . '
@ -1724,7 +1734,7 @@ function sync($mode, $where_type = '', $where_ids = '', $resync_parents = false,
} }
else else
{ {
$sql = 'SELECT t.forum_id, SUM(t.topic_replies + 1) AS forum_posts $sql = 'SELECT t.forum_id, SUM(t.topic_posts) AS forum_posts, SUM(t.topic_posts_unapproved) AS forum_posts_unapproved, SUM(t.topic_posts_softdeleted) AS forum_posts_softdeleted
FROM ' . TOPICS_TABLE . ' t FROM ' . TOPICS_TABLE . ' t
WHERE ' . $db->sql_in_set('t.forum_id', $forum_ids) . ' WHERE ' . $db->sql_in_set('t.forum_id', $forum_ids) . '
AND t.topic_visibility = ' . ITEM_APPROVED . ' AND t.topic_visibility = ' . ITEM_APPROVED . '
@ -1739,6 +1749,8 @@ function sync($mode, $where_type = '', $where_ids = '', $resync_parents = false,
$forum_id = (sizeof($forum_ids) == 1) ? (int) $forum_ids[0] : (int) $row['forum_id']; $forum_id = (sizeof($forum_ids) == 1) ? (int) $forum_ids[0] : (int) $row['forum_id'];
$forum_data[$forum_id]['posts'] = (int) $row['forum_posts']; $forum_data[$forum_id]['posts'] = (int) $row['forum_posts'];
$forum_data[$forum_id]['posts_unapproved'] = (int) $row['forum_posts_unapproved'];
$forum_data[$forum_id]['posts_softdeleted'] = (int) $row['forum_posts_softdeleted'];
} }
$db->sql_freeresult($result); $db->sql_freeresult($result);
} }
@ -1819,7 +1831,7 @@ function sync($mode, $where_type = '', $where_ids = '', $resync_parents = false,
if ($sync_extra) if ($sync_extra)
{ {
array_push($fieldnames, 'posts', 'topics', 'topics_real'); array_push($fieldnames, 'posts', 'posts_unapproved', 'posts_softdeleted', 'topics', 'topics_unapproved', 'topics_softdeleted');
} }
foreach ($forum_data as $forum_id => $row) foreach ($forum_data as $forum_id => $row)
@ -1858,7 +1870,7 @@ function sync($mode, $where_type = '', $where_ids = '', $resync_parents = false,
$db->sql_transaction('begin'); $db->sql_transaction('begin');
$sql = 'SELECT t.topic_id, t.forum_id, t.topic_moved_id, t.topic_visibility, ' . (($sync_extra) ? 't.topic_attachment, t.topic_reported, ' : '') . 't.topic_poster, t.topic_time, t.topic_replies, t.topic_replies_real, t.topic_first_post_id, t.topic_first_poster_name, t.topic_first_poster_colour, t.topic_last_post_id, t.topic_last_post_subject, t.topic_last_poster_id, t.topic_last_poster_name, t.topic_last_poster_colour, t.topic_last_post_time $sql = 'SELECT t.topic_id, t.forum_id, t.topic_moved_id, t.topic_visibility, ' . (($sync_extra) ? 't.topic_attachment, t.topic_reported, ' : '') . 't.topic_poster, t.topic_time, t.topic_posts, t.topic_posts_unapproved, t.topic_posts_softdeleted, t.topic_first_post_id, t.topic_first_poster_name, t.topic_first_poster_colour, t.topic_last_post_id, t.topic_last_post_subject, t.topic_last_poster_id, t.topic_last_poster_name, t.topic_last_poster_colour, t.topic_last_post_time
FROM ' . TOPICS_TABLE . " t FROM ' . TOPICS_TABLE . " t
$where_sql"; $where_sql";
$result = $db->sql_query($sql); $result = $db->sql_query($sql);
@ -1874,8 +1886,9 @@ function sync($mode, $where_type = '', $where_ids = '', $resync_parents = false,
$topic_id = (int) $row['topic_id']; $topic_id = (int) $row['topic_id'];
$topic_data[$topic_id] = $row; $topic_data[$topic_id] = $row;
$topic_data[$topic_id]['visibility'] = ITEM_UNAPPROVED; $topic_data[$topic_id]['visibility'] = ITEM_UNAPPROVED;
$topic_data[$topic_id]['replies_real'] = -1; $topic_data[$topic_id]['posts'] = 0;
$topic_data[$topic_id]['replies'] = 0; $topic_data[$topic_id]['posts_unapproved'] = 0;
$topic_data[$topic_id]['posts_softdeleted'] = 0;
$topic_data[$topic_id]['first_post_id'] = 0; $topic_data[$topic_id]['first_post_id'] = 0;
$topic_data[$topic_id]['last_post_id'] = 0; $topic_data[$topic_id]['last_post_id'] = 0;
unset($topic_data[$topic_id]['topic_id']); unset($topic_data[$topic_id]['topic_id']);
@ -1917,14 +1930,24 @@ function sync($mode, $where_type = '', $where_ids = '', $resync_parents = false,
// When we'll be done, only topics with no posts will remain // When we'll be done, only topics with no posts will remain
unset($delete_topics[$topic_id]); unset($delete_topics[$topic_id]);
$topic_data[$topic_id]['replies_real'] += $row['total_posts']; if ($row['post_visibility'] == ITEM_APPROVED)
{
$topic_data[$topic_id]['posts'] = $row['total_posts'];
}
else if ($row['post_visibility'] == ITEM_UNAPPROVED)
{
$topic_data[$topic_id]['posts_unapproved'] = $row['total_posts'];
}
else if ($row['post_visibility'] == ITEM_DELETED)
{
$topic_data[$topic_id]['posts_softdeleted'] = $row['total_posts'];
}
if ($row['post_visibility'] == ITEM_APPROVED) if ($row['post_visibility'] == ITEM_APPROVED)
{ {
$topic_data[$topic_id]['visibility'] = ITEM_APPROVED; $topic_data[$topic_id]['visibility'] = ITEM_APPROVED;
$topic_data[$topic_id]['first_post_id'] = $row['first_post_id']; $topic_data[$topic_id]['first_post_id'] = $row['first_post_id'];
$topic_data[$topic_id]['last_post_id'] = $row['last_post_id']; $topic_data[$topic_id]['last_post_id'] = $row['last_post_id'];
$topic_data[$topic_id]['replies'] = $row['total_posts'] - 1;
} }
else if ($topic_data[$topic_id]['visibility'] != ITEM_APPROVED) else if ($topic_data[$topic_id]['visibility'] != ITEM_APPROVED)
{ {
@ -2120,7 +2143,7 @@ function sync($mode, $where_type = '', $where_ids = '', $resync_parents = false,
} }
// These are fields that will be synchronised // These are fields that will be synchronised
$fieldnames = array('time', 'visibility', 'replies', 'replies_real', 'poster', 'first_post_id', 'first_poster_name', 'first_poster_colour', 'last_post_id', 'last_post_subject', 'last_post_time', 'last_poster_id', 'last_poster_name', 'last_poster_colour'); $fieldnames = array('time', 'visibility', 'posts', 'posts_unapproved', 'posts_softdeleted', 'poster', 'first_post_id', 'first_poster_name', 'first_poster_colour', 'last_post_id', 'last_post_subject', 'last_post_time', 'last_poster_id', 'last_poster_name', 'last_poster_colour');
if ($sync_extra) if ($sync_extra)
{ {