1 | <?php |
---|
2 | |
---|
3 | /** |
---|
4 | * Copyright (C) 2008-2011 FluxBB |
---|
5 | * based on code by Rickard Andersson copyright (C) 2002-2008 PunBB |
---|
6 | * License: http://www.gnu.org/licenses/gpl.html GPL version 2 or higher |
---|
7 | */ |
---|
8 | |
---|
9 | // Tell header.php to use the admin template |
---|
10 | define('PUN_ADMIN_CONSOLE', 1); |
---|
11 | // Tell common.php that we don't want output buffering |
---|
12 | define('PUN_DISABLE_BUFFERING', 1); |
---|
13 | |
---|
14 | define('PUN_ROOT', dirname(__FILE__).'/'); |
---|
15 | require PUN_ROOT.'include/common.php'; |
---|
16 | require PUN_ROOT.'include/common_admin.php'; |
---|
17 | |
---|
18 | |
---|
19 | if ($pun_user['g_id'] != PUN_ADMIN) |
---|
20 | message($lang_common['No permission']); |
---|
21 | |
---|
22 | // Load the admin_maintenance.php language file |
---|
23 | require PUN_ROOT.'lang/'.$admin_language.'/admin_maintenance.php'; |
---|
24 | |
---|
25 | $action = isset($_REQUEST['action']) ? trim($_REQUEST['action']) : ''; |
---|
26 | |
---|
27 | if ($action == 'rebuild') |
---|
28 | { |
---|
29 | $per_page = isset($_GET['i_per_page']) ? intval($_GET['i_per_page']) : 0; |
---|
30 | $start_at = isset($_GET['i_start_at']) ? intval($_GET['i_start_at']) : 0; |
---|
31 | |
---|
32 | // Check per page is > 0 |
---|
33 | if ($per_page < 1) |
---|
34 | message($lang_admin_maintenance['Posts must be integer message']); |
---|
35 | |
---|
36 | @set_time_limit(0); |
---|
37 | |
---|
38 | // If this is the first cycle of posts we empty the search index before we proceed |
---|
39 | if (isset($_GET['i_empty_index'])) |
---|
40 | { |
---|
41 | // This is the only potentially "dangerous" thing we can do here, so we check the referer |
---|
42 | confirm_referrer('admin_maintenance.php'); |
---|
43 | |
---|
44 | $db->truncate_table('search_matches') or error('Unable to empty search index match table', __FILE__, __LINE__, $db->error()); |
---|
45 | $db->truncate_table('search_words') or error('Unable to empty search index words table', __FILE__, __LINE__, $db->error()); |
---|
46 | |
---|
47 | // Reset the sequence for the search words (not needed for SQLite) |
---|
48 | switch ($db_type) |
---|
49 | { |
---|
50 | case 'mysql': |
---|
51 | case 'mysqli': |
---|
52 | case 'mysql_innodb': |
---|
53 | case 'mysqli_innodb': |
---|
54 | $result = $db->query('ALTER TABLE '.$db->prefix.'search_words auto_increment=1') or error('Unable to update table auto_increment', __FILE__, __LINE__, $db->error()); |
---|
55 | break; |
---|
56 | |
---|
57 | case 'pgsql'; |
---|
58 | $result = $db->query('SELECT setval(\''.$db->prefix.'search_words_id_seq\', 1, false)') or error('Unable to update sequence', __FILE__, __LINE__, $db->error()); |
---|
59 | } |
---|
60 | } |
---|
61 | |
---|
62 | $page_title = array(pun_htmlspecialchars($pun_config['o_board_title']), $lang_admin_maintenance['Rebuilding search index']); |
---|
63 | |
---|
64 | ?> |
---|
65 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> |
---|
66 | |
---|
67 | <html> |
---|
68 | <head> |
---|
69 | <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> |
---|
70 | <title><?php echo generate_page_title($page_title) ?></title> |
---|
71 | <style type="text/css"> |
---|
72 | body { |
---|
73 | font: 12px Verdana, Arial, Helvetica, sans-serif; |
---|
74 | color: #333333; |
---|
75 | background-color: #FFFFFF |
---|
76 | } |
---|
77 | |
---|
78 | h1 { |
---|
79 | font-size: 16px; |
---|
80 | font-weight: normal; |
---|
81 | } |
---|
82 | </style> |
---|
83 | </head> |
---|
84 | <body> |
---|
85 | |
---|
86 | <h1><?php echo $lang_admin_maintenance['Rebuilding index info'] ?></h1> |
---|
87 | <hr /> |
---|
88 | |
---|
89 | <?php |
---|
90 | |
---|
91 | $query_str = ''; |
---|
92 | |
---|
93 | require PUN_ROOT.'include/search_idx.php'; |
---|
94 | |
---|
95 | // Fetch posts to process this cycle |
---|
96 | $result = $db->query('SELECT p.id, p.message, t.subject, t.first_post_id FROM '.$db->prefix.'posts AS p INNER JOIN '.$db->prefix.'topics AS t ON t.id=p.topic_id WHERE p.id >= '.$start_at.' ORDER BY p.id ASC LIMIT '.$per_page) or error('Unable to fetch posts', __FILE__, __LINE__, $db->error()); |
---|
97 | |
---|
98 | $end_at = 0; |
---|
99 | while ($cur_item = $db->fetch_assoc($result)) |
---|
100 | { |
---|
101 | echo '<p><span>'.sprintf($lang_admin_maintenance['Processing post'], $cur_item['id']).'</span></p>'."\n"; |
---|
102 | |
---|
103 | if ($cur_item['id'] == $cur_item['first_post_id']) |
---|
104 | update_search_index('post', $cur_item['id'], $cur_item['message'], $cur_item['subject']); |
---|
105 | else |
---|
106 | update_search_index('post', $cur_item['id'], $cur_item['message']); |
---|
107 | |
---|
108 | $end_at = $cur_item['id']; |
---|
109 | } |
---|
110 | |
---|
111 | // Check if there is more work to do |
---|
112 | if ($end_at > 0) |
---|
113 | { |
---|
114 | $result = $db->query('SELECT id FROM '.$db->prefix.'posts WHERE id > '.$end_at.' ORDER BY id ASC LIMIT 1') or error('Unable to fetch next ID', __FILE__, __LINE__, $db->error()); |
---|
115 | |
---|
116 | if ($db->num_rows($result) > 0) |
---|
117 | $query_str = '?action=rebuild&i_per_page='.$per_page.'&i_start_at='.$db->result($result); |
---|
118 | } |
---|
119 | |
---|
120 | $db->end_transaction(); |
---|
121 | $db->close(); |
---|
122 | |
---|
123 | exit('<script type="text/javascript">window.location="admin_maintenance.php'.$query_str.'"</script><hr /><p>'.sprintf($lang_admin_maintenance['Javascript redirect failed'], '<a href="admin_maintenance.php'.$query_str.'">'.$lang_admin_maintenance['Click here'].'</a>').'</p>'); |
---|
124 | } |
---|
125 | |
---|
126 | if ($action == 'prune') |
---|
127 | { |
---|
128 | $prune_from = trim($_POST['prune_from']); |
---|
129 | $prune_sticky = intval($_POST['prune_sticky']); |
---|
130 | |
---|
131 | if (isset($_POST['prune_comply'])) |
---|
132 | { |
---|
133 | confirm_referrer('admin_maintenance.php'); |
---|
134 | |
---|
135 | $prune_days = intval($_POST['prune_days']); |
---|
136 | $prune_date = ($prune_days) ? time() - ($prune_days * 86400) : -1; |
---|
137 | |
---|
138 | @set_time_limit(0); |
---|
139 | |
---|
140 | if ($prune_from == 'all') |
---|
141 | { |
---|
142 | $result = $db->query('SELECT id FROM '.$db->prefix.'forums') or error('Unable to fetch forum list', __FILE__, __LINE__, $db->error()); |
---|
143 | $num_forums = $db->num_rows($result); |
---|
144 | |
---|
145 | for ($i = 0; $i < $num_forums; ++$i) |
---|
146 | { |
---|
147 | $fid = $db->result($result, $i); |
---|
148 | |
---|
149 | prune($fid, $prune_sticky, $prune_date); |
---|
150 | update_forum($fid); |
---|
151 | } |
---|
152 | } |
---|
153 | else |
---|
154 | { |
---|
155 | $prune_from = intval($prune_from); |
---|
156 | prune($prune_from, $prune_sticky, $prune_date); |
---|
157 | update_forum($prune_from); |
---|
158 | } |
---|
159 | |
---|
160 | // Locate any "orphaned redirect topics" and delete them |
---|
161 | $result = $db->query('SELECT t1.id FROM '.$db->prefix.'topics AS t1 LEFT JOIN '.$db->prefix.'topics AS t2 ON t1.moved_to=t2.id WHERE t2.id IS NULL AND t1.moved_to IS NOT NULL') or error('Unable to fetch redirect topics', __FILE__, __LINE__, $db->error()); |
---|
162 | $num_orphans = $db->num_rows($result); |
---|
163 | |
---|
164 | if ($num_orphans) |
---|
165 | { |
---|
166 | for ($i = 0; $i < $num_orphans; ++$i) |
---|
167 | $orphans[] = $db->result($result, $i); |
---|
168 | |
---|
169 | $db->query('DELETE FROM '.$db->prefix.'topics WHERE id IN('.implode(',', $orphans).')') or error('Unable to delete redirect topics', __FILE__, __LINE__, $db->error()); |
---|
170 | } |
---|
171 | |
---|
172 | redirect('admin_maintenance.php', $lang_admin_maintenance['Posts pruned redirect']); |
---|
173 | } |
---|
174 | |
---|
175 | $prune_days = trim($_POST['req_prune_days']); |
---|
176 | if ($prune_days == '' || preg_match('%[^0-9]%', $prune_days)) |
---|
177 | message($lang_admin_maintenance['Days must be integer message']); |
---|
178 | |
---|
179 | $prune_date = time() - ($prune_days * 86400); |
---|
180 | |
---|
181 | // Concatenate together the query for counting number of topics to prune |
---|
182 | $sql = 'SELECT COUNT(id) FROM '.$db->prefix.'topics WHERE last_post<'.$prune_date.' AND moved_to IS NULL'; |
---|
183 | |
---|
184 | if ($prune_sticky == '0') |
---|
185 | $sql .= ' AND sticky=0'; |
---|
186 | |
---|
187 | if ($prune_from != 'all') |
---|
188 | { |
---|
189 | $prune_from = intval($prune_from); |
---|
190 | $sql .= ' AND forum_id='.$prune_from; |
---|
191 | |
---|
192 | // Fetch the forum name (just for cosmetic reasons) |
---|
193 | $result = $db->query('SELECT forum_name FROM '.$db->prefix.'forums WHERE id='.$prune_from) or error('Unable to fetch forum name', __FILE__, __LINE__, $db->error()); |
---|
194 | $forum = '"'.pun_htmlspecialchars($db->result($result)).'"'; |
---|
195 | } |
---|
196 | else |
---|
197 | $forum = $lang_admin_maintenance['All forums']; |
---|
198 | |
---|
199 | $result = $db->query($sql) or error('Unable to fetch topic prune count', __FILE__, __LINE__, $db->error()); |
---|
200 | $num_topics = $db->result($result); |
---|
201 | |
---|
202 | if (!$num_topics) |
---|
203 | message(sprintf($lang_admin_maintenance['No old topics message'], $prune_days)); |
---|
204 | |
---|
205 | |
---|
206 | $page_title = array(pun_htmlspecialchars($pun_config['o_board_title']), $lang_admin_common['Admin'], $lang_admin_common['Prune']); |
---|
207 | define('PUN_ACTIVE_PAGE', 'admin'); |
---|
208 | require PUN_ROOT.'header.php'; |
---|
209 | |
---|
210 | generate_admin_menu('maintenance'); |
---|
211 | |
---|
212 | ?> |
---|
213 | <div class="blockform"> |
---|
214 | <h2><span><?php echo $lang_admin_maintenance['Prune head'] ?></span></h2> |
---|
215 | <div class="box"> |
---|
216 | <form method="post" action="admin_maintenance.php"> |
---|
217 | <div class="inform"> |
---|
218 | <input type="hidden" name="action" value="prune" /> |
---|
219 | <input type="hidden" name="prune_days" value="<?php echo $prune_days ?>" /> |
---|
220 | <input type="hidden" name="prune_sticky" value="<?php echo $prune_sticky ?>" /> |
---|
221 | <input type="hidden" name="prune_from" value="<?php echo $prune_from ?>" /> |
---|
222 | <fieldset> |
---|
223 | <legend><?php echo $lang_admin_maintenance['Confirm prune subhead'] ?></legend> |
---|
224 | <div class="infldset"> |
---|
225 | <p><?php printf($lang_admin_maintenance['Confirm prune info'], $prune_days, $forum, forum_number_format($num_topics)) ?></p> |
---|
226 | <p class="warntext"><?php echo $lang_admin_maintenance['Confirm prune warn'] ?></p> |
---|
227 | </div> |
---|
228 | </fieldset> |
---|
229 | </div> |
---|
230 | <p class="buttons"><input type="submit" name="prune_comply" value="<?php echo $lang_admin_common['Prune'] ?>" /><a href="javascript:history.go(-1)"><?php echo $lang_admin_common['Go back'] ?></a></p> |
---|
231 | </form> |
---|
232 | </div> |
---|
233 | </div> |
---|
234 | <div class="clearer"></div> |
---|
235 | </div> |
---|
236 | <?php |
---|
237 | |
---|
238 | require PUN_ROOT.'footer.php'; |
---|
239 | exit; |
---|
240 | } |
---|
241 | |
---|
242 | |
---|
243 | // Get the first post ID from the db |
---|
244 | $result = $db->query('SELECT id FROM '.$db->prefix.'posts ORDER BY id ASC LIMIT 1') or error('Unable to fetch topic info', __FILE__, __LINE__, $db->error()); |
---|
245 | if ($db->num_rows($result)) |
---|
246 | $first_id = $db->result($result); |
---|
247 | |
---|
248 | $page_title = array(pun_htmlspecialchars($pun_config['o_board_title']), $lang_admin_common['Admin'], $lang_admin_common['Maintenance']); |
---|
249 | define('PUN_ACTIVE_PAGE', 'admin'); |
---|
250 | require PUN_ROOT.'header.php'; |
---|
251 | |
---|
252 | generate_admin_menu('maintenance'); |
---|
253 | |
---|
254 | ?> |
---|
255 | <div class="blockform"> |
---|
256 | <h2><span><?php echo $lang_admin_maintenance['Maintenance head'] ?></span></h2> |
---|
257 | <div class="box"> |
---|
258 | <form method="get" action="admin_maintenance.php"> |
---|
259 | <div class="inform"> |
---|
260 | <input type="hidden" name="action" value="rebuild" /> |
---|
261 | <fieldset> |
---|
262 | <legend><?php echo $lang_admin_maintenance['Rebuild index subhead'] ?></legend> |
---|
263 | <div class="infldset"> |
---|
264 | <p><?php printf($lang_admin_maintenance['Rebuild index info'], '<a href="admin_options.php#maintenance">'.$lang_admin_common['Maintenance mode'].'</a>') ?></p> |
---|
265 | <table class="aligntop" cellspacing="0"> |
---|
266 | <tr> |
---|
267 | <th scope="row"><?php echo $lang_admin_maintenance['Posts per cycle label'] ?></th> |
---|
268 | <td> |
---|
269 | <input type="text" name="i_per_page" size="7" maxlength="7" value="300" tabindex="1" /> |
---|
270 | <span><?php echo $lang_admin_maintenance['Posts per cycle help'] ?></span> |
---|
271 | </td> |
---|
272 | </tr> |
---|
273 | <tr> |
---|
274 | <th scope="row"><?php echo $lang_admin_maintenance['Starting post label'] ?></th> |
---|
275 | <td> |
---|
276 | <input type="text" name="i_start_at" size="7" maxlength="7" value="<?php echo (isset($first_id)) ? $first_id : 0 ?>" tabindex="2" /> |
---|
277 | <span><?php echo $lang_admin_maintenance['Starting post help'] ?></span> |
---|
278 | </td> |
---|
279 | </tr> |
---|
280 | <tr> |
---|
281 | <th scope="row"><?php echo $lang_admin_maintenance['Empty index label'] ?></th> |
---|
282 | <td class="inputadmin"> |
---|
283 | <span><input type="checkbox" name="i_empty_index" value="1" tabindex="3" checked="checked" />  <?php echo $lang_admin_maintenance['Empty index help'] ?></span> |
---|
284 | </td> |
---|
285 | </tr> |
---|
286 | </table> |
---|
287 | <p class="topspace"><?php echo $lang_admin_maintenance['Rebuild completed info'] ?></p> |
---|
288 | <div class="fsetsubmit"><input type="submit" name="rebuild_index" value="<?php echo $lang_admin_maintenance['Rebuild index'] ?>" tabindex="4" /></div> |
---|
289 | </div> |
---|
290 | </fieldset> |
---|
291 | </div> |
---|
292 | </form> |
---|
293 | |
---|
294 | <form method="post" action="admin_maintenance.php" onsubmit="return process_form(this)"> |
---|
295 | <div class="inform"> |
---|
296 | <input type="hidden" name="action" value="prune" /> |
---|
297 | <fieldset> |
---|
298 | <legend><?php echo $lang_admin_maintenance['Prune subhead'] ?></legend> |
---|
299 | <div class="infldset"> |
---|
300 | <table class="aligntop" cellspacing="0"> |
---|
301 | <tr> |
---|
302 | <th scope="row"><?php echo $lang_admin_maintenance['Days old label'] ?></th> |
---|
303 | <td> |
---|
304 | <input type="text" name="req_prune_days" size="3" maxlength="3" tabindex="5" /> |
---|
305 | <span><?php echo $lang_admin_maintenance['Days old help'] ?></span> |
---|
306 | </td> |
---|
307 | </tr> |
---|
308 | <tr> |
---|
309 | <th scope="row"><?php echo $lang_admin_maintenance['Prune sticky label'] ?></th> |
---|
310 | <td> |
---|
311 | <input type="radio" name="prune_sticky" value="1" tabindex="6" checked="checked" /> <strong><?php echo $lang_admin_common['Yes'] ?></strong>   <input type="radio" name="prune_sticky" value="0" /> <strong><?php echo $lang_admin_common['No'] ?></strong> |
---|
312 | <span><?php echo $lang_admin_maintenance['Prune sticky help'] ?></span> |
---|
313 | </td> |
---|
314 | </tr> |
---|
315 | <tr> |
---|
316 | <th scope="row"><?php echo $lang_admin_maintenance['Prune from label'] ?></th> |
---|
317 | <td> |
---|
318 | <select name="prune_from" tabindex="7"> |
---|
319 | <option value="all"><?php echo $lang_admin_maintenance['All forums'] ?></option> |
---|
320 | <?php |
---|
321 | |
---|
322 | $result = $db->query('SELECT c.id AS cid, c.cat_name, f.id AS fid, f.forum_name FROM '.$db->prefix.'categories AS c INNER JOIN '.$db->prefix.'forums AS f ON c.id=f.cat_id WHERE f.redirect_url IS NULL ORDER BY c.disp_position, c.id, f.disp_position') or error('Unable to fetch category/forum list', __FILE__, __LINE__, $db->error()); |
---|
323 | |
---|
324 | $cur_category = 0; |
---|
325 | while ($forum = $db->fetch_assoc($result)) |
---|
326 | { |
---|
327 | if ($forum['cid'] != $cur_category) // Are we still in the same category? |
---|
328 | { |
---|
329 | if ($cur_category) |
---|
330 | echo "\t\t\t\t\t\t\t\t\t\t\t".'</optgroup>'."\n"; |
---|
331 | |
---|
332 | echo "\t\t\t\t\t\t\t\t\t\t\t".'<optgroup label="'.pun_htmlspecialchars($forum['cat_name']).'">'."\n"; |
---|
333 | $cur_category = $forum['cid']; |
---|
334 | } |
---|
335 | |
---|
336 | echo "\t\t\t\t\t\t\t\t\t\t\t\t".'<option value="'.$forum['fid'].'">'.pun_htmlspecialchars($forum['forum_name']).'</option>'."\n"; |
---|
337 | } |
---|
338 | |
---|
339 | ?> |
---|
340 | </optgroup> |
---|
341 | </select> |
---|
342 | <span><?php echo $lang_admin_maintenance['Prune from help'] ?></span> |
---|
343 | </td> |
---|
344 | </tr> |
---|
345 | </table> |
---|
346 | <p class="topspace"><?php printf($lang_admin_maintenance['Prune info'], '<a href="admin_options.php#maintenance">'.$lang_admin_common['Maintenance mode'].'</a>') ?></p> |
---|
347 | <div class="fsetsubmit"><input type="submit" name="prune" value="<?php echo $lang_admin_common['Prune'] ?>" tabindex="8" /></div> |
---|
348 | </div> |
---|
349 | </fieldset> |
---|
350 | </div> |
---|
351 | </form> |
---|
352 | </div> |
---|
353 | </div> |
---|
354 | <div class="clearer"></div> |
---|
355 | </div> |
---|
356 | <?php |
---|
357 | |
---|
358 | require PUN_ROOT.'footer.php'; |
---|