107 // |
107 // |
108 // Delete topics from $forum_id that are "older than" $prune_date (if $prune_sticky is 1, sticky topics will also be deleted) |
108 // Delete topics from $forum_id that are "older than" $prune_date (if $prune_sticky is 1, sticky topics will also be deleted) |
109 // |
109 // |
110 function prune($forum_id, $prune_sticky, $prune_date) |
110 function prune($forum_id, $prune_sticky, $prune_date) |
111 { |
111 { |
112 global $db; |
112 global $pun_db; |
113 |
113 |
114 $extra_sql = ($prune_date != -1) ? ' AND last_post<'.$prune_date : ''; |
114 $extra_sql = ($prune_date != -1) ? ' AND last_post<'.$prune_date : ''; |
115 |
115 |
116 if (!$prune_sticky) |
116 if (!$prune_sticky) |
117 $extra_sql .= ' AND sticky=\'0\''; |
117 $extra_sql .= ' AND sticky=\'0\''; |
118 |
118 |
119 // Fetch topics to prune |
119 // Fetch topics to prune |
120 $result = $db->query('SELECT id FROM '.$db->prefix.'topics WHERE forum_id='.$forum_id.$extra_sql, true) or error('Unable to fetch topics', __FILE__, __LINE__, $db->error()); |
120 $result = $pun_db->query('SELECT id FROM '.$pun_db->prefix.'topics WHERE forum_id='.$forum_id.$extra_sql, true) or error('Unable to fetch topics', __FILE__, __LINE__, $pun_db->error()); |
121 |
121 |
122 $topic_ids = ''; |
122 $topic_ids = ''; |
123 while ($row = $db->fetch_row($result)) |
123 while ($row = $pun_db->fetch_row($result)) |
124 $topic_ids .= (($topic_ids != '') ? ',' : '').$row[0]; |
124 $topic_ids .= (($topic_ids != '') ? ',' : '').$row[0]; |
125 |
125 |
126 if ($topic_ids != '') |
126 if ($topic_ids != '') |
127 { |
127 { |
128 // Fetch posts to prune |
128 // Fetch posts to prune |
129 $result = $db->query('SELECT id FROM '.$db->prefix.'posts WHERE topic_id IN('.$topic_ids.')', true) or error('Unable to fetch posts', __FILE__, __LINE__, $db->error()); |
129 $result = $pun_db->query('SELECT id FROM '.$pun_db->prefix.'posts WHERE topic_id IN('.$topic_ids.')', true) or error('Unable to fetch posts', __FILE__, __LINE__, $pun_db->error()); |
130 |
130 |
131 $post_ids = ''; |
131 $post_ids = ''; |
132 while ($row = $db->fetch_row($result)) |
132 while ($row = $pun_db->fetch_row($result)) |
133 $post_ids .= (($post_ids != '') ? ',' : '').$row[0]; |
133 $post_ids .= (($post_ids != '') ? ',' : '').$row[0]; |
134 |
134 |
135 if ($post_ids != '') |
135 if ($post_ids != '') |
136 { |
136 { |
137 // Delete topics |
137 // Delete topics |
138 $db->query('DELETE FROM '.$db->prefix.'topics WHERE id IN('.$topic_ids.')') or error('Unable to prune topics', __FILE__, __LINE__, $db->error()); |
138 $pun_db->query('DELETE FROM '.$pun_db->prefix.'topics WHERE id IN('.$topic_ids.')') or error('Unable to prune topics', __FILE__, __LINE__, $pun_db->error()); |
139 // Delete subscriptions |
139 // Delete subscriptions |
140 $db->query('DELETE FROM '.$db->prefix.'subscriptions WHERE topic_id IN('.$topic_ids.')') or error('Unable to prune subscriptions', __FILE__, __LINE__, $db->error()); |
140 $pun_db->query('DELETE FROM '.$pun_db->prefix.'subscriptions WHERE topic_id IN('.$topic_ids.')') or error('Unable to prune subscriptions', __FILE__, __LINE__, $pun_db->error()); |
141 // Delete posts |
141 // Delete posts |
142 $db->query('DELETE FROM '.$db->prefix.'posts WHERE id IN('.$post_ids.')') or error('Unable to prune posts', __FILE__, __LINE__, $db->error()); |
142 $pun_db->query('DELETE FROM '.$pun_db->prefix.'posts WHERE id IN('.$post_ids.')') or error('Unable to prune posts', __FILE__, __LINE__, $pun_db->error()); |
143 |
143 |
144 // We removed a bunch of posts, so now we have to update the search index |
144 // We removed a bunch of posts, so now we have to update the search index |
145 require_once PUN_ROOT.'include/search_idx.php'; |
145 require_once PUN_ROOT.'include/search_idx.php'; |
146 strip_search_index($post_ids); |
146 strip_search_index($post_ids); |
147 } |
147 } |