From 4b3d092ec204901198028f0a4d17f11db925e552 Mon Sep 17 00:00:00 2001 From: diml Date: Mon, 23 Mar 2009 20:43:38 +0000 Subject: [PATCH] Addresses the tracker MDL - 18638 --- search/tests/index.php | 103 +++++++++++++++++++++++------------------ 1 file changed, 58 insertions(+), 45 deletions(-) diff --git a/search/tests/index.php b/search/tests/index.php index 9b7cb7a7d1..541f476796 100644 --- a/search/tests/index.php +++ b/search/tests/index.php @@ -1,9 +1,20 @@ 1.8 + * @date 2008/03/31 + * @license http://www.gnu.org/copyleft/gpl.html GNU Public License + * @version Moodle 2.0 **/ @set_time_limit(0); @@ -11,40 +22,38 @@ @ob_end_flush(); require_once('../../config.php'); - require_once("$CFG->dirroot/search/lib.php"); /// makes inclusions of the Zend Engine more reliable - $separator = (array_key_exists('WINDIR', $_SERVER)) ? ';' : ':' ; - ini_set('include_path', $CFG->dirroot.'\search'.$separator.ini_get('include_path')); + ini_set('include_path', $CFG->dirroot.PATH_SEPARATOR.'search'.PATH_SEPARATOR.ini_get('include_path')); - require_login(); + require_once($CFG->dirroot.'/search/lib.php'); + require_login(); + if (empty($CFG->enableglobalsearch)) { print_error('globalsearchdisabled', 'search'); } - + if (!has_capability('moodle/site:doanything', get_context_instance(CONTEXT_SYSTEM))) { print_error('onlyadmins', 'error', get_login_url()); - } //if + } mtrace('
Server Time: '.date('r',time()));
     mtrace("Testing global search capabilities:\n");
-
-    $phpversion = phpversion();
-
+    
     //fix paths for testing
     set_include_path(get_include_path().":../");
     require_once("$CFG->dirroot/search/Zend/Search/Lucene.php");
-
+    
     mtrace("Checking activity modules:\n");
-
+    
     //the presence of the required search functions -
     // * mod_iterator
     // * mod_get_content_for_index
     //are the sole basis for including a module in the index at the moment.
-
+    
 /// get all installed modules
-    if ($mods = get_records('modules', '', '', 'name', 'id,name')){
+    if ($mods = $DB->get_records('modules', null, 'name', 'id, name')){
 
         $searchabletypes = array_values(search_get_document_types());
 
@@ -58,13 +67,13 @@
                 if (file_exists($documentfile)){
                     $searchables[] = $mod;
                 }
-            }
-        }
+            }        
+        }    
         mtrace(count($searchables).' modules to search in / '.count($mods).' modules found.');
     }
-
+      
 /// collects blocks as indexable information may be found in blocks either
-    if ($blocks = get_records('block', '', '', 'name', 'id,name')) {
+    if ($blocks = $DB->get_records('block', null, 'name', 'id,name')) {
         $blocks_searchables = array();
         // prepend the "block_" prefix to discriminate document type plugins
         foreach($blocks as $block){
@@ -79,62 +88,66 @@
                     $mod->location = 'blocks';
                     $blocks_searchables[] = $block;
                 }
-            }
-        }
+            }        
+        }    
         mtrace(count($blocks_searchables).' blocks to search in / '.count($blocks).' blocks found.');
         $searchables = array_merge($searchables, $blocks_searchables);
     }
-
+      
 /// add virtual modules onto the back of the array
 
     $additional = search_get_additional_modules();
     mtrace(count($additional).' additional to search in.');
     $searchables = array_merge($searchables, $additional);
-
+    
     foreach ($searchables as $mod) {
+
+        $key = 'search_in_'.$mod->name;
+        if (isset($CFG->$key) && !$CFG->$key) {
+            mtrace("module $key has been administratively disabled. Skipping...\n");
+            continue;
+        }
+
         if ($mod->location == 'internal'){
             $class_file = $CFG->dirroot.'/search/documents/'.$mod->name.'_document.php';
         } else {
             $class_file = $CFG->dirroot.'/'.$mod->location.'/'.$mod->name.'/search_document.php';
         }
-
+    
         if (file_exists($class_file)) {
             include_once($class_file);
-
-            if (!defined('SEARCH_TYPE_'.strtoupper($mod->name))) {
-                mtrace("ERROR: Constant 'SEARCH_TYPE_".strtoupper($mod->name)."' is not defined in search/searchtypes.php or in module");
+    
+            if ($mod->location != 'internal' && !defined('X_SEARCH_TYPE_'.strtoupper($mod->name))) {
+                mtrace("ERROR: Constant 'X_SEARCH_TYPE_".strtoupper($mod->name)."' is not defined in search/searchtypes.php or in module");
                 continue;
             }
-
+            
             $iter_function = $mod->name.'_iterator';
             $index_function = $mod->name.'_get_content_for_index';
-
+            
             if (function_exists($index_function) && function_exists($iter_function)) {
-                if (is_array($iter_function())) {
-                    $documents = $index_function(array_pop($iter_function()));
-
+                $entries = $iter_function();
+                if (!empty($entries)) {
+                    $documents = $index_function(array_pop($entries));
+            
                     if (is_array($documents)) {
                         mtrace("Success: '$mod->name' module seems to be ready for indexing.");
                     } else {
                         mtrace("ERROR: $index_function() doesn't seem to be returning an array.");
-                    }
+                    } 
                 } else {
-                    mtrace("ERROR: $iter_function() doesn't seem to be returning an object array.");
-                }
+                    mtrace("Success : '$mod->name' has nothing to index.");
+                } 
             } else {
                 mtrace("ERROR: $iter_function() and/or $index_function() does not exist in $class_file");
-            }
+            } 
         } else {
             mtrace("Notice: $class_file does not exist, this module will not be indexed.");
-        }
-    }
-
-    //finished modules
-    mtrace("\nFinished checking activity modules.");
-
-    //now blocks...
-    //
-
+        } 
+    } 
+    
+    mtrace("\nFinished checking for searcheable items.");
+        
     mtrace("
Back to query page or Start indexing."); mtrace('
'); -?> +?> \ No newline at end of file -- 2.39.5