diff options
author | Joas Schilling <nickvergessen@gmx.de> | 2012-10-09 14:02:42 +0200 |
---|---|---|
committer | Joas Schilling <nickvergessen@gmx.de> | 2012-10-09 14:02:42 +0200 |
commit | 224be5bc4f7ffdf6f22c3da3aff94fb7a3d7571f (patch) | |
tree | 45be26b2a784f9a9d32bf93cc8580382b6c17ef3 /phpBB/includes/functions_admin.php | |
parent | 8267cbbd03888f0b89fbbd345b19d9b36e1190b2 (diff) | |
download | forums-224be5bc4f7ffdf6f22c3da3aff94fb7a3d7571f.tar forums-224be5bc4f7ffdf6f22c3da3aff94fb7a3d7571f.tar.gz forums-224be5bc4f7ffdf6f22c3da3aff94fb7a3d7571f.tar.bz2 forums-224be5bc4f7ffdf6f22c3da3aff94fb7a3d7571f.tar.xz forums-224be5bc4f7ffdf6f22c3da3aff94fb7a3d7571f.zip |
[feature/soft-delete] Fix sync('topic_visibility')
The function can not rely on the first post anymore, as that one could be soft
deleted but the topic still has approved replies which are still visible.
PHPBB3-9567
Diffstat (limited to 'phpBB/includes/functions_admin.php')
-rw-r--r-- | phpBB/includes/functions_admin.php | 73 |
1 files changed, 41 insertions, 32 deletions
diff --git a/phpBB/includes/functions_admin.php b/phpBB/includes/functions_admin.php index 04c99b5e62..0a351aa6e8 100644 --- a/phpBB/includes/functions_admin.php +++ b/phpBB/includes/functions_admin.php @@ -1383,43 +1383,52 @@ function sync($mode, $where_type = '', $where_ids = '', $resync_parents = false, case 'topic_visibility': $db->sql_transaction('begin'); - switch ($db->sql_layer) + + $sql = 'SELECT t.topic_id, p.post_visibility + FROM ' . TOPICS_TABLE . ' t, ' . POSTS_TABLE . " p + $where_sql_and p.topic_id = t.topic_id + AND p.post_visibility = " . ITEM_APPROVED; + $result = $db->sql_query($sql); + + $topics_approved = array(); + while ($row = $db->sql_fetchrow($result)) { - case 'mysql4': - case 'mysqli': - $sql = 'UPDATE ' . TOPICS_TABLE . ' t, ' . POSTS_TABLE . " p - SET t.topic_visibility = p.post_visibility - $where_sql_and t.topic_first_post_id = p.post_id"; - $db->sql_query($sql); - break; + $topics_approved[] = (int) $row['topic_id']; + } + $db->sql_freeresult($result); - default: - $sql = 'SELECT t.topic_id, p.post_visibility - FROM ' . TOPICS_TABLE . ' t, ' . POSTS_TABLE . " p - $where_sql_and p.post_id = t.topic_first_post_id - AND p.post_visibility <> t.topic_visibility"; - $result = $db->sql_query($sql); + $sql = 'SELECT t.topic_id, p.post_visibility + FROM ' . TOPICS_TABLE . ' t, ' . POSTS_TABLE . " p + $where_sql_and " . $db->sql_in_set('t.topic_id', $topics_approved, true, true) . ' + AND p.topic_id = t.topic_id + AND p.post_visibility = ' . ITEM_DELETED; + $result = $db->sql_query($sql); - $topic_ids = array(); - while ($row = $db->sql_fetchrow($result)) - { - $topic_ids[$row['topic_id']] = $row['post_visibility']; - } - $db->sql_freeresult($result); + $topics_softdeleted = array(); + while ($row = $db->sql_fetchrow($result)) + { + $topics_softdeleted[] = (int) $row['topic_id']; + } + $db->sql_freeresult($result); - if (!sizeof($topic_ids)) - { - return; - } + $topics_softdeleted = array_diff($topics_softdeleted, $topics_approved); + $topics_not_unapproved = array_merge($topics_softdeleted, $topics_approved); - foreach ($topic_ids as $topic_id => $visibility) - { - $sql = 'UPDATE ' . TOPICS_TABLE . ' - SET topic_visibility = ' . $visibility . ' - WHERE topic_id' . $topic_id; - $db->sql_query($sql); - } - break; + $update_ary = array( + ITEM_UNAPPROVED => (!empty($topics_not_unapproved)) ? $where_sql_and . ' ' . $db->sql_in_set('topic_id', $topics_not_unapproved, true) : '', + ITEM_APPROVED => (!empty($topics_approved)) ? ' WHERE ' . $db->sql_in_set('topic_id', $topics_approved) : '', + ITEM_DELETED => (!empty($topics_softdeleted)) ? ' WHERE ' . $db->sql_in_set('topic_id', $topics_softdeleted) : '', + ); + + foreach ($topic_visiblities as $visibility => $sql_where) + { + if ($sql_where) + { + $sql = 'UPDATE ' . TOPICS_TABLE . ' + SET topic_visibility = ' . $visibility . ' + ' . $sql_where; + $db->sql_query($sql); + } } $db->sql_transaction('commit'); |