PUN_ADMIN)
message($lang_common['No permission']);
if (isset($_GET['i_per_page']) && isset($_GET['i_start_at']))
{
$per_page = intval($_GET['i_per_page']);
$start_at = intval($_GET['i_start_at']);
if ($per_page < 1 || $start_at < 1)
message($lang_common['Bad request']);
@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');
$truncate_sql = ($db_type != 'sqlite') ? 'TRUNCATE TABLE ' : 'DELETE FROM ';
$db->query($truncate_sql.$db->prefix.'search_matches') or error('Impossible de vider la table search index match', __FILE__, __LINE__, $db->error());
$db->query($truncate_sql.$db->prefix.'search_words') or error('Impossible de vider la table search index words', __FILE__, __LINE__, $db->error());
// Reset the sequence for the search words (not needed for SQLite)
switch ($db_type)
{
case 'mysql':
case 'mysqli':
$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());
break;
case 'pgsql';
$result = $db->query('SELECT setval(\'search_words_id_seq\', 1, false)') or error('Impossible de modifier la séquence', __FILE__, __LINE__, $db->error());
}
}
$end_at = $start_at + $per_page;
?>
/ Reconstruction des index de recherches ...
Reconstruction des index ... C'est peut être le bon moment pour aller prendre un café :-)
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());
$cur_topic = 0;
while ($cur_post = $db->fetch_row($result))
{
if ($cur_post[0] <> $cur_topic)
{
// Fetch subject and ID of first post in topic
$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());
list($first_post, $subject) = $db->fetch_row($result2);
$cur_topic = $cur_post[0];
}
echo 'Traitement du message '.$cur_post[1].' de la discussion '.$cur_post[0].'
'."\n";
if ($cur_post[1] == $first_post) // This is the "topic post" so we have to index the subject as well
update_search_index('post', $cur_post[1], $cur_post[2], $subject);
else
update_search_index('post', $cur_post[1], $cur_post[2]);
}
// Check if there is more work to do
$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());
$query_str = ($db->num_rows($result)) ? '?i_per_page='.$per_page.'&i_start_at='.$end_at : '';
$db->end_transaction();
$db->close();
exit('
La redirection javaScript a échouée. Cliquez ici pour continuer.');
}
// Get the first post ID from the db
$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());
if ($db->num_rows($result))
$first_id = $db->result($result);
$page_title = pun_htmlspecialchars($pun_config['o_board_title']).' / Admin / Maintenance';
require PUN_ROOT.'header.php';
generate_admin_menu('maintenance');
?>