|
1 <?php |
|
2 /*********************************************************************** |
|
3 |
|
4 Copyright (C) 2002-2008 PunBB.org |
|
5 |
|
6 This file is part of PunBB. |
|
7 |
|
8 PunBB is free software; you can redistribute it and/or modify it |
|
9 under the terms of the GNU General Public License as published |
|
10 by the Free Software Foundation; either version 2 of the License, |
|
11 or (at your option) any later version. |
|
12 |
|
13 PunBB is distributed in the hope that it will be useful, but |
|
14 WITHOUT ANY WARRANTY; without even the implied warranty of |
|
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
16 GNU General Public License for more details. |
|
17 |
|
18 You should have received a copy of the GNU General Public License |
|
19 along with this program; if not, write to the Free Software |
|
20 Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
|
21 MA 02111-1307 USA |
|
22 |
|
23 ************************************************************************/ |
|
24 |
|
25 |
|
26 if (!defined('PUN_ROOT')) |
|
27 define('PUN_ROOT', '../'); |
|
28 |
|
29 // Tell common.php that we don't want output buffering |
|
30 define('PUN_DISABLE_BUFFERING', 1); |
|
31 |
|
32 require PUN_ROOT.'include/common.php'; |
|
33 require PUN_ROOT.'include/common_admin.php'; |
|
34 |
|
35 // import globals (I really hope this isn't dangerous) |
|
36 foreach ( $GLOBALS as $key => $_ ) |
|
37 { |
|
38 $$key =& $GLOBALS[$key]; |
|
39 } |
|
40 |
|
41 ($hook = get_hook('ari_start')) ? eval($hook) : null; |
|
42 |
|
43 if ($session->user_level < USER_LEVEL_ADMIN) |
|
44 message($lang_common['No permission']); |
|
45 |
|
46 // The reindexer isn't used for MySQL |
|
47 if ($db_type == 'mysql' || $db_type == 'mysqli') |
|
48 message($lang_common['Bad request']); |
|
49 |
|
50 // Load the admin.php language file |
|
51 require PUN_ROOT.'lang/'.$pun_user['language'].'/admin.php'; |
|
52 $GLOBALS['lang_admin'] = $lang_admin; |
|
53 |
|
54 |
|
55 if (isset($_GET['i_per_page']) && isset($_GET['i_start_at'])) |
|
56 { |
|
57 $per_page = intval($_GET['i_per_page']); |
|
58 $start_at = intval($_GET['i_start_at']); |
|
59 if ($per_page < 1 || $start_at < 1) |
|
60 message($lang_common['Bad request']); |
|
61 |
|
62 ($hook = get_hook('ari_cycle_start')) ? eval($hook) : null; |
|
63 |
|
64 @set_time_limit(0); |
|
65 |
|
66 // If this is the first cycle of posts we empty the search index before we proceed |
|
67 if (isset($_GET['i_empty_index'])) |
|
68 { |
|
69 $query = array( |
|
70 'DELETE' => 'search_matches' |
|
71 ); |
|
72 |
|
73 ($hook = get_hook('ari_qr_empty_search_matches')) ? eval($hook) : null; |
|
74 $pun_db->query_build($query) or error(__FILE__, __LINE__); |
|
75 |
|
76 $query = array( |
|
77 'DELETE' => 'search_words' |
|
78 ); |
|
79 |
|
80 ($hook = get_hook('ari_qr_empty_search_words')) ? eval($hook) : null; |
|
81 $pun_db->query_build($query) or error(__FILE__, __LINE__); |
|
82 |
|
83 // Reset the sequence for the search words (not needed for SQLite) |
|
84 if ($db_type == 'pgsql') |
|
85 $result = $pun_db->query('SELECT setval(\''.$pun_db->prefix.'search_words_id_seq\', 1, false)') or error(__FILE__, __LINE__); |
|
86 } |
|
87 |
|
88 ?> |
|
89 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> |
|
90 |
|
91 <html lang="<?php $lang_common['lang_identifier'] ?>" dir="<?php echo $lang_common['lang_direction'] ?>"> |
|
92 <head> |
|
93 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> |
|
94 |
|
95 <title><?php echo htmlspecialchars($pun_config['o_board_title']) ?> - Rebuilding search index …</title> |
|
96 <style type="text/css"> |
|
97 body { |
|
98 font: 68.75% Verdana, Arial, Helvetica, sans-serif; |
|
99 color: #333333; |
|
100 background-color: #FFFFFF |
|
101 } |
|
102 </style> |
|
103 </head> |
|
104 <body> |
|
105 |
|
106 <p><?php echo $lang_admin['Rebuilding index'] ?></p> |
|
107 |
|
108 <?php |
|
109 |
|
110 require PUN_ROOT.'include/search_idx.php'; |
|
111 |
|
112 // Fetch posts to process |
|
113 $query = array( |
|
114 'SELECT' => 'p.id, p.message, t.id, t.subject, t.first_post_id', |
|
115 'FROM' => 'posts AS p', |
|
116 'JOINS' => array( |
|
117 array( |
|
118 'INNER JOIN' => 'topics AS t', |
|
119 'ON' => 't.id=p.topic_id' |
|
120 ) |
|
121 ), |
|
122 'WHERE' => 'p.id>='.$start_at, |
|
123 'ORDER BY' => 'p.id', |
|
124 'LIMIT' => $per_page |
|
125 ); |
|
126 |
|
127 ($hook = get_hook('ari_qr_fetch_posts')) ? eval($hook) : null; |
|
128 $result = $pun_db->query_build($query) or error(__FILE__, __LINE__); |
|
129 |
|
130 $post_id = 0; |
|
131 echo '<p>'; |
|
132 while ($cur_post = $pun_db->fetch_row($result)) |
|
133 { |
|
134 printf($lang_admin['Processing post'], $cur_post[0], $cur_post[2]).'<br />'."\n"; |
|
135 |
|
136 if ($cur_post[0] == $cur_post[4]) // This is the "topic post" so we have to index the subject as well |
|
137 update_search_index('post', $cur_post[0], $cur_post[1], $cur_post[3]); |
|
138 else |
|
139 update_search_index('post', $cur_post[0], $cur_post[1]); |
|
140 |
|
141 $post_id = $cur_post[0]; |
|
142 } |
|
143 echo '</p>'; |
|
144 |
|
145 // Check if there is more work to do |
|
146 $query = array( |
|
147 'SELECT' => 'p.id', |
|
148 'FROM' => 'posts AS p', |
|
149 'WHERE' => 'p.id>'.$post_id, |
|
150 'ORDER BY' => 'p.id', |
|
151 'LIMIT' => '1' |
|
152 ); |
|
153 |
|
154 ($hook = get_hook('ari_qr_find_next_post')) ? eval($hook) : null; |
|
155 $result = $pun_db->query_build($query) or error(__FILE__, __LINE__); |
|
156 |
|
157 $query_str = ($pun_db->num_rows($result)) ? '?i_per_page='.$per_page.'&i_start_at='.$pun_db->result($result) : ''; |
|
158 |
|
159 ($hook = get_hook('ari_cycle_end')) ? eval($hook) : null; |
|
160 |
|
161 $pun_db->end_transaction(); |
|
162 $pun_db->close(); |
|
163 |
|
164 exit('<script type="text/javascript">window.location="'.pun_link($pun_url['admin_reindex']).$query_str.'"</script><br />'.$lang_admin['Javascript redirect'].' <a href="'.pun_link($pun_url['admin_reindex']).$query_str.'">'.$lang_admin['Click to continue'].'</a>.'); |
|
165 } |
|
166 |
|
167 |
|
168 // Get the first post ID from the db |
|
169 $query = array( |
|
170 'SELECT' => 'p.id', |
|
171 'FROM' => 'posts AS p', |
|
172 'ORDER BY' => 'p.id', |
|
173 'LIMIT' => '1' |
|
174 ); |
|
175 |
|
176 ($hook = get_hook('ari_qr_find_lowest_post_id')) ? eval($hook) : null; |
|
177 $result = $pun_db->query_build($query) or error(__FILE__, __LINE__); |
|
178 if ($pun_db->num_rows($result)) |
|
179 $first_id = $pun_db->result($result); |
|
180 |
|
181 // Setup form |
|
182 $pun_page['set_count'] = $pun_page['fld_count'] = 0; |
|
183 |
|
184 // Setup breadcrumbs |
|
185 $pun_page['crumbs'] = array( |
|
186 array($pun_config['o_board_title'], pun_link($pun_url['index'])), |
|
187 array($lang_admin['Forum administration'], pun_link($pun_url['admin_index'])), |
|
188 $lang_admin['Rebuild index'] |
|
189 ); |
|
190 |
|
191 define('PUN_PAGE_SECTION', 'management'); |
|
192 define('PUN_PAGE', 'admin-reindex'); |
|
193 require PUN_ROOT.'header.php'; |
|
194 |
|
195 ?> |
|
196 <div id="pun-main" class="main sectioned admin"> |
|
197 |
|
198 <?php echo generate_admin_menu(); ?> |
|
199 |
|
200 <div class="main-head"> |
|
201 <h1><span>{ <?php echo end($pun_page['crumbs']) ?> }</span></h1> |
|
202 </div> |
|
203 |
|
204 <div class="main-content frm"> |
|
205 <div class="frm-head"> |
|
206 <h2><span><?php echo $lang_admin['Reindex heading'] ?></span></h2> |
|
207 </div> |
|
208 <div class="frm-info"> |
|
209 <p><?php echo $lang_admin['Reindex info'] ?></p> |
|
210 </div> |
|
211 <form class="frm-form" method="get" accept-charset="utf-8" action="<?php echo pun_link($pun_url['admin_reindex']) ?>"> |
|
212 <div class="hidden"> |
|
213 <input type="hidden" name="csrf_token" value="<?php echo generate_form_token(pun_link($pun_url['admin_reindex'])) ?>" /> |
|
214 </div> |
|
215 <?php ($hook = get_hook('ari_pre_rebuild_fieldset')) ? eval($hook) : null; ?> |
|
216 <fieldset class="frm-set set<?php echo ++$pun_page['set_count'] ?>"> |
|
217 <legend class="frm-legend"><span><?php echo $lang_admin['Rebuild index legend'] ?></span></legend> |
|
218 <?php ($hook = get_hook('ari_pre_per_page')) ? eval($hook) : null; ?> |
|
219 <div class="frm-fld text"> |
|
220 <label for="fld<?php echo ++$pun_page['fld_count'] ?>"> |
|
221 <span class="fld-label"><?php echo $lang_admin['Posts per cycle'] ?></span><br /> |
|
222 <span class="fld-input"><input type="text" id="fld<?php echo $pun_page['fld_count'] ?>" name="i_per_page" size="7" maxlength="7" value="100" /></span> |
|
223 <span class="fld-help"><?php echo $lang_admin['Posts per cycle info'] ?></span> |
|
224 </label> |
|
225 </div> |
|
226 <div class="frm-fld text"> |
|
227 <label for="fld<?php echo ++$pun_page['fld_count'] ?>"> |
|
228 <span class="fld-label"><?php echo $lang_admin['Starting post'] ?></span><br /> |
|
229 <span class="fld-input"><input type="text" id="fld<?php echo $pun_page['fld_count'] ?>" name="i_start_at" size="7" maxlength="7" value="<?php echo (isset($first_id)) ? $first_id : 0 ?>" /></span> |
|
230 <span class="fld-help"><?php echo $lang_admin['Starting post info'] ?></span> |
|
231 </label> |
|
232 </div> |
|
233 <div class="radbox checkbox"> |
|
234 <label for="fld<?php echo ++$pun_page['fld_count'] ?>"><span class="fld-label"><?php echo $lang_admin['Empty index'] ?></span><br /><input type="checkbox" id="fld<?php echo $pun_page['fld_count'] ?>" name="i_empty_index" value="1" checked="checked" /> <?php echo $lang_admin['Empty index info'] ?></label> |
|
235 </div> |
|
236 <?php ($hook = get_hook('ari_rebuild_end')) ? eval($hook) : null; ?> |
|
237 </fieldset> |
|
238 <?php ($hook = get_hook('ari_pre_infobox')) ? eval($hook) : null; ?> |
|
239 <div class="frm-info"> |
|
240 <p class="important"><?php echo $lang_admin['Reindex warning'] ?></p> |
|
241 <p class="warn"><?php echo $lang_admin['Empty index warning'] ?></p> |
|
242 </div> |
|
243 <div class="frm-buttons"> |
|
244 <span class="submit"><input type="submit" name="rebuild_index" value="<?php echo $lang_admin['Rebuild index'] ?>" /></span> |
|
245 </div> |
|
246 </form> |
|
247 </div> |
|
248 |
|
249 </div> |
|
250 <?php |
|
251 |
|
252 require PUN_ROOT.'footer.php'; |