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