Search functions moved from mod/name/lib.php to search/documents/mod_document.php.
[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')) {
46 foreach ($mods as $mod) {
47 $class_file = $CFG->dirroot.'/search/documents/'.$mod->name.'_document.php';
48
49 if (file_exists($class_file)) {
50 include_once($class_file);
51
52 if (!defined('SEARCH_'.strtoupper($mod->name).'_TYPE')) {
53 mtrace("ERROR: Constant 'SEARCH_".strtoupper($mod->name)."_TYPE' is not defined in /search/lib.php");
54 continue;
55 } //if
56
57 $iter_function = $mod->name.'_iterator';
58 $index_function = $mod->name.'_get_content_for_index';
59
60 if (function_exists($index_function) && function_exists($iter_function)) {
61 if (is_array($iter_function())) {
62 $documents = $index_function(array_pop($iter_function()));
63
64 if (is_array($documents)) {
65 mtrace("Success: '$mod->name' module seems to be ready for indexing.");
66 } else {
67 mtrace("ERROR: $index_function() doesn't seem to be returning an array.");
68 } //else
69 } else {
70 mtrace("ERROR: $iter_function() doesn't seem to be returning an object array.");
71 } //else
72 } else {
73 mtrace("ERROR: $iter_function() and/or $index_function() does not exist in $class_file");
74 } //else
75 } else {
76 mtrace("Notice: $class_file does not exist, this module will not be indexed.");
77 } //else
78 } //foreach
79 } //if
80
81 //finished modules
82 mtrace("\nFinished checking activity modules.");
83
84 //now blocks...
85 //
86
87 mtrace("<br><a href='../index.php'>Back to query page</a> or <a href='../indexersplash.php'>Start indexing</a>.");
88 mtrace('</pre>');
89
90?>