Fix a possible race condition in the PaintWeb DML code.
[moodle/mihaisucan.git] / search / tests / index.php
blob81e2daf9955dabd155861c038de2982b59f11ab7
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 /// makes inclusions of the Zend Engine more reliable
17 ini_set('include_path', $CFG->dirroot.DIRECTORY_SEPARATOR.'search'.PATH_SEPARATOR.ini_get('include_path'));
19 require_login();
21 if (empty($CFG->enableglobalsearch)) {
22 error('Global searching is not enabled.');
25 if (!has_capability('moodle/site:doanything', get_context_instance(CONTEXT_SYSTEM))) {
26 error("You need to be an admin user to use this page.", $CFG->wwwroot.'/login/index.php');
27 } //if
29 mtrace('<pre>Server Time: '.date('r',time()));
30 mtrace("Testing global search capabilities:\n");
32 $phpversion = phpversion();
34 //fix paths for testing
35 set_include_path(get_include_path().":../");
36 require_once($CFG->dirroot.'/search/Zend/Search/Lucene.php');
38 mtrace("Checking activity modules:\n");
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.
45 /// get all installed modules
46 if ($mods = get_records('modules', '', '', 'name', 'id,name')){
48 $searchabletypes = array_values(search_get_document_types());
50 foreach($mods as $mod){
51 if (in_array($mod->name, $searchabletypes)){
52 $mod->location = 'internal';
53 $searchables[] = $mod;
54 } else {
55 $documentfile = $CFG->dirroot."/mod/{$mod->name}/search_document.php";
56 $mod->location = 'mod';
57 if (file_exists($documentfile)){
58 $searchables[] = $mod;
62 mtrace(count($searchables).' modules to search in / '.count($mods).' modules found.');
65 /// collects blocks as indexable information may be found in blocks either
66 if ($blocks = get_records('block', '', '', 'name', 'id,name')) {
67 $blocks_searchables = array();
68 // prepend the "block_" prefix to discriminate document type plugins
69 foreach($blocks as $block){
70 $block->dirname = $block->name;
71 $block->name = 'block_'.$block->name;
72 if (in_array('SEARCH_TYPE_'.strtoupper($block->name), $searchabletypes)){
73 $mod->location = 'internal';
74 $blocks_searchables[] = $block;
75 } else {
76 $documentfile = $CFG->dirroot."/blocks/{$block->dirname}/search_document.php";
77 if (file_exists($documentfile)){
78 $mod->location = 'blocks';
79 $blocks_searchables[] = $block;
83 mtrace(count($blocks_searchables).' blocks to search in / '.count($blocks).' blocks found.');
84 $searchables = array_merge($searchables, $blocks_searchables);
87 /// add virtual modules onto the back of the array
89 $additional = search_get_additional_modules();
90 mtrace(count($additional).' additional to search in.');
91 $searchables = array_merge($searchables, $additional);
93 foreach ($searchables as $mod) {
95 $key = 'search_in_'.$mod->name;
96 if (isset($CFG->$key) && !$CFG->$key) {
97 mtrace("module $key has been administratively disabled. Skipping...\n");
98 continue;
101 if ($mod->location == 'internal'){
102 $class_file = $CFG->dirroot.'/search/documents/'.$mod->name.'_document.php';
103 } else {
104 $class_file = $CFG->dirroot.'/'.$mod->location.'/'.$mod->name.'/search_document.php';
107 if (file_exists($class_file)) {
108 include_once($class_file);
110 if ($mod->location != 'internal' && !defined('X_SEARCH_TYPE_'.strtoupper($mod->name))) {
111 mtrace("ERROR: Constant 'X_SEARCH_TYPE_".strtoupper($mod->name)."' is not defined in search/searchtypes.php or in module");
112 continue;
115 $iter_function = $mod->name.'_iterator';
116 $index_function = $mod->name.'_get_content_for_index';
118 if (function_exists($index_function) && function_exists($iter_function)) {
119 $entries = $iter_function();
120 if (!empty($entries)) {
121 $documents = $index_function(array_pop($entries));
123 if (is_array($documents)) {
124 mtrace("Success: '$mod->name' module seems to be ready for indexing.");
125 } else {
126 mtrace("ERROR: $index_function() doesn't seem to be returning an array.");
128 } else {
129 mtrace("Success : '$mod->name' has nothing to index.");
131 } else {
132 mtrace("ERROR: $iter_function() and/or $index_function() does not exist in $class_file");
134 } else {
135 mtrace("Notice: $class_file does not exist, this module will not be indexed.");
139 //finished modules
140 mtrace("\nFinished checking activity modules.");
142 //now blocks...
145 mtrace("<br/><a href='../index.php'>Back to query page</a> or <a href='../indexersplash.php'>Start indexing</a>.");
146 mtrace('</pre>');