26 // Tell header.php to use the admin template |
26 // Tell header.php to use the admin template |
27 define('PUN_ADMIN_CONSOLE', 1); |
27 define('PUN_ADMIN_CONSOLE', 1); |
28 // Tell common.php that we don't want output buffering |
28 // Tell common.php that we don't want output buffering |
29 define('PUN_DISABLE_BUFFERING', 1); |
29 define('PUN_DISABLE_BUFFERING', 1); |
30 |
30 |
31 define('PUN_ROOT', './'); |
31 //define('PUN_ROOT', './'); |
32 require PUN_ROOT.'include/common.php'; |
32 //require PUN_ROOT.'include/common.php'; |
|
33 |
|
34 global $pun_db, $pun_user, $pun_config, $lang_common; |
|
35 |
33 require PUN_ROOT.'include/common_admin.php'; |
36 require PUN_ROOT.'include/common_admin.php'; |
34 |
37 |
35 |
38 |
36 if ($pun_user['g_id'] > PUN_ADMIN) |
39 if ($pun_user['g_id'] < PUN_ADMIN) |
37 message($lang_common['No permission']); |
40 message($lang_common['No permission']); |
38 |
41 |
39 |
42 |
40 if (isset($_GET['i_per_page']) && isset($_GET['i_start_at'])) |
43 if (isset($_GET['i_per_page']) && isset($_GET['i_start_at'])) |
41 { |
44 { |
51 { |
54 { |
52 // This is the only potentially "dangerous" thing we can do here, so we check the referer |
55 // This is the only potentially "dangerous" thing we can do here, so we check the referer |
53 confirm_referrer('admin_maintenance.php'); |
56 confirm_referrer('admin_maintenance.php'); |
54 |
57 |
55 $truncate_sql = ($db_type != 'sqlite' && $db_type != 'pgsql') ? 'TRUNCATE TABLE ' : 'DELETE FROM '; |
58 $truncate_sql = ($db_type != 'sqlite' && $db_type != 'pgsql') ? 'TRUNCATE TABLE ' : 'DELETE FROM '; |
56 $db->query($truncate_sql.$db->prefix.'search_matches') or error('Unable to empty search index match table', __FILE__, __LINE__, $db->error()); |
59 $pun_db->query($truncate_sql.$pun_db->prefix.'search_matches') or error('Unable to empty search index match table', __FILE__, __LINE__, $pun_db->error()); |
57 $db->query($truncate_sql.$db->prefix.'search_words') or error('Unable to empty search index words table', __FILE__, __LINE__, $db->error()); |
60 $pun_db->query($truncate_sql.$pun_db->prefix.'search_words') or error('Unable to empty search index words table', __FILE__, __LINE__, $pun_db->error()); |
58 |
61 |
59 // Reset the sequence for the search words (not needed for SQLite) |
62 // Reset the sequence for the search words (not needed for SQLite) |
60 switch ($db_type) |
63 switch ($db_type) |
61 { |
64 { |
62 case 'mysql': |
65 case 'mysql': |
63 case 'mysqli': |
66 case 'mysqli': |
64 $result = $db->query('ALTER TABLE '.$db->prefix.'search_words auto_increment=1') or error('Unable to update table auto_increment', __FILE__, __LINE__, $db->error()); |
67 $result = $pun_db->query('ALTER TABLE '.$pun_db->prefix.'search_words auto_increment=1') or error('Unable to update table auto_increment', __FILE__, __LINE__, $pun_db->error()); |
65 break; |
68 break; |
66 |
69 |
67 case 'pgsql'; |
70 case 'pgsql'; |
68 $result = $db->query('SELECT setval(\''.$db->prefix.'search_words_id_seq\', 1, false)') or error('Unable to update sequence', __FILE__, __LINE__, $db->error()); |
71 $result = $pun_db->query('SELECT setval(\''.$pun_db->prefix.'search_words_id_seq\', 1, false)') or error('Unable to update sequence', __FILE__, __LINE__, $pun_db->error()); |
69 } |
72 } |
70 } |
73 } |
71 |
74 |
72 $end_at = $start_at + $per_page; |
75 $end_at = $start_at + $per_page; |
73 |
76 |
93 <?php |
96 <?php |
94 |
97 |
95 require PUN_ROOT.'include/search_idx.php'; |
98 require PUN_ROOT.'include/search_idx.php'; |
96 |
99 |
97 // Fetch posts to process |
100 // Fetch posts to process |
98 $result = $db->query('SELECT DISTINCT t.id, p.id, p.message FROM '.$db->prefix.'topics AS t INNER JOIN '.$db->prefix.'posts AS p ON t.id=p.topic_id WHERE t.id>='.$start_at.' AND t.id<'.$end_at.' ORDER BY t.id') or error('Unable to fetch topic/post info', __FILE__, __LINE__, $db->error()); |
101 $result = $pun_db->query('SELECT DISTINCT t.id, p.id, p.message FROM '.$pun_db->prefix.'topics AS t INNER JOIN '.$pun_db->prefix.'posts AS p ON t.id=p.topic_id WHERE t.id>='.$start_at.' AND t.id<'.$end_at.' ORDER BY t.id') or error('Unable to fetch topic/post info', __FILE__, __LINE__, $pun_db->error()); |
99 |
102 |
100 $cur_topic = 0; |
103 $cur_topic = 0; |
101 while ($cur_post = $db->fetch_row($result)) |
104 while ($cur_post = $pun_db->fetch_row($result)) |
102 { |
105 { |
103 if ($cur_post[0] <> $cur_topic) |
106 if ($cur_post[0] <> $cur_topic) |
104 { |
107 { |
105 // Fetch subject and ID of first post in topic |
108 // Fetch subject and ID of first post in topic |
106 $result2 = $db->query('SELECT p.id, t.subject, MIN(p.posted) AS first FROM '.$db->prefix.'posts AS p INNER JOIN '.$db->prefix.'topics AS t ON t.id=p.topic_id WHERE t.id='.$cur_post[0].' GROUP BY p.id, t.subject ORDER BY first LIMIT 1') or error('Unable to fetch topic info', __FILE__, __LINE__, $db->error()); |
109 $result2 = $pun_db->query('SELECT p.id, t.subject, MIN(p.posted) AS first FROM '.$pun_db->prefix.'posts AS p INNER JOIN '.$pun_db->prefix.'topics AS t ON t.id=p.topic_id WHERE t.id='.$cur_post[0].' GROUP BY p.id, t.subject ORDER BY first LIMIT 1') or error('Unable to fetch topic info', __FILE__, __LINE__, $pun_db->error()); |
107 list($first_post, $subject) = $db->fetch_row($result2); |
110 list($first_post, $subject) = $pun_db->fetch_row($result2); |
108 |
111 |
109 $cur_topic = $cur_post[0]; |
112 $cur_topic = $cur_post[0]; |
110 } |
113 } |
111 |
114 |
112 echo 'Processing post <strong>'.$cur_post[1].'</strong> in topic <strong>'.$cur_post[0].'</strong><br />'."\n"; |
115 echo 'Processing post <strong>'.$cur_post[1].'</strong> in topic <strong>'.$cur_post[0].'</strong><br />'."\n"; |
116 else |
119 else |
117 update_search_index('post', $cur_post[1], $cur_post[2]); |
120 update_search_index('post', $cur_post[1], $cur_post[2]); |
118 } |
121 } |
119 |
122 |
120 // Check if there is more work to do |
123 // Check if there is more work to do |
121 $result = $db->query('SELECT id FROM '.$db->prefix.'topics WHERE id>'.$end_at) or error('Unable to fetch topic info', __FILE__, __LINE__, $db->error()); |
124 $result = $pun_db->query('SELECT id FROM '.$pun_db->prefix.'topics WHERE id>'.$end_at) or error('Unable to fetch topic info', __FILE__, __LINE__, $pun_db->error()); |
122 |
125 |
123 $query_str = ($db->num_rows($result)) ? '?i_per_page='.$per_page.'&i_start_at='.$end_at : ''; |
126 $query_str = ($pun_db->num_rows($result)) ? '?i_per_page='.$per_page.'&i_start_at='.$end_at : ''; |
124 |
127 |
125 $db->end_transaction(); |
128 $pun_db->end_transaction(); |
126 $db->close(); |
129 $pun_db->close(); |
127 |
130 |
128 exit('<script type="text/javascript">window.location="admin_maintenance.php'.$query_str.'"</script><br />JavaScript redirect unsuccessful. Click <a href="admin_maintenance.php'.$query_str.'">here</a> to continue.'); |
131 exit('<script type="text/javascript">window.location="admin_maintenance.php'.$query_str.'"</script><br />JavaScript redirect unsuccessful. Click <a href="admin_maintenance.php'.$query_str.'">here</a> to continue.'); |
129 } |
132 } |
130 |
133 |
131 |
134 |
132 // Get the first post ID from the db |
135 // Get the first post ID from the db |
133 $result = $db->query('SELECT id FROM '.$db->prefix.'topics ORDER BY id LIMIT 1') or error('Unable to fetch topic info', __FILE__, __LINE__, $db->error()); |
136 $result = $pun_db->query('SELECT id FROM '.$pun_db->prefix.'topics ORDER BY id LIMIT 1') or error('Unable to fetch topic info', __FILE__, __LINE__, $pun_db->error()); |
134 if ($db->num_rows($result)) |
137 if ($pun_db->num_rows($result)) |
135 $first_id = $db->result($result); |
138 $first_id = $pun_db->result($result); |
136 |
139 |
137 $page_title = pun_htmlspecialchars($pun_config['o_board_title']).' / Admin / Maintenance'; |
140 $page_title = pun_htmlspecialchars($pun_config['o_board_title']).' / Admin / Maintenance'; |
138 require PUN_ROOT.'header.php'; |
141 require PUN_ROOT.'header.php'; |
139 |
142 |
140 generate_admin_menu('maintenance'); |
143 generate_admin_menu('maintenance'); |