2 /***********************************************************************
4 Copyright (C) 2002-2005 Rickard Andersson (rickard@punbb.org)
6 This file is part of PunBB.
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.
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.
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,
23 ************************************************************************/
26 // Tell header.php to use the admin template
27 define('PUN_ADMIN_CONSOLE', 1);
28 // Tell common.php that we don't want output buffering
29 define('PUN_DISABLE_BUFFERING', 1);
31 define('PUN_ROOT', './');
32 require PUN_ROOT
.'include/common.php';
33 require PUN_ROOT
.'include/common_admin.php';
36 if ($pun_user['g_id'] > PUN_ADMIN
)
37 message($lang_common['No permission']);
40 if (isset($_GET['i_per_page']) && isset($_GET['i_start_at']))
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']);
49 // If this is the first cycle of posts we empty the search index before we proceed
50 if (isset($_GET['i_empty_index']))
52 // This is the only potentially "dangerous" thing we can do here, so we check the referer
53 confirm_referrer('admin_maintenance.php');
55 $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());
57 $db->query($truncate_sql.$db->prefix
.'search_words') or error('Unable to empty search index words table', __FILE__
, __LINE__
, $db->error());
59 // Reset the sequence for the search words (not needed for SQLite)
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());
68 $result = $db->query('SELECT setval(\''.$db->prefix
.'search_words_id_seq\', 1, false)') or error('Unable to update sequence', __FILE__
, __LINE__
, $db->error());
73 <!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
77 <meta http
-equiv
="Content-Type" content
="text/html; charset=UTF-8" />
78 <title
><?php
echo pun_htmlspecialchars($pun_config['o_board_title']) ?
> / Reconstruction des index de recherches
...</title
>
79 <style type
="text/css">
81 font
: 10px Verdana
, Arial
, Helvetica
, sans
-serif
;
83 background
-color
: #FFFFFF
89 Reconstruction des index
... C
'est peut être le bon moment pour aller prendre un café :-)<br /><br />
93 require PUN_ROOT.'include/search_idx
.php
';
95 // Fetch posts to process
96 $result = $db->query('SELECT id FROM
'.$db->prefix.'topics WHERE id
>='.$start_at.' ORDER BY id LIMIT
'.$per_page) or error('Unable to fetch topic
list', __FILE__, __LINE__, $db->error());
98 while ($cur_topic = $db->fetch_row($result))
99 $topics[] = $cur_topic[0];
101 $result = $db->query('SELECT topic_id
, id
, message FROM
'.$db->prefix.'posts WHERE topic_id
IN ('.implode(',', $topics).') ORDER BY topic_id
') or error('Unable to fetch topic
/post info
', __FILE__, __LINE__, $db->error());
104 while ($cur_post = $db->fetch_row($result))
106 if ($cur_post[0] <> $cur_topic)
108 // Fetch subject and ID of first post in topic
109 $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());
110 list($first_post, $subject) = $db->fetch_row($result2);
112 $cur_topic = $cur_post[0];
115 echo 'Traitement du message
<strong
>'.$cur_post[1].'</strong
> de la discussion
<strong
>'.$cur_post[0].'</strong
><br
/>'."\n";
117 if ($cur_post[1] == $first_post) // This is the "topic post" so we have to index the subject as well
118 update_search_index('post
', $cur_post[1], $cur_post[2], $subject);
120 update_search_index('post
', $cur_post[1], $cur_post[2]);
123 // Check if there is more work to do
124 $result = $db->query('SELECT id FROM
'.$db->prefix.'topics WHERE id
>'.$cur_topic.' ORDER BY id ASC LIMIT
1') or error('Unable to fetch topic info
', __FILE__, __LINE__, $db->error());
126 $query_str = ($db->num_rows($result)) ? '?i_per_page
='.$per_page.'&i_start_at
='.$db->result($result) : '';
128 $db->end_transaction();
131 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
.');
135 // Get the first post ID from the db
136 $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());
137 if ($db->num_rows($result))
138 $first_id = $db->result($result);
140 $page_title = pun_htmlspecialchars($pun_config['o_board_title
']).' / Admin
/ Maintenance
';
141 require PUN_ROOT.'header
.php
';
143 generate_admin_menu('maintenance
');
146 <div class="blockform">
147 <h2><span>Maintenance des Forums</span></h2>
149 <form method="get" action="admin_maintenance.php">
152 <legend>Reconstruction des index de recherches</legend>
153 <div class="infldset">
154 <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>
155 <table class="aligntop" cellspacing="0">
157 <th scope="row">Discussions par cycle</th>
159 <input type="text" name="i_per_page" size="7" maxlength="7" value="100" tabindex="1" />
160 <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 reconstruction
.</span
>
164 <th scope
="row">ID de la discussion de départ
</th
>
166 <input type
="text" name
="i_start_at" size
="7" maxlength
="7" value
="<?php echo (isset($first_id)) ? $first_id : 0 ?>" tabindex
="2" />
167 <span
>L
'ID de discussion de laquelle vous souhaitez lancer la reconstruction. La valeur par défaut est le premier ID disponible dans la base de données. Normalement vous ne devriez pas avoir à changer ceci.</span>
171 <th scope="row">Vider index</th>
172 <td class="inputadmin">
173 <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>
177 <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
>
178 <div
class="fsetsubmit"><input type
="submit" name
="rebuild_index" value
=" Reconstruire index " tabindex
="4" /></div
>
185 <div
class="clearer"></div
>
189 require PUN_ROOT
.'footer.php';