Changeset 3 for branches/rsr.v5.1.dev/web/punbb/admin_maintenance.php
- Timestamp:
- Nov 14, 2011, 11:17:15 PM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/rsr.v5.1.dev/web/punbb/admin_maintenance.php
r1 r3 1 1 <?php 2 2 3 /*********************************************************************** 4 5 Copyright (C) 2002-2005 Rickard Andersson (rickard@punbb.org) 6 7 This file is part of PunBB. 8 9 PunBB is free software; you can redistribute it and/or modify it 10 under the terms of the GNU General Public License as published 11 by the Free Software Foundation; either version 2 of the License, 12 or (at your option) any later version. 13 14 PunBB is distributed in the hope that it will be useful, but 15 WITHOUT ANY WARRANTY; without even the implied warranty of 16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 GNU General Public License for more details. 18 19 You should have received a copy of the GNU General Public License 20 along with this program; if not, write to the Free Software 21 Foundation, Inc., 59 Temple Place, Suite 330, Boston, 22 MA 02111-1307 USA 23 24 ************************************************************************/ 25 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 */ 26 8 27 9 // Tell header.php to use the admin template … … 30 12 define('PUN_DISABLE_BUFFERING', 1); 31 13 32 define('PUN_ROOT', './');14 define('PUN_ROOT', dirname(__FILE__).'/'); 33 15 require PUN_ROOT.'include/common.php'; 34 16 require PUN_ROOT.'include/common_admin.php'; 35 17 36 if ($pun_user['g_id'] > PUN_ADMIN) 18 19 if ($pun_user['g_id'] != PUN_ADMIN) 37 20 message($lang_common['No permission']); 38 21 39 if (isset($_GET['i_per_page']) && isset($_GET['i_start_at'])) 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') 40 28 { 41 42 $per_page = intval($_GET['i_per_page']); 43 $start_at = intval($_GET['i_start_at']); 44 if ($per_page < 1 || $start_at < 1) 45 message($lang_common['Bad request']); 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']); 46 35 47 36 @set_time_limit(0); … … 53 42 confirm_referrer('admin_maintenance.php'); 54 43 55 $truncate_sql = ($db_type != 'sqlite') ? 'TRUNCATE TABLE ' : 'DELETE FROM '; 56 $db->query($truncate_sql.$db->prefix.'search_matches') or error('Impossible de vider la table search index match', __FILE__, __LINE__, $db->error()); 57 $db->query($truncate_sql.$db->prefix.'search_words') or error('Impossible de vider la table search index words', __FILE__, __LINE__, $db->error()); 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()); 58 46 59 47 // Reset the sequence for the search words (not needed for SQLite) … … 62 50 case 'mysql': 63 51 case 'mysqli': 64 $result = $db->query('ALTER TABLE '.$db->prefix.'search_words auto_increment=1') or error('Impossible de modifier l\'auto-incrémentation', __FILE__, __LINE__, $db->error()); 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()); 65 55 break; 66 56 67 57 case 'pgsql'; 68 $result = $db->query('SELECT setval(\' search_words_id_seq\', 1, false)') or error('Impossible de modifier la séquence', __FILE__, __LINE__, $db->error());69 } 70 } 71 72 $ end_at = $start_at + $per_page;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']); 73 63 74 64 ?> … … 77 67 <html> 78 68 <head> 79 <meta http-equiv="Content-Type" content="text/html; charset= iso-8859-1" />80 <title><?php echo pun_htmlspecialchars($pun_config['o_board_title']) ?> / Reconstruction des index de recherches ...</title>69 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 70 <title><?php echo generate_page_title($page_title) ?></title> 81 71 <style type="text/css"> 82 72 body { 83 font: 1 0px Verdana, Arial, Helvetica, sans-serif;73 font: 12px Verdana, Arial, Helvetica, sans-serif; 84 74 color: #333333; 85 75 background-color: #FFFFFF 76 } 77 78 h1 { 79 font-size: 16px; 80 font-weight: normal; 86 81 } 87 82 </style> … … 89 84 <body> 90 85 91 Reconstruction des index ... C'est peut être le bon moment pour aller prendre un café :-)<br /><br /> 92 93 <?php 86 <h1><?php echo $lang_admin_maintenance['Rebuilding index info'] ?></h1> 87 <hr /> 88 89 <?php 90 91 $query_str = ''; 94 92 95 93 require PUN_ROOT.'include/search_idx.php'; 96 94 97 // 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('Impossible de retrouver les informations des discussions et des messages', __FILE__, __LINE__, $db->error()); 99 100 $cur_topic = 0; 101 while ($cur_post = $db->fetch_row($result)) 102 { 103 if ($cur_post[0] <> $cur_topic) 104 { 105 // 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('Impossible de retrouver les informations des discussions', __FILE__, __LINE__, $db->error()); 107 list($first_post, $subject) = $db->fetch_row($result2); 108 109 $cur_topic = $cur_post[0]; 110 } 111 112 echo 'Traitement du message <strong>'.$cur_post[1].'</strong> de la discussion <strong>'.$cur_post[0].'</strong><br />'."\n"; 113 114 if ($cur_post[1] == $first_post) // This is the "topic post" so we have to index the subject as well 115 update_search_index('post', $cur_post[1], $cur_post[2], $subject); 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']); 116 105 else 117 update_search_index('post', $cur_post[1], $cur_post[2]); 106 update_search_index('post', $cur_item['id'], $cur_item['message']); 107 108 $end_at = $cur_item['id']; 118 109 } 119 110 120 111 // Check if there is more work to do 121 $result = $db->query('SELECT id FROM '.$db->prefix.'topics WHERE id>'.$end_at) or error('Impossible de retrouver les informations de discussions', __FILE__, __LINE__, $db->error()); 122 123 $query_str = ($db->num_rows($result)) ? '?i_per_page='.$per_page.'&i_start_at='.$end_at : ''; 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 } 124 119 125 120 $db->end_transaction(); 126 121 $db->close(); 127 122 128 exit('<script type="text/javascript">window.location="admin_maintenance.php'.$query_str.'"</script>< br />La redirection javaScript a échouée. <a href="admin_maintenance.php'.$query_str.'">Cliquez ici</a> pour continuer.');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>'); 129 124 } 130 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 131 242 132 243 // 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('Impossible de retrouver les informations de discussions', __FILE__, __LINE__, $db->error());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()); 134 245 if ($db->num_rows($result)) 135 246 $first_id = $db->result($result); 136 247 137 $page_title = pun_htmlspecialchars($pun_config['o_board_title']).' / Admin / Maintenance'; 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'); 138 250 require PUN_ROOT.'header.php'; 139 251 … … 142 254 ?> 143 255 <div class="blockform"> 144 <h2><span> Maintenance des Forums</span></h2>256 <h2><span><?php echo $lang_admin_maintenance['Maintenance head'] ?></span></h2> 145 257 <div class="box"> 146 258 <form method="get" action="admin_maintenance.php"> 147 259 <div class="inform"> 260 <input type="hidden" name="action" value="rebuild" /> 148 261 <fieldset> 149 <legend> Reconstruction des index de recherches</legend>262 <legend><?php echo $lang_admin_maintenance['Rebuild index subhead'] ?></legend> 150 263 <div class="infldset"> 151 <p> Si vous avez ajouté, modifié ou supprimé manuellement des messages dans la base de données ou si vous avez des problÚmes avec la recherche vous devriez reconstruire les index de recherche (supprime les mots inutiles). Pour de meilleures performances, pendant la reconstruction des index, vous devriez mettre vos forums en mode maintenance. <strong>La reconstruction des index de recherches peut prendre beaucoup de temps et augmenter considérablement la charge serveur au cours du processus de reconstruction !</strong></p>264 <p><?php printf($lang_admin_maintenance['Rebuild index info'], '<a href="admin_options.php#maintenance">'.$lang_admin_common['Maintenance mode'].'</a>') ?></p> 152 265 <table class="aligntop" cellspacing="0"> 153 266 <tr> 154 <th scope="row"> Discussions par cycle</th>155 <td> 156 <input type="text" name="i_per_page" size="7" maxlength="7" value=" 100" tabindex="1" />157 <span> Le nombre de discussions à traiter par cycle. Si vous saisissez 100, une centaine de discussions sera traitée et ensuite la page sera actualisée. Cela permet d'éviter que le script n'atteigne le temps limite d'exécution pendant le processus de recontruction.</span>158 </td> 159 </tr> 160 <tr> 161 <th scope="row"> ID de la discussion de départ</th>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> 162 275 <td> 163 276 <input type="text" name="i_start_at" size="7" maxlength="7" value="<?php echo (isset($first_id)) ? $first_id : 0 ?>" tabindex="2" /> 164 <span> L'ID de discussion de laquelle vous souhaitez lancer la reconstruction. La valeur par défaut est le premier ID diponible dans la base de données. Normalement vous ne devriez pas avoir à changer ceci.</span>165 </td> 166 </tr> 167 <tr> 168 <th scope="row"> Vider index</th>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> 169 282 <td class="inputadmin"> 170 <span><input type="checkbox" name="i_empty_index" value="1" tabindex="3" checked="checked" />   Cochez cette option si vous souhaitez que les index de recherches soient vidés avant la reconstruction (voir ci-dessous).</span>283 <span><input type="checkbox" name="i_empty_index" value="1" tabindex="3" checked="checked" />  <?php echo $lang_admin_maintenance['Empty index help'] ?></span> 171 284 </td> 172 285 </tr> 173 286 </table> 174 <p class="topspace">Lorsque le processus sera terminé vous serez redirigé sur cette page. Il est fortement recommandé que Javascript soit activé sur votre navigateur pour effectuer la reconstruction (pour une redirection automatique lorsqu'un cycle est achevé). Si vous êtes obligé d'abandonner le processus de reconstruction, notez l'ID du dernier sujet traité et saisissez cet ID+1 dans le champ "ID de la discussion de départ" quand/si vous reprennez le processus ("Vider index" ne doit pas être coché).</p> 175 <div class="fsetsubmit"><input type="submit" name="rebuild_index" value=" Reconstruire index " tabindex="4" /></div> 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> 176 348 </div> 177 349 </fieldset>
Note: See TracChangeset
for help on using the changeset viewer.