<?php
/**
* copyright : (C) 2001-2009 Advanced Internet Designs Inc.
* email : forum@prohost.org
* $Id: reindex.php,v 1.36 2009/02/16 05:37:11 frank Exp $
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; version 2 of the License.
**/
// this is the same file as indexdb.php, except CLI code is included
// Modified to allow throttling so the website can remain running.
// A config file is used to control reindexing speed. It is named
// reindex.ini, which has a single number in it - the delay after
// each insert into fud28_search_cache. The delay is expressed
// in seconds and can be less than 1, e.g. 0.25 or 0.5.
$default_throttle = 500000;
$configfile = "reindex.throttle";
@set_time_limit(0);
@ini_set("memory_limit", "100M");
require('./GLOBALS.php');
fud_use('adm_cli.inc', 1);
cli_execute(1);
fud_use('adm.inc', true);
fud_use('glob.inc', true);
fud_use('isearch.inc');
fud_use('fileio.inc');
fud_use('rev_fmt.inc');
if ($FUD_OPT_1 & 1) {
echo "\nDisabling the forum for the duration of maintenance run\n";
maintenance_status('Undergoing maintenance, please come back later.', 1);
}
echo "\nPlease wait while index is being rebuilt.\nThis may take a while depending on the size of your forum.";
ob_flush(); flush();
$tbl =& $DBHOST_TBL_PREFIX;
if (defined('forum_debug')) {
list($locale, $GLOBALS['usr']->lang) = db_saq("SELECT locale, lang FROM {$tbl}themes WHERE theme_opt & (1|2) LIMIT 1");
$GLOBALS['good_locale'] = setlocale(LC_ALL, $locale);
}
db_lock($tbl.'msg_store WRITE, '.$tbl.'search_cache WRITE, '.$tbl.'search WRITE, '.$tbl.'index WRITE, '.$tbl.'title_index WRITE, '.$tbl.'msg WRITE');
q('DELETE FROM '.$tbl.'search');
q('DELETE FROM '.$tbl.'index');
q('DELETE FROM '.$tbl.'title_index');
if (!($sid = q_singleval("SELECT MIN(query_type) FROM ".$tbl."search_cache WHERE srch_query='' AND query_type<0"))) {
q('DELETE FROM '.$tbl.'search_cache');
}
$i = 0;
$c = q('SELECT id, subject, length, foff, file_id FROM '.$tbl.'msg WHERE '.($sid ? ' id>'.$sid.' AND ' : '').' apr=1 ORDER BY subject');
$qty = mysql_num_rows($c);
echo "\n\nRe-indexing " . $qty . " messages.";
$old_subject = '';
while ($r = db_rowarr($c)) {
if ($old_subject != $r[1]) {
$subj = $old_subject = $r[1];
} else {
$subj = '';
}
q('INSERT INTO '.$tbl.'search_cache (srch_query, query_type, expiry, msg_id, n_match) VALUES(\'\', -'.$r[0].', 0,0,0)');
index_text($subj, read_msg_body($r[3], $r[2], $r[4]), $r[0]);
$i++;
db_unlock();
echo "\nProcessed " . $i;
// Throttling mechanism
$fud_reindex_delay = 0;
if (file_exists($configfile)) {
$config = fopen($configfile, "r");
$fud_reindex_delay = trim(fgets($config));
fclose($config);
}
if ($fud_reindex_delay > 0) {
$throttle = $fud_reindex_delay * 1000000;
} else {
$throttle = $default_throttle;
}
usleep($throttle); // Delay
db_lock($tbl.'msg_store WRITE, '.$tbl.'search_cache WRITE, '.$tbl.'search WRITE, '.$tbl.'index WRITE, '.$tbl.'title_index WRITE, '.$tbl.'msg WRITE');
}
unset($c);
q('DELETE FROM '.$tbl.'search_cache');
db_unlock();
echo "\n\nDone! All messages indexed\n";
if ($FUD_OPT_1 & 1) {
echo "\nRe-enabling the forum.\n";
maintenance_status($GLOBALS['DISABLED_REASON'], 0);
} else {
echo "\nYour forum is currently disabled, to re-enable it go to the Global Settings Manager and re-enable it.\n";
}
?>