0 if ($per_page < 1) message($lang_admin_maintenance['Posts must be integer message']); @set_time_limit(0); // If this is the first cycle of posts we empty the search index before we proceed if (isset($_GET['i_empty_index'])) { // This is the only potentially "dangerous" thing we can do here, so we check the referer confirm_referrer('admin_maintenance.php'); $db->truncate_table('search_matches') or error('Unable to empty search index match table', __FILE__, __LINE__, $db->error()); $db->truncate_table('search_words') or error('Unable to empty search index words table', __FILE__, __LINE__, $db->error()); // Reset the sequence for the search words (not needed for SQLite) switch ($db_type) { case 'mysql': case 'mysqli': case 'mysql_innodb': case 'mysqli_innodb': $result = $db->query('ALTER TABLE '.$db->prefix.'search_words auto_increment=1') or error('Unable to update table auto_increment', __FILE__, __LINE__, $db->error()); break; case 'pgsql'; $result = $db->query('SELECT setval(\''.$db->prefix.'search_words_id_seq\', 1, false)') or error('Unable to update sequence', __FILE__, __LINE__, $db->error()); } } $page_title = array(pun_htmlspecialchars($pun_config['o_board_title']), $lang_admin_maintenance['Rebuilding search index']); ?>
'.sprintf($lang_admin_maintenance['Processing post'], $cur_item['id']).'
'."\n"; if ($cur_item['id'] == $cur_item['first_post_id']) update_search_index('post', $cur_item['id'], $cur_item['message'], $cur_item['subject']); else update_search_index('post', $cur_item['id'], $cur_item['message']); $end_at = $cur_item['id']; } // Check if there is more work to do if ($end_at > 0) { $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()); if ($db->num_rows($result) > 0) $query_str = '?action=rebuild&i_per_page='.$per_page.'&i_start_at='.$db->result($result); } $db->end_transaction(); $db->close(); exit(''.sprintf($lang_admin_maintenance['Javascript redirect failed'], ''.$lang_admin_maintenance['Click here'].'').'
'); } if ($action == 'prune') { $prune_from = trim($_POST['prune_from']); $prune_sticky = intval($_POST['prune_sticky']); if (isset($_POST['prune_comply'])) { confirm_referrer('admin_maintenance.php'); $prune_days = intval($_POST['prune_days']); $prune_date = ($prune_days) ? time() - ($prune_days * 86400) : -1; @set_time_limit(0); if ($prune_from == 'all') { $result = $db->query('SELECT id FROM '.$db->prefix.'forums') or error('Unable to fetch forum list', __FILE__, __LINE__, $db->error()); $num_forums = $db->num_rows($result); for ($i = 0; $i < $num_forums; ++$i) { $fid = $db->result($result, $i); prune($fid, $prune_sticky, $prune_date); update_forum($fid); } } else { $prune_from = intval($prune_from); prune($prune_from, $prune_sticky, $prune_date); update_forum($prune_from); } // Locate any "orphaned redirect topics" and delete them $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()); $num_orphans = $db->num_rows($result); if ($num_orphans) { for ($i = 0; $i < $num_orphans; ++$i) $orphans[] = $db->result($result, $i); $db->query('DELETE FROM '.$db->prefix.'topics WHERE id IN('.implode(',', $orphans).')') or error('Unable to delete redirect topics', __FILE__, __LINE__, $db->error()); } redirect('admin_maintenance.php', $lang_admin_maintenance['Posts pruned redirect']); } $prune_days = trim($_POST['req_prune_days']); if ($prune_days == '' || preg_match('%[^0-9]%', $prune_days)) message($lang_admin_maintenance['Days must be integer message']); $prune_date = time() - ($prune_days * 86400); // Concatenate together the query for counting number of topics to prune $sql = 'SELECT COUNT(id) FROM '.$db->prefix.'topics WHERE last_post<'.$prune_date.' AND moved_to IS NULL'; if ($prune_sticky == '0') $sql .= ' AND sticky=0'; if ($prune_from != 'all') { $prune_from = intval($prune_from); $sql .= ' AND forum_id='.$prune_from; // Fetch the forum name (just for cosmetic reasons) $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()); $forum = '"'.pun_htmlspecialchars($db->result($result)).'"'; } else $forum = $lang_admin_maintenance['All forums']; $result = $db->query($sql) or error('Unable to fetch topic prune count', __FILE__, __LINE__, $db->error()); $num_topics = $db->result($result); if (!$num_topics) message(sprintf($lang_admin_maintenance['No old topics message'], $prune_days)); $page_title = array(pun_htmlspecialchars($pun_config['o_board_title']), $lang_admin_common['Admin'], $lang_admin_common['Prune']); define('PUN_ACTIVE_PAGE', 'admin'); require PUN_ROOT.'header.php'; generate_admin_menu('maintenance'); ?>