fixing header/formatting
[moodle.git] / search / tests / index.php
CommitLineData
a25a3912 1<?php
2
3 /* Used to test if modules/blocks are ready to included in the search index.
4 * Carries out some basic function/file existence tests - the search module
5 * is expected to exist, along with the db schema files and the search data
6 * directory.
7 * */
eef868d1 8
d052434c 9@set_time_limit(0);
10@ob_implicit_flush(true);
11@ob_end_flush();
12
13require_once('../../config.php');
14require_once("$CFG->dirroot/search/lib.php");
15
16require_login();
17
18$strsearch = get_string('search', 'search');
19$strquery = get_string('stats');
20
21$navlinks[] = array('name' => $strsearch, 'link' => "../index.php", 'type' => 'misc');
22$navlinks[] = array('name' => $strquery, 'link' => "../stats.php", 'type' => 'misc');
23$navlinks[] = array('name' => get_string('runindexertest','search'), 'link' => null, 'type' => 'misc');
24$navigation = build_navigation($navlinks);
25$site = get_site();
26print_header("$strsearch", "$site->fullname" , $navigation, "", "", true, "&nbsp;", navmenu($site));
27
28if (empty($CFG->enableglobalsearch)) {
721d74b0 29 error('Global searching is not enabled.');
d052434c 30}
721d74b0 31
d052434c 32if (!isadmin()) {
a25a3912 33 error("You need to be an admin user to use this page.", "$CFG->wwwroot/login/index.php");
d052434c 34} //if
eef868d1 35
d052434c 36mtrace('<pre>Server Time: '.date('r',time()));
37mtrace("Testing global search capabilities:\n");
eef868d1 38
d052434c 39$phpversion = phpversion();
eef868d1 40
d052434c 41if (!search_check_php5()) {
a25a3912 42 mtrace("ERROR: PHP 5.0.0 or later required (currently using version $phpversion).");
43 exit(0);
d052434c 44} else {
a25a3912 45 mtrace("Success: PHP 5.0.0 or later is installed ($phpversion).\n");
d052434c 46} //else
a25a3912 47
d052434c 48//fix paths for testing
49set_include_path(get_include_path().":../");
50require_once("$CFG->dirroot/search/Zend/Search/Lucene.php");
eef868d1 51
d052434c 52mtrace("Checking activity modules:\n");
eef868d1 53
d052434c 54//the presence of the required search functions -
55// * mod_iterator
56// * mod_get_content_for_index
57//are the sole basis for including a module in the index at the moment.
eef868d1 58
d052434c 59if ($mods = get_records_select('modules')) {
c629cfed 60 $mods = array_merge($mods, search_get_additional_modules());
eef868d1 61
a25a3912 62 foreach ($mods as $mod) {
d052434c 63 $class_file = $CFG->dirroot.'/search/documents/'.$mod->name.'_document.php';
64
65 if (file_exists($class_file)) {
66 include_once($class_file);
67
68 if (!defined('SEARCH_TYPE_'.strtoupper($mod->name))) {
69 mtrace("ERROR: Constant 'SEARCH_TYPE_".strtoupper($mod->name)."' is not defined in /search/lib.php");
70 continue;
71 } //if
72
73 $iter_function = $mod->name.'_iterator';
74 $index_function = $mod->name.'_get_content_for_index';
75
76 if (function_exists($index_function) && function_exists($iter_function)) {
77 if (is_array($iter_function())) {
78 $documents = $index_function(array_pop($iter_function()));
79
80 if (is_array($documents)) {
81 mtrace("Success: '$mod->name' module seems to be ready for indexing.");
82 } else {
83 mtrace("ERROR: $index_function() doesn't seem to be returning an array.");
84 } //else
85 } else {
86 mtrace("ERROR: $iter_function() doesn't seem to be returning an object array.");
87 } //else
a25a3912 88 } else {
d052434c 89 mtrace("ERROR: $iter_function() and/or $index_function() does not exist in $class_file");
a25a3912 90 } //else
a25a3912 91 } else {
d052434c 92 mtrace("Notice: $class_file does not exist, this module will not be indexed.");
a25a3912 93 } //else
a25a3912 94 } //foreach
d052434c 95} //if
eef868d1 96
d052434c 97//finished modules
98mtrace("\nFinished checking activity modules.");
eef868d1 99
d052434c 100//now blocks...
101//
a25a3912 102
d052434c 103mtrace("<br/><a href='../index.php'>Back to query page</a> or <a href='../indexersplash.php'>Start indexing</a>.");
104mtrace('</pre>');
105print_footer();
a25a3912 106?>