query('SELECT id FROM '.$db->prefix.'topics WHERE forum_id='.$forum_id.$extra) or error('Unable to fetch topics', __FILE__, __LINE__, $db->error());
while ($row = $db->fetch_row($result))
$topic_ids .= (($topic_ids != '') ? ',' : '').$row[0];
if ($topic_ids != '')
{
// Fetch posts to prune
$result = $db->query('SELECT id FROM '.$db->prefix.'posts WHERE topic_id IN('.$topic_ids.')') or error('Unable to fetch posts', __FILE__, __LINE__, $db->error());
while ($row = $db->fetch_row($result))
$post_ids .= (($post_ids != '') ? ',' : '').$row[0];
if ($post_ids != '')
{
// Delete topics (start transaction)
// End transaction must be done after prune() (i.e. in updateForum() or when deleting a forum)
$db->query('DELETE FROM '.$db->prefix.'topics WHERE id IN('.$topic_ids.')', PUN_TRANS_START) or error('Unable to prune topics', __FILE__, __LINE__, $db->error());
$db->query('DELETE FROM '.$db->prefix.'posts WHERE id IN('.$post_ids.')') or error('Unable to prune posts', __FILE__, __LINE__, $db->error());
// We removed a bunch of posts, so now we have to update the search index
require 'include/searchidx.php';
strip_search_index($post_ids);
}
}
}