2006-07-25 17:10:58 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
require_once('../config.php');
|
|
|
|
require_once("$CFG->dirroot/search/lib.php");
|
2006-09-20 21:00:45 +00:00
|
|
|
|
2006-08-16 13:34:07 +00:00
|
|
|
require_login();
|
|
|
|
|
2006-10-30 21:01:47 +00:00
|
|
|
if (empty($CFG->enableglobalsearch)) {
|
|
|
|
error('Global searching is not enabled.');
|
|
|
|
}
|
|
|
|
|
2006-08-16 13:34:07 +00:00
|
|
|
if (!isadmin()) {
|
|
|
|
error("You need to be an admin user to use this page.", "$CFG->wwwroot/login/index.php");
|
|
|
|
} //if
|
2006-09-20 21:00:45 +00:00
|
|
|
|
2006-08-16 13:34:07 +00:00
|
|
|
//check for php5 (lib.php)
|
|
|
|
if (!search_check_php5()) {
|
|
|
|
$phpversion = phpversion();
|
|
|
|
mtrace("Sorry, global search requires PHP 5.0.0 or later (currently using version $phpversion)");
|
|
|
|
exit(0);
|
2006-09-20 21:00:45 +00:00
|
|
|
} //if
|
|
|
|
|
|
|
|
require_once("$CFG->dirroot/search/indexlib.php");
|
|
|
|
|
2006-08-16 13:34:07 +00:00
|
|
|
$index = new Zend_Search_Lucene(SEARCH_INDEX_PATH);
|
|
|
|
$dbcontrol = new IndexDBControl();
|
2006-09-20 21:00:45 +00:00
|
|
|
$deletion_count = 0;
|
|
|
|
|
2006-08-16 13:34:07 +00:00
|
|
|
mtrace('<pre>Starting clean-up of removed records...');
|
2006-08-21 00:50:29 +00:00
|
|
|
mtrace('Index size before: '.$CFG->search_index_size."\n");
|
2006-09-20 21:00:45 +00:00
|
|
|
|
2006-07-25 17:10:58 +00:00
|
|
|
if ($mods = get_records_select('modules')) {
|
2006-08-21 00:50:29 +00:00
|
|
|
$mods = array_merge($mods, search_get_additional_modules());
|
2006-09-20 21:00:45 +00:00
|
|
|
|
2006-07-25 17:10:58 +00:00
|
|
|
foreach ($mods as $mod) {
|
2006-08-21 00:50:29 +00:00
|
|
|
//build function names
|
2006-07-25 17:10:58 +00:00
|
|
|
$class_file = $CFG->dirroot.'/search/documents/'.$mod->name.'_document.php';
|
2006-08-16 13:34:07 +00:00
|
|
|
$delete_function = $mod->name.'_delete';
|
|
|
|
$db_names_function = $mod->name.'_db_names';
|
2006-09-20 21:00:45 +00:00
|
|
|
$deletions = array();
|
|
|
|
|
2006-07-25 17:10:58 +00:00
|
|
|
if (file_exists($class_file)) {
|
2006-08-16 13:34:07 +00:00
|
|
|
require_once($class_file);
|
2006-09-20 21:00:45 +00:00
|
|
|
|
2006-08-16 13:34:07 +00:00
|
|
|
if (function_exists($delete_function) and function_exists($db_names_function)) {
|
|
|
|
mtrace("Checking $mod->name module for deletions.");
|
|
|
|
$values = $db_names_function();
|
2006-09-20 21:00:45 +00:00
|
|
|
|
2006-08-21 00:50:29 +00:00
|
|
|
$sql = "select id, docid from ".SEARCH_DATABASE_TABLE.
|
|
|
|
" where doctype like '$mod->name'".
|
|
|
|
" and docid not in".
|
|
|
|
" (select ".$values[0]." from ".$values[1].")";
|
2006-08-16 13:34:07 +00:00
|
|
|
|
2006-09-20 21:00:45 +00:00
|
|
|
$records = get_records_sql($sql);
|
|
|
|
|
2006-08-21 00:50:29 +00:00
|
|
|
//build an array of all the deleted records
|
2006-09-20 21:00:45 +00:00
|
|
|
if (is_array($records)) {
|
2006-08-16 13:34:07 +00:00
|
|
|
foreach($records as $record) {
|
|
|
|
$deletions[] = $delete_function($record->docid);
|
|
|
|
} //foreach
|
2006-09-20 21:00:45 +00:00
|
|
|
} //if
|
|
|
|
|
|
|
|
foreach ($deletions as $delete) {
|
2006-08-21 00:50:29 +00:00
|
|
|
//find the specific document in the index, using it's docid and doctype as keys
|
2006-09-20 21:00:45 +00:00
|
|
|
$doc = $index->find("+docid:$delete +doctype:$mod->name");
|
|
|
|
|
2006-08-16 13:34:07 +00:00
|
|
|
//get the record, should only be one
|
|
|
|
foreach ($doc as $thisdoc) {
|
|
|
|
++$deletion_count;
|
|
|
|
mtrace(" Delete: $thisdoc->title (database id = $thisdoc->dbid, index id = $thisdoc->id, moodle instance id = $thisdoc->docid)");
|
2006-09-20 21:00:45 +00:00
|
|
|
|
2006-08-21 00:50:29 +00:00
|
|
|
//remove it from index and database table
|
2006-08-16 13:34:07 +00:00
|
|
|
$dbcontrol->delDocument($thisdoc);
|
2006-09-20 21:00:45 +00:00
|
|
|
$index->delete($thisdoc->id);
|
2006-08-16 13:34:07 +00:00
|
|
|
} //foreach
|
|
|
|
} //foreach
|
2006-09-20 21:00:45 +00:00
|
|
|
|
2006-08-16 13:34:07 +00:00
|
|
|
mtrace("Finished $mod->name.\n");
|
2006-09-20 21:00:45 +00:00
|
|
|
} //if
|
2006-08-16 13:34:07 +00:00
|
|
|
} //if
|
2006-07-25 17:10:58 +00:00
|
|
|
} //foreach
|
|
|
|
} //if
|
2006-09-20 21:00:45 +00:00
|
|
|
|
2006-08-16 13:34:07 +00:00
|
|
|
//commit changes
|
|
|
|
$index->commit();
|
2006-09-20 21:00:45 +00:00
|
|
|
|
2006-08-21 00:50:29 +00:00
|
|
|
//update index date and index size
|
2006-08-16 13:34:07 +00:00
|
|
|
set_config("search_indexer_run_date", time());
|
2006-08-21 00:50:29 +00:00
|
|
|
set_config("search_index_size", (int)$CFG->search_index_size - (int)$deletion_count);
|
2006-07-25 17:10:58 +00:00
|
|
|
|
2006-08-16 13:34:07 +00:00
|
|
|
mtrace("Finished $deletion_count removals.");
|
|
|
|
mtrace('Index size after: '.$index->count().'</pre>');
|
2006-07-25 17:10:58 +00:00
|
|
|
|
|
|
|
?>
|