diff --git a/admin/settings/development.php b/admin/settings/development.php index 192df5b8d30..d6c9e4f0634 100644 --- a/admin/settings/development.php +++ b/admin/settings/development.php @@ -7,11 +7,7 @@ if ($hassiteconfig) { // speedup for non-admins, add all caps used on this page // Experimental settings page $ADMIN->add('development', new admin_category('experimental', get_string('experimental','admin'))); - require_once($CFG->dirroot .'/search/lib.php'); $temp = new admin_settingpage('experimentalsettings', get_string('experimentalsettings', 'admin')); - $englobalsearch = new admin_setting_configcheckbox('enableglobalsearch', get_string('enableglobalsearch', 'admin'), get_string('configenableglobalsearch', 'admin'), 0); - $englobalsearch->set_updatedcallback('search_updatedcallback'); - $temp->add($englobalsearch); //TODO: Re-enable cc-import once re-implemented in 2.0.x //$temp->add(new admin_setting_configcheckbox('enableimsccimport', get_string('enable_cc_import', 'imscc'), get_string('enable_cc_import_description', 'imscc'), 0)); $temp->add(new admin_setting_configcheckbox('enablesafebrowserintegration', get_string('enablesafebrowserintegration', 'admin'), get_string('configenablesafebrowserintegration', 'admin'), 0)); diff --git a/blocks/search/README.txt b/blocks/search/README.txt deleted file mode 100644 index 48dfb9f4679..00000000000 --- a/blocks/search/README.txt +++ /dev/null @@ -1,15 +0,0 @@ -This block is a revamping of the Google Summer Of Code Project (2006) on Global Search engine -for Moodle. New block version is completed and internationalized according to Moodle multilengual support. - -This block instanciates a startup database model for the search engine. - -## Installing - -You need installing the following elements in order the global search to be available : - -1. The global search bloc (this block) -2. update the /search root package from CVS -3. The antiword libraries -4. The xpdf libraries - -Both last libraries are provided as a patch called "global_search_libraries" in the contrib section. \ No newline at end of file diff --git a/blocks/search/block_search.php b/blocks/search/block_search.php deleted file mode 100644 index 1aeb08c085e..00000000000 --- a/blocks/search/block_search.php +++ /dev/null @@ -1,73 +0,0 @@ -title = get_string('pluginname', 'block_search'); - } //init - - // only one instance of this block is required - function instance_allow_multiple() { - return false; - } //instance_allow_multiple - - // label and button values can be set in admin - function has_config() { - return true; - } //has_config - - function get_content() { - global $CFG; - - if (empty($CFG->enableglobalsearch)) { - return ''; - } - - //cache block contents - if ($this->content !== NULL) { - return $this->content; - } //if - - $this->content = new stdClass; - - //basic search form - $this->content->text = - '
'; - - //no footer, thanks - $this->content->footer = ''; - - return $this->content; - } //get_content - - function specialisation() { - //empty! - } //specialisation - - /** - * wraps up to search engine cron - */ - function cron(){ - global $CFG; - - include($CFG->dirroot.'/search/cron.php'); - } - - } //block_search - diff --git a/blocks/search/db/install.php b/blocks/search/db/install.php deleted file mode 100644 index f8a13cf7f20..00000000000 --- a/blocks/search/db/install.php +++ /dev/null @@ -1,10 +0,0 @@ -set_field('block', 'visible', 0, array('name'=>'search')); - -} - diff --git a/blocks/search/db/install.xml b/blocks/search/db/install.xml deleted file mode 100644 index c5c2b52d29c..00000000000 --- a/blocks/search/db/install.xml +++ /dev/null @@ -1,30 +0,0 @@ - -Sorry, you need to confirm indexing via indexersplash.php" - .". (Back to query page)."); - - exit(0); - } - -/// check for php5 (lib.php) - - //php5 found, continue including php5-only files - //require_once("$CFG->dirroot/search/Zend/Search/Lucene.php"); - require_once($CFG->dirroot.'/search/indexlib.php'); - - mtrace(''); - mtrace('
Server Time: '.date('r',time())."\n");
-
- if (isset($CFG->search_indexer_busy) && $CFG->search_indexer_busy == '1') {
- //means indexing was not finished previously
- mtrace("Warning: Indexing was not successfully completed last time, restarting.\n");
- }
-
-/// turn on busy flag
-
- set_config('search_indexer_busy', '1');
-
- //paths
- $index_path = SEARCH_INDEX_PATH;
- $index_db_file = "{$CFG->dirroot}/search/db/$CFG->dbtype.sql";
- $dbcontrol = new IndexDBControl();
-
-/// setup directory in data root
-
- if (!file_exists($index_path)) {
- mtrace("Data directory ($index_path) does not exist, attempting to create.");
- if (!mkdir($index_path, $CFG->directorypermissions)) {
- search_pexit("Error creating data directory at: $index_path. Please correct.");
- }
- else {
- mtrace("Directory successfully created.");
- }
- }
- else {
- mtrace("Using {$index_path} as data directory.");
- }
-
- Zend_Search_Lucene_Analysis_Analyzer::setDefault(new Zend_Search_Lucene_Analysis_Analyzer_Common_Utf8_CaseInsensitive());
- $index = new Zend_Search_Lucene($index_path, true);
-
-/// New regeneration
-
- mtrace('Deleting old index entries.');
- $DB->delete_records(SEARCH_DATABASE_TABLE);
-
-/// begin timer
-
- search_stopwatch();
- mtrace("Starting 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.
-
- $searchables = search_collect_searchables();
-
-/// start indexation
-
- if ($searchables){
- foreach ($searchables as $mod) {
-
- //mark last update times for mods to now.
- $indexdatestring = 'search_indexer_update_date_'.$mod->name;
- set_config($indexdatestring, time());
- $indexdatestring = 'search_indexer_run_date_'.$mod->name;
- set_config($indexdatestring, time());
-
- mtrace("starting indexing {$mod->name}\n");
-
- $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);
-
- //build function names
- $iter_function = $mod->name.'_iterator';
- $index_function = $mod->name.'_get_content_for_index';
- $counter = 0;
- if (function_exists($index_function) && function_exists($iter_function)) {
- mtrace("Processing module function $index_function ...");
- $sources = $iter_function();
- if ($sources){
- foreach ($sources as $i) {
- $documents = $index_function($i);
-
- //begin transaction
- if ($documents){
- foreach($documents as $document) {
- $counter++;
-
- // temporary fix until MDL-24822 is resolved
- if ($document->group_id == -1 and $mod->name ='forum') {
- $document->group_id = 0;
- }
- //object to insert into db
- $dbid = $dbcontrol->addDocument($document);
-
- //synchronise db with index
- $document->addField(Zend_Search_Lucene_Field::Keyword('dbid', $dbid));
-
- //add document to index
- $index->addDocument($document);
-
- //commit every x new documents, and print a status message
- if (($counter % 2000) == 0) {
- $index->commit();
- mtrace(".. $counter");
- }
- }
- }
- //end transaction
- }
- }
-
- //commit left over documents, and finish up
- $index->commit();
-
- mtrace("-- $counter documents indexed");
- mtrace("done.\n");
- }
- } else {
- mtrace ("No search document found for plugin {$mod->name}. Ignoring.");
- }
- }
- }
-
-/// finished modules
-
- mtrace('Finished activity modules');
- search_stopwatch();
-
- mtrace(".
Back to query page.");
- mtrace('');
-
-/// finished, turn busy flag off
-
- set_config('search_indexer_busy', '0');
-
-/// mark the time we last updated
-
- set_config('search_indexer_run_date', time());
-
-/// and the index size
-
- set_config('search_index_size', (int)$index->count());
-
-?>
\ No newline at end of file
diff --git a/search/indexersplash.php b/search/indexersplash.php
deleted file mode 100644
index 78ac128d71f..00000000000
--- a/search/indexersplash.php
+++ /dev/null
@@ -1,77 +0,0 @@
- 1.8
- * @date 2008/03/31
- * @version prepared for 2.0
- * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
- *
- * This file serves as a splash-screen (entry page) to the indexer script -
- * it is in place to prevent accidental reindexing which can lead to a loss
- * of time, amongst other things.
- */
-
- /**
- * includes and requires
- */
- require_once('../config.php');
-
- /// makes inclusions of the Zend Engine more reliable
- ini_set('include_path', $CFG->dirroot.DIRECTORY_SEPARATOR.'search'.PATH_SEPARATOR.ini_get('include_path'));
-
- require_once($CFG->dirroot.'/search/lib.php');
-
- /// check global search is enabled
-
- require_login();
-
- if (empty($CFG->enableglobalsearch)) {
- print_error('globalsearchdisabled', 'search');
- }
-
- if (!has_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM))) {
- print_error('beadmin', 'search', get_login_url());
- }
-
- require_once("$CFG->dirroot/search/indexlib.php");
- $indexinfo = new IndexInfo();
-
- if ($indexinfo->valid()) {
- $strsearch = get_string('search', 'search');
- $strquery = get_string('stats');
-
- // print page header
- $site = get_site();
-
- $PAGE->set_url('/search/indexersplash.php');
- $PAGE->set_context(get_context_instance(CONTEXT_SYSTEM));
- $PAGE->navbar->add($strsearch, new moodle_url('/search/index.php'));
- $PAGE->navbar->add($strquery, new moodle_url('/search/stats.php'));
- $PAGE->navbar->add(get_string('runindexer','search'));
- $PAGE->set_title($strsearch);
- $PAGE->set_heading($site->fullname);
- echo $OUTPUT->header();
-
- mtrace("The data directory ($indexinfo->path) contains $indexinfo->filecount files, and\n" - ."there are ".$indexinfo->dbcount." records in the block_search_documents table.\n" - ."\n" - ."This indicates that you have already succesfully indexed this site. Follow the link\n" - ."if you are sure that you want to continue indexing - this will replace any existing\n" - ."index data (no Moodle data is affected).\n" - ."\n" - ."You are encouraged to use the 'Test indexing' script before continuing onto\n" - ."indexing - this will check if the modules are set up correctly. Please correct\n" - ."any errors before proceeding.\n" - ."\n" - ."Test indexing or " - ."Continue indexing or Back to query page." - .""); - echo $OUTPUT->footer(); - } else { - header('Location: indexer.php?areyousure=yes'); - } -?> diff --git a/search/indexlib.php b/search/indexlib.php deleted file mode 100644 index 3c2075ef291..00000000000 --- a/search/indexlib.php +++ /dev/null @@ -1,262 +0,0 @@ - 1.8 -* @date 2008/03/31 -* @version prepared for 2.0 -* @license http://www.gnu.org/copyleft/gpl.html GNU Public License -* -* Index info class -* -* Used to retrieve information about an index. -* Has methods to check for valid database and data directory, -* and the index itself. -*/ - -/** -* includes and requires -*/ -require_once($CFG->dirroot.'/search/lib.php'); -require_once($CFG->dirroot.'/search/Zend/Search/Lucene.php'); - -/** -* main class for searchable information in the Lucene index -*/ -class IndexInfo { - - private $path, //index data directory - $size, //size of directory (i.e. the whole index) - $filecount, //number of files - $indexcount, //number of docs in index - $dbcount, //number of docs in db - $types, //array of [document types => count] - $complete, //is index completely formed? - $time; //date index was generated - - public function __construct($path = SEARCH_INDEX_PATH) { - global $CFG, $DB; - - $this->path = $path; - - //test to see if there is a valid index on disk, at the specified path - try { - $test_index = new Zend_Search_Lucene($this->path, false); - $validindex = true; - } catch(Exception $e) { - $validindex = false; - } - - //retrieve file system info about the index if it is valid - if ($validindex) { - $this->size = display_size(get_directory_size($this->path)); - $index_dir = get_directory_list($this->path, '', false, false); - $this->filecount = count($index_dir); - $this->indexcount = $test_index->count(); - } - else { - $this->size = 0; - $this->filecount = 0; - $this->indexcount = 0; - } - - $db_exists = false; //for now - - //get all the current tables in moodle - $admin_tables = $DB->get_tables(); - - //check if our search table exists - if (in_array(SEARCH_DATABASE_TABLE, $admin_tables)) { - //retrieve database information if it does - $db_exists = true; - - //total documents - $this->dbcount = $DB->count_records(SEARCH_DATABASE_TABLE); - - //individual document types - $types = search_collect_searchables(false, false); - asort($types); - - foreach(array_keys($types) as $type) { - $c = $DB->count_records(SEARCH_DATABASE_TABLE, array('doctype' => $type)); - $types[$type]->records = (int)$c; - } - $this->types = $types; - } else { - $this->dbcount = 0; - $this->types = array(); - } - - //check if the busy flag is set - if (isset($CFG->search_indexer_busy) && $CFG->search_indexer_busy == '1') { - $this->complete = false; - } else { - $this->complete = true; - } - - //get the last run date for the indexer - if ($this->valid() && $CFG->search_indexer_run_date) { - $this->time = $CFG->search_indexer_run_date; - } else { - $this->time = 0; - } - } - - /** - * returns false on error, and the error message via referenced variable $err - * @param array $err array of errors - */ - public function valid(&$err = null) { - $err = array(); - $ret = true; - - if (!$this->is_valid_dir()) { - $err['dir'] = get_string('invalidindexerror', 'search'); - $ret = false; - } - - if (!$this->is_valid_db()) { - $err['db'] = get_string('emptydatabaseerror', 'search'); - $ret = false; - } - - if (!$this->complete) { - $err['index'] = get_string('uncompleteindexingerror','search'); - $ret = false; - } - - return $ret; - } - - /** - * is the index dir valid - * - */ - public function is_valid_dir() { - if ($this->filecount > 0) { - return true; - } else { - return false; - } - } - - /** - * is the db table valid - * - */ - public function is_valid_db() { - if ($this->dbcount > 0) { - return true; - } else { - return false; - } - } - - /** - * shorthand get method for the class variables - * @param object $var - */ - public function __get($var) { - if (in_array($var, array_keys(get_class_vars(get_class($this))))) { - return $this->$var; - } - } -} - - -/** -* DB Index control class -* -* Used to control the search index database table -*/ -class IndexDBControl { - - /** - * does the table exist? - * @deprecated - * @uses $CFG, $DB - */ - public function checkTableExists() { - global $CFG, $DB; - - $tables = $DB->get_tables(); - if (in_array(SEARCH_DATABASE_TABLE, $tables)) { - return true; - } - else { - return false; - } - } //checkTableExists - - /** - * NEVER USED - * - * is our database setup valid? - * @uses db, CFG - * @deprecated Database is installed at install and should not be dropped out - * - public function checkDB() { - global $CFG, $db; - - $sqlfile = "{$CFG->dirroot}/search/db/$CFG->dbtype.sql"; - $ret = false; - if ($this->checkTableExists()) { - execute_sql('drop table '.SEARCH_DATABASE_TABLE, false); - } - - //turn output buffering on - to hide modify_database() output - ob_start(); - $ret = modify_database($sqlfile, '', false); - - //chuck the buffer and resume normal operation - ob_end_clean(); - return $ret; - } //checkDB */ - - /** - * add a document record to the table - * @param document must be a Lucene SearchDocument instance - * @uses $CFG, $DB - */ - public function addDocument($document=null) { - global $DB, $CFG; - - if ($document == null) { - return false; - } - - // object to insert into db - $doc->doctype = $document->doctype; - $doc->docid = $document->docid; - $doc->itemtype = $document->itemtype; - $doc->title = $document->title; - $doc->url = $document->url; - $doc->updated = time(); - $doc->docdate = $document->date; - $doc->courseid = $document->course_id; - $doc->groupid = $document->group_id; - - //insert summary into db - $table = SEARCH_DATABASE_TABLE; - $id = $DB->insert_record($table, $doc); - - return $id; - } - - /** - * remove a document record from the index - * @param document must be a Lucene document instance, or at least a dbid enveloppe - * @uses $DB - */ - public function delDocument($document) { - global $DB; - - $table = SEARCH_DATABASE_TABLE; - $DB->delete_records($table, array('id' => $document->dbid)); - } -} - -?> \ No newline at end of file diff --git a/search/lib.php b/search/lib.php deleted file mode 100644 index d93a633f810..00000000000 --- a/search/lib.php +++ /dev/null @@ -1,197 +0,0 @@ - 1.8 -* @date 2008/03/31 -* @version prepared for 2.0 -* @license http://www.gnu.org/copyleft/gpl.html GNU Public License -* -* General function library -* -* This file must not contain any PHP 5, because it is used to test for PHP 5 -* itself, and needs to be able to be executed on PHP 4 installations. -* -*/ - -/** -* Constants -*/ -define('SEARCH_INDEX_PATH', $CFG->dataroot.'/search'); -define('SEARCH_DATABASE_TABLE', 'block_search_documents'); - -// get document types -include_once $CFG->dirroot.'/search/searchtypes.php'; - -/** -* collects all searchable items identities -* @param boolean $namelist if true, only returns list of names of searchable items -* @param boolean $verbose if true, prints a discovering status -* @return an array of names or an array of type descriptors -*/ -function search_collect_searchables($namelist=false, $verbose=true){ - global $CFG, $DB; - - $searchables = array(); - $searchables_names = array(); - -/// get all installed modules - if ($mods = $DB->get_records('modules', null, 'name', 'id,name')){ - - $searchabletypes = array_values(search_get_document_types()); - - foreach($mods as $mod){ - $plugin = new StdClass(); - $plugin->name = $mod->name; - $plugin->type = 'mod'; - if (in_array($mod->name, $searchabletypes)){ - $plugin->location = 'internal'; - $searchables[$plugin->name] = $plugin; - $searchables_names[] = $mod->name; - } else { - $documentfile = $CFG->dirroot."/mod/{$mod->name}/search_document.php"; - $plugin->location = 'mod'; - if (file_exists($documentfile)){ - $searchables[$plugin->name] = $plugin; - $searchables_names[] = $mod->name; - } - } - } - if ($verbose) mtrace(count($searchables).' modules to search in / '.count($mods).' modules found.'); - } - -/// collects blocks as indexable information may be found in blocks either - 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){ - $plugin = new StdClass(); - $plugin->dirname = $block->name; - $plugin->name = 'block_'.$block->name; - if (in_array('SEARCH_TYPE_'.strtoupper($block->name), $searchabletypes)){ - $plugin->location = 'internal'; - $plugin->type = 'block'; - $blocks_searchables[$plugin->name] = $plugin; - $searchables_names[] = $plugin->name; - } else { - $documentfile = $CFG->dirroot."/blocks/{$plugin->dirname}/search_document.php"; - if (file_exists($documentfile)){ - $plugin->location = 'blocks'; - $plugin->type = 'block'; - $blocks_searchables[$plugin->name] = $plugin; - $searchables_names[] = $plugin->name; - } - } - } - if ($verbose) 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($searchables_names); - if (!empty($additional)){ - if ($verbose) mtrace(count($additional).' additional to search in.'); - $searchables = array_merge($searchables, $additional); - } - - if ($namelist) - return $searchables_names; - return $searchables; -} - -/** -* returns all the document type constants that are known in core implementation -* @param prefix a pattern for recognizing constants -* @return an array of type labels -*/ -function search_get_document_types($prefix = 'SEARCH_TYPE_') { - $ret = array(); - foreach (get_defined_constants() as $key => $value) { - if (preg_match("/^{$prefix}/", $key)){ - $ret[$key] = $value; - } - } - sort($ret); - return $ret; -} - -/** -* additional virtual modules to index -* -* By adding 'moo' to the extras array, an additional document type -* documents/moo_document.php will be indexed - this allows for -* virtual modules to be added to the index, i.e. non-module specific -* information. -*/ -function search_get_additional_modules(&$searchables_names) { - $extras = array(/* additional keywords go here */); - if (defined('SEARCH_EXTRAS')){ - $extras = explode(',', SEARCH_EXTRAS); - } - - $ret = array(); - $temp = new StdClass; - foreach($extras as $extra) { - $plugin = new StdClass(); - $plugin->name = $extra; - $plugin->location = 'internal'; - eval('$plugin->type = TYPE_FOR_SEARCH_TYPE_'.strtoupper($extra).';'); - $ret[$plugin->name] = $plugin; - $searchables_names[] = $extra; - } - - return $ret; -} - -/** -* shortens a url so it can fit on the results page -* @param url the url -* @param length the size limit we want -*/ -function search_shorten_url($url, $length=30) { - return substr($url, 0, $length)."..."; -} - -/** -* simple timer function, on first call, records a current microtime stamp, outputs result on 2nd call -* @param cli an output formatting switch -* @return void -*/ -function search_stopwatch($cli = false) { - if (!empty($GLOBALS['search_script_start_time'])) { - if (!$cli) print ''; - print round(microtime(true) - $GLOBALS['search_script_start_time'], 6).' '.get_string('seconds', 'search'); - if (!$cli) print ''; - unset($GLOBALS['search_script_start_time']); - } else { - $GLOBALS['search_script_start_time'] = microtime(true); - } -} - -/** -* print and exit (for debugging) -* @param str a variable to explore -* @return void -*/ -function search_pexit($str = "") { - if (is_array($str) or is_object($str)) { - print_r($str); - } else if ($str) { - print $str."
' . get_string('noindexmessage', 'search') . '' . get_string('createanindex', 'search')."
\n"; - } - - ?> -Server Time: '.date('r',time()));
- mtrace("Testing global search capabilities:\n");
-
- //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 = $DB->get_records('modules', null, 'name', 'id, name')){
-
- $searchabletypes = array_values(search_get_document_types());
-
- foreach($mods as $mod){
- if (in_array($mod->name, $searchabletypes)){
- $mod->location = 'internal';
- $searchables[] = $mod;
- } else {
- $documentfile = $CFG->dirroot."/mod/{$mod->name}/search_document.php";
- $mod->location = 'mod';
- 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 = $DB->get_records('block', null, 'name', 'id,name')) {
- $blocks_searchables = array();
- // prepend the "block_" prefix to discriminate document type plugins
- foreach($blocks as $block){
- $block->dirname = $block->name;
- $block->name = 'block_'.$block->name;
- if (in_array('SEARCH_TYPE_'.strtoupper($block->name), $searchabletypes)){
- $mod->location = 'internal';
- $blocks_searchables[] = $block;
- } else {
- $documentfile = $CFG->dirroot."/blocks/{$block->dirname}/search_document.php";
- if (file_exists($documentfile)){
- $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 ($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)) {
- $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("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.");
- }
- }
-
- mtrace("\nFinished checking for searcheable items.");
-
- mtrace("
Back to query page or Start indexing.");
- mtrace('');
-?>
\ No newline at end of file
diff --git a/search/update.php b/search/update.php
deleted file mode 100644
index eb75f555ad6..00000000000
--- a/search/update.php
+++ /dev/null
@@ -1,200 +0,0 @@
- 1.8
- * @date 2008/03/31
- * @version prepared for 2.0
- * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
- *
- * Index asynchronous updator
- *
- * Major chages in this review is passing the xxxx_db_names return to
- * multiple arity to handle multiple document types modules
- */
-
- /**
- * includes and requires
- */
- require_once('../config.php');
-
- if (!defined('MOODLE_INTERNAL')) {
- die('Direct access to this script is forbidden.'); /// It must be included from the cron script
- }
-
- global $DB;
-
-/// makes inclusions of the Zend Engine more reliable
- ini_set('include_path', $CFG->dirroot.DIRECTORY_SEPARATOR.'search'.PATH_SEPARATOR.ini_get('include_path'));
-
- require_once($CFG->dirroot.'/search/lib.php');
- require_once($CFG->dirroot.'/search/indexlib.php');
-
-/// checks global search activation
-
- // require_login();
-
- if (empty($CFG->enableglobalsearch)) {
- print_error('globalsearchdisabled', 'search');
- }
-
- /*
- Obsolete with the MOODLE INTERNAL check
- if (!has_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM))) {
- print_error('beadmin', 'search', get_login_url());
- }
- */
-
- try {
- $index = new Zend_Search_Lucene(SEARCH_INDEX_PATH);
- } catch(LuceneException $e) {
- mtrace("Could not construct a valid index. Maybe the first indexation was never made, or files might be corrupted. Run complete indexation again.");
- return;
- }
- $dbcontrol = new IndexDBControl();
- $update_count = 0;
- $mainstartupdatedate = time();
-
-/// indexing changed resources
-
- mtrace("Starting index update (updates)...\n");
-
- if ($mods = search_collect_searchables(false, true)){
-
- foreach ($mods as $mod) {
- $indexdate = 0;
- $indexdatestring = 'search_indexer_update_date_'.$mod->name;
- $startupdatedate = time();
- if (isset($CFG->$indexdatestring)) {
- $indexdate = $CFG->$indexdatestring;
- }
-
- $class_file = $CFG->dirroot.'/search/documents/'.$mod->name.'_document.php';
- $get_document_function = $mod->name.'_single_document';
- $delete_function = $mod->name.'_delete';
- $db_names_function = $mod->name.'_db_names';
- $updates = array();
-
- if (file_exists($class_file)) {
- require_once($class_file);
-
- //if both required functions exist
- if (function_exists($delete_function) and function_exists($db_names_function) and function_exists($get_document_function)) {
- mtrace("Checking $mod->name module for updates.");
- $valuesArray = $db_names_function();
- if ($valuesArray){
- foreach($valuesArray as $values){
- $where = (isset($values[5]) and $values[5]!='') ? 'AND ('.$values[5].')' : '';
- $itemtypes = ($values[4] != '*' && $values[4] != 'any') ? " AND itemtype = '{$values[4]}' " : '' ;
-
- //TODO: check 'in' syntax with other RDBMS' (add and update.php as well)
- $table = SEARCH_DATABASE_TABLE;
- $query = "
- SELECT
- docid,
- itemtype
- FROM
- {{$table}}
- WHERE
- doctype = ?
- $itemtypes
- ";
- $docIds = $DB->get_records_sql_menu($query, array($mod->name));
- if (!empty($docIds)){
- list($usql, $params) = $DB->get_in_or_equal(array_keys($docIds));
- $query = "
- SELECT
- id,
- $values[0] as docid
- FROM
- {{$values[1]}}
- WHERE
- $values[3] > $indexdate AND
- id $usql
- $where
- ";
- $records = $DB->get_records_sql($query, $params);
- } else {
- $records = array();
- }
-
- foreach($records as $record) {
- $updates[] = $delete_function($record->docid, $docIds[$record->docid]);
- }
- }
-
- foreach ($updates as $update) {
- ++$update_count;
- $added_doc = false;
-
- //get old document for deletion later
- // change from default text only search to include numerals for this search.
- Zend_Search_Lucene_Analysis_Analyzer::setDefault(new Zend_Search_Lucene_Analysis_Analyzer_Common_TextNum_CaseInsensitive());
- $doc = $index->find("+docid:{$update->id} +doctype:{$mod->name} +itemtype:{$update->itemtype}");
-
- try {
- //add new modified document back into index
- $add = $get_document_function($update->id, $update->itemtype);
-
- //object to insert into db
- $dbid = $dbcontrol->addDocument($add);
-
- //synchronise db with index
- $add->addField(Zend_Search_Lucene_Field::Keyword('dbid', $dbid));
- mtrace(" Add: $add->title (database id = $add->dbid, moodle instance id = $add->docid)");
- $index->addDocument($add);
- $added_doc = true;
- }
-
- catch (dml_write_exception $e) {
- mtrace(" Add: FAILED adding '$add->title' , moodle instance id = $add->docid , Error: $e->error ");
- mtrace($e);
- $added_doc = false;
- }
-
- if ($added_doc) {
- // ok we've successfully added the new document so far
- // delete single previous old document
- try {
- //get the record, should only be one
- foreach ($doc as $thisdoc) {
- mtrace(" Delete: $thisdoc->title (database id = $thisdoc->dbid, index id = $thisdoc->id, moodle instance id = $thisdoc->docid)");
- $dbcontrol->delDocument($thisdoc);
- $index->delete($thisdoc->id);
- }
- }
-
- catch (dml_write_exception $e) {
- mtrace(" Delete: FAILED deleting '$thisdoc->title' , moodle instance id = $thisdoc->docid , Error: $e->error ");
- mtrace($e);
- }
- }
- }
- }
- else{
- mtrace("No types to update.\n");
- }
- //commit changes
- $index->commit();
-
- //update index date
- set_config($indexdatestring, $startupdatedate);
-
- mtrace("Finished $mod->name.\n");
- }
- }
- }
- }
-
- //commit changes
- $index->commit();
-
- //update index date
- set_config('search_indexer_update_date', $mainstartupdatedate);
-
- mtrace("Finished $update_count updates");
-
-?>
\ No newline at end of file
diff --git a/version.php b/version.php
index 6bcc026af5b..a8ec5fc4c2b 100644
--- a/version.php
+++ b/version.php
@@ -31,7 +31,7 @@ defined('MOODLE_INTERNAL') || die();
-$version = 2011102700.00; // YYYYMMDD = weekly release date of this DEV branch
+$version = 2011102700.01; // YYYYMMDD = weekly release date of this DEV branch
// RR = release increments - 00 in DEV branches
// .XX = incremental changes