MDL-10604:
[moodle-linuxchix.git] / search / tests / index.php
blobd31cd734672c5375d9c8ca5ced7e5f759408b6ee
1 <?php
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 * */
9 @set_time_limit(0);
10 @ob_implicit_flush(true);
11 @ob_end_flush();
13 require_once('../../config.php');
14 require_once("$CFG->dirroot/search/lib.php");
16 require_login();
18 if (empty($CFG->enableglobalsearch)) {
19 error('Global searching is not enabled.');
22 if (!isadmin()) {
23 error("You need to be an admin user to use this page.", "$CFG->wwwroot/login/index.php");
24 } //if
26 mtrace('<pre>Server Time: '.date('r',time()));
27 mtrace("Testing global search capabilities:\n");
29 $phpversion = phpversion();
31 if (!search_check_php5()) {
32 mtrace("ERROR: PHP 5.0.0 or later required (currently using version $phpversion).");
33 exit(0);
34 } else {
35 mtrace("Success: PHP 5.0.0 or later is installed ($phpversion).\n");
36 } //else
38 //fix paths for testing
39 set_include_path(get_include_path().":../");
40 require_once("$CFG->dirroot/search/Zend/Search/Lucene.php");
42 mtrace("Checking activity modules:\n");
44 //the presence of the required search functions -
45 // * mod_iterator
46 // * mod_get_content_for_index
47 //are the sole basis for including a module in the index at the moment.
49 if ($mods = get_records_select('modules')) {
50 $mods = array_merge($mods, search_get_additional_modules());
52 foreach ($mods as $mod) {
53 $class_file = $CFG->dirroot.'/search/documents/'.$mod->name.'_document.php';
55 if (file_exists($class_file)) {
56 include_once($class_file);
58 if (!defined('SEARCH_TYPE_'.strtoupper($mod->name))) {
59 mtrace("ERROR: Constant 'SEARCH_TYPE_".strtoupper($mod->name)."' is not defined in /search/lib.php");
60 continue;
61 } //if
63 $iter_function = $mod->name.'_iterator';
64 $index_function = $mod->name.'_get_content_for_index';
66 if (function_exists($index_function) && function_exists($iter_function)) {
67 if (is_array($iter_function())) {
68 $documents = $index_function(array_pop($iter_function()));
70 if (is_array($documents)) {
71 mtrace("Success: '$mod->name' module seems to be ready for indexing.");
72 } else {
73 mtrace("ERROR: $index_function() doesn't seem to be returning an array.");
74 } //else
75 } else {
76 mtrace("ERROR: $iter_function() doesn't seem to be returning an object array.");
77 } //else
78 } else {
79 mtrace("ERROR: $iter_function() and/or $index_function() does not exist in $class_file");
80 } //else
81 } else {
82 mtrace("Notice: $class_file does not exist, this module will not be indexed.");
83 } //else
84 } //foreach
85 } //if
87 //finished modules
88 mtrace("\nFinished checking activity modules.");
90 //now blocks...
93 mtrace("<br/><a href='../index.php'>Back to query page</a> or <a href='../indexersplash.php'>Start indexing</a>.");
94 mtrace('</pre>');