diff -Naru search_original/.cvsignore search/.cvsignore --- search_original/.cvsignore 1970-01-01 09:00:00.000000000 +0900 +++ search/.cvsignore 2007-12-19 18:20:01.965250000 +0900 @@ -0,0 +1 @@ +delete_log.php diff -Naru search_original/cron.php search/cron.php --- search_original/cron.php 2009-01-08 16:30:17.283625000 +0900 +++ search/cron.php 2009-06-08 14:48:01.221404900 +0900 @@ -12,6 +12,28 @@ * adds documents created since the last index run */ +// (Shirai147): Enabling search/cron.php to run at command line (2009/06/05) +// (Shirai147): Add from here + /** + * includes and requires + */ + if (!isset($_SERVER['REMOTE_ADDR'])) { + if (isset($_SERVER['argv'][0])) { + chdir(dirname($_SERVER['argv'][0])); + } + require_once('../config.php'); + define('FULLME', 'cron'); +/// emulate normal session + $SESSION = new object(); + $USER = get_admin(); /// Temporarily, to provide environment for this script + +/// ignore admins timezone, language and locale - use site deafult instead! + $USER->timezone = $CFG->timezone; + $USER->lang = ''; + $USER->theme = ''; + course_setup(SITEID); + } +// (Shirai147): Add to here if (!defined('MOODLE_INTERNAL')) { die('Direct access to this script is forbidden.'); /// It must be included from a Moodle page } diff -Naru search_original/documents/assignment_document.php search/documents/assignment_document.php --- search_original/documents/assignment_document.php 2009-06-05 09:48:14.138625000 +0900 +++ search/documents/assignment_document.php 2009-06-08 15:13:46.452550500 +0900 @@ -125,6 +125,10 @@ case 'upload' : { $submitted->source = 'files'; $submitted->data = "{$assignment->course}/moddata/assignment/{$assignment->id}/{$submission->userid}"; +// (Debug011): $submitted->path is not set when the type of the assignment is uploadsingle/upload (2009/06/04) +// (Debug011): Add from here + $submitted->path = $submitted->data; +// (Debug011): Add to here } break; case 'offline' : continue; // cannot index, no content in Moodle !! @@ -132,20 +136,41 @@ } if (empty($submitted)) continue; // ignoring - if ($submitted->source = 'text'){ +// (Debug010): The uploaded files as the assignment aren't made indeies since these files are misstaken for 'test' (2009/06/04) +// (Debug010): Modified from here +// if ($submitted->source = 'text'){ + if ($submitted->source == 'text'){ +// (Debug010): Modified to here $submission->description = $submitted->data; $submission->description = preg_replace("/<[^>]*>/", '', $submission->description); // stip all tags $documents[] = new AssignmentSearchDocument(get_object_vars($submission), $cm->id, 'submission', $assignment->course, $submission->userid, $context->id); mtrace("finished online submission for {$submission->authors} in assignement {$assignment->name}"); - } elseif ($submitted->source = 'files'){ +// (Debug010): Modified from here +// } elseif ($submitted->source = 'files'){ + } elseif ($submitted->source == 'files'){ +// (Debug010): Modified to here +// (Debug011): $submitted->path is not set when the type of the assignment is uploadsingle/upload (2009/06/04) +// (Debug011): Modified from here $SUBMITTED = opendir($submitted->path); + $SUBMITTED = opendir("{$CFG->dataroot}/{$submitted->path}"); +// (Debug011): Modified to here while($entry = readdir($SUBMITTED)){ if (ereg("^\.", $entry)) continue; // exclude hidden and dirs . and .. $path = "{$submitted->path}/{$entry}"; - $documents[] = assignment_get_physical_file($submission, $assignment, $cm, $path, $context_id, $documents); +// (Debug015): function assignment_get_physical_file() does not have argument $getsingle (2009/06/04) +// (Debug015): Deleting "$documents[] = ", and adding parameter 'false' +// (Debug012): $context->id is $context_id (2009/06/04) +// (Debug012) & (Debug015): Modified from here +// $documents[] = assignment_get_physical_file($submission, $assignment, $cm, $path, $context_id, $documents); + assignment_get_physical_file($submission, $assignment, $cm, $path, $context->id, false, $documents); +// (Debug012): Modified to here mtrace("finished attachement $path for {$submission->authors} in assignement {$assignment->name}"); } - closedir($submission->path); +// (Debug014): $submission->path is $SUBMITTED (2009/06/04) +// (Debug014): Modified from here +// closedir($submission->path); + closedir($SUBMITTED); +// (Debug014): Modified to here } } } @@ -165,7 +190,11 @@ * @param documents the array of documents, by ref, where to add the new document. * @return a search document when unique or false. */ -function assignment_get_physical_file(&$submission, &$assignment, &$cm, $path, $context_id, &$documents = null){ +// (Debug015): function assignment_get_physical_file() does not have argument $getsingle (2009/06/04) +// (Debug015): Modified from here +// function assignment_get_physical_file(&$submission, &$assignment, &$cm, $path, $context_id, &$documents = null){ +function assignment_get_physical_file(&$submission, &$assignment, &$cm, $path, $context_id, $getsingle, &$documents = null){ +// (Debug015): Modified to here global $CFG; $fileparts = pathinfo($path); @@ -185,7 +214,13 @@ if (file_exists($CFG->dirroot.'/search/documents/physical_'.$ext.'.php')){ include_once($CFG->dirroot.'/search/documents/physical_'.$ext.'.php'); $function_name = 'get_text_for_indexing_'.$ext; - $submission->description = $function_name(null, $path); +// (Debug013): First argument of functions get_text_for_indexing_() is 'call by reference' (2009/06/04) +// (Debug013): Comment out this line +// $submission->description = $function_name(null, $path); +// (Debug013): Add from here + $dummyResource = null; + $submission->description = $function_name($dummyResource, $path); +// (Debug013): Add to here // get authors $user = get_record('user', 'id', $submission->userid); diff -Naru search_original/documents/data_document.php search/documents/data_document.php --- search_original/documents/data_document.php 2009-06-05 09:48:14.138625000 +0900 +++ search/documents/data_document.php 2009-06-08 15:17:11.719348700 +0900 @@ -46,7 +46,11 @@ if ($record['userid']){ $user = get_record('user', 'id', $record['userid']); } - $doc->author = (isset($user)) ? $user->firstname.' '.$user->lastname : '' ; +// (Debug005): function fullname() is not used in data module to set the author field (2009/06/03) +// (Debug005): Modified from here +// $doc->author = (isset($user)) ? $user->firstname.' '.$user->lastname : '' ; + $doc->author = (isset($user)) ? fullname($user) : '' ; +// (Debug005): Modified to here $doc->contents = $record['content']; $doc->url = data_make_link($record['dataid'], $record['id']); diff -Naru search_original/documents/forum_document.php search/documents/forum_document.php --- search_original/documents/forum_document.php 2009-06-05 09:48:14.138625000 +0900 +++ search/documents/forum_document.php 2009-06-08 14:49:54.915797500 +0900 @@ -93,6 +93,13 @@ $coursemodule = get_field('modules', 'id', 'name', 'forum'); $cm = get_record('course_modules', 'course', $forum->course, 'module', $coursemodule, 'instance', $forum->id); +// (Shirai136): When the course module does not exist in mdl_course_modules, SQL syntax error will occur (2009/05/29) +// (Shirai136): Add from here + if (empty($cm)) { + mtrace("Missing this forum: Course=".$forum->course."/ ForumID=".$forum->id); + return $documents; + } +// (Shirai136): Add to here $context = get_context_instance(CONTEXT_MODULE, $cm->id); foreach($posts as $aPost) { diff -Naru search_original/documents/glossary_document.php search/documents/glossary_document.php --- search_original/documents/glossary_document.php 2009-05-20 21:10:49.503625000 +0900 +++ search/documents/glossary_document.php 2009-06-08 15:18:56.758828400 +0900 @@ -44,7 +44,11 @@ if ($entry['userid']) $user = get_record('user', 'id', $entry['userid']); - $doc->author = ($user ) ? $user->firstname.' '.$user->lastname : '' ; +// (Debug009): function fullname() is not used in glossary module to set the author field (2009/06/04) +// (Debug009): Modified from here +// $doc->author = ($user ) ? $user->firstname.' '.$user->lastname : '' ; + $doc->author = ($user ) ? fullname($user) : '' ; +// (Debug009): Modified to here $doc->contents = strip_tags($entry['definition']); $doc->url = glossary_make_link($entry['id']); @@ -77,7 +81,11 @@ if ($entry['userid']) $user = get_record('user', 'id', $entry['userid']); - $doc->author = ($user ) ? $user->firstname.' '.$user->lastname : '' ; +// (Debug009): function fullname() is not used in glossary module to set the author field (2009/06/04) +// (Debug009): Modified from here +// $doc->author = ($user ) ? $user->firstname.' '.$user->lastname : '' ; + $doc->author = ($user ) ? fullname($user) : '' ; +// (Debug009): Modified to here $doc->contents = strip_tags($entry['entrycomment']); $doc->url = glossary_make_link($entry['entryid']); diff -Naru search_original/documents/label_document.php search/documents/label_document.php --- search_original/documents/label_document.php 2009-06-05 09:48:14.138625000 +0900 +++ search/documents/label_document.php 2009-06-08 14:50:23.476103900 +0900 @@ -88,6 +88,13 @@ $coursemodule = get_field('modules', 'id', 'name', 'label'); $cm = get_record('course_modules', 'course', $label->course, 'module', $coursemodule, 'instance', $label->id); +// (Shirai136): When the course module does not exist in mdl_course_modules, SQL syntax error will occur (2009/05/29) +// (Shirai136): Add from here + if (empty($cm)) { + mtrace("Missing this label: Course=".$label->course."/ LabelID=".$label->id); + return $documents; + } +// (Shirai136): Add to here $context = get_context_instance(CONTEXT_MODULE, $cm->id); $documents[] = new LabelSearchDocument(get_object_vars($label), $context->id); diff -Naru search_original/documents/physical_doc.php search/documents/physical_doc.php --- search_original/documents/physical_doc.php 2009-06-05 09:48:14.138625000 +0900 +++ search/documents/physical_doc.php 2009-06-08 14:52:04.218366300 +0900 @@ -30,7 +30,11 @@ // just call pdftotext over stdout and capture the output if (!empty($CFG->block_search_word_to_text_cmd)){ if (!file_exists("{$moodleroot}{$CFG->block_search_word_to_text_cmd}")){ - mtrace('Error with MSWord to text converter command : exectutable not found at '.$moodleroot.$CFG->block_search_word_to_text_cmd); +(Shirai145): Adding path for external converter and modifying "exectuable" -> "executable" (2009/05/30) +// (Shirai145): Modified from here +// mtrace('Error with MSWord to text converter command : exectutable not found at '.$moodleroot.$CFG->block_search_word_to_text_cmd); + mtrace('Error with MSWord to text converter command : executable not found at '.$moodleroot.$CFG->block_search_word_to_text_cmd); +// (Shirai145): Modified to here } else { if ($directfile == ''){ $file = escapeshellarg("{$CFG->dataroot}/{$resource->course}/{$resource->reference}"); diff -Naru search_original/documents/resource_document.php search/documents/resource_document.php --- search_original/documents/resource_document.php 2009-06-05 09:48:14.138625000 +0900 +++ search/documents/resource_document.php 2009-06-08 15:20:31.283423400 +0900 @@ -100,6 +100,13 @@ foreach($resources as $aResource){ $coursemodule = get_field('modules', 'id', 'name', 'resource'); $cm = get_record('course_modules', 'course', $aResource->course, 'module', $coursemodule, 'instance', $aResource->id); +// (Shirai136): When the course module does not exist in mdl_course_modules, SQL syntax error will occur (2009/05/29) +// (Shirai136): Add from here + if (empty($cm)) { + mtrace("Missing this resource: Course=".$aResource->course."/ ResourceID=".$aResource->id); + return $documents; + } +// (Shirai136): Add to here $context = get_context_instance(CONTEXT_MODULE, $cm->id); $aResource->id = $cm->id; $documents[] = new ResourceSearchDocument(get_object_vars($aResource), $context->id); @@ -258,7 +265,11 @@ $cm = get_record('course_modules', 'id', $resource->id); $context = get_context_instance(CONTEXT_MODULE, $cm->id); if ($resource->type == 'file' && @$CFG->block_search_enable_file_indexing){ - $document = resource_get_physical_file($resource, true, $context->id); +// (Debug008): The order of arguments $contex->id and true are wrong (exchanged) (2009/06/04) +// (Debug008): Modified from here +// $document = resource_get_physical_file($resource, true, $context->id); + $document = resource_get_physical_file($resource, $context->id, true); +// (Debug008): Modified to here if (!$document) mtrace("Warning : this document {$resource->name} will not be indexed"); return $document; } else { diff -Naru search_original/documents/user_document.php search/documents/user_document.php --- search_original/documents/user_document.php 2009-06-05 09:48:14.138625000 +0900 +++ search/documents/user_document.php 2009-06-08 15:22:43.945958300 +0900 @@ -270,13 +270,21 @@ } } elseif ($itemtype == 'post') { if ($post = get_records('post', 'id', $id)){ +// (Debug006): The return value of get_records() are array() (2009/06/03) +// (Debug006): Add from here + $post = $post[$id]; +// (Debug006): Add to here $texts = array(); $texts[] = $post->subject; $texts[] = $post->summary; $texts[] = $post->content; $post->description = implode(" ", $texts); $posthash = get_object_vars($post); - return new UserPostSearchDocument($posthash, $user->id, 'post', null); +// (Debug007): $user->id is $post->userid (2009/06/03) +// (Debug007): Modified from here +// return new UserPostSearchDocument($posthash, $user->id, 'post', null); + return new UserPostSearchDocument($posthash, $post->userid, 'post', null); +// (Debug007): Modified to here } } elseif ($itemtype == 'attachment' && @$CFG->block_search_enable_file_indexing) { if ($post = get_records('post', 'id', $id)){ diff -Naru search_original/documents/wiki_document.php search/documents/wiki_document.php --- search_original/documents/wiki_document.php 2009-06-05 09:48:14.138625000 +0900 +++ search/documents/wiki_document.php 2009-06-08 14:55:21.343850900 +0900 @@ -169,6 +169,13 @@ if ($entries){ $coursemodule = get_field('modules', 'id', 'name', 'wiki'); $cm = get_record('course_modules', 'course', $wiki->course, 'module', $coursemodule, 'instance', $wiki->id); +// (Shirai136): When the course module does not exist in mdl_course_modules, SQL syntax error will occur (2009/05/29) +// (Shirai136): Add from here + if (empty($cm)) { + mtrace("Missing this wiki: Course=".$wiki->course."/ WikiID=".$wiki->id); + return $documents; + } +// (Shirai136): Add to here $context = get_context_instance(CONTEXT_MODULE, $cm->id); foreach($entries as $entry) { @@ -180,7 +187,11 @@ if (is_array($pages)) { foreach($pages as $page) { if (strlen($page->content) > 0) { - $documents[] = new WikiSearchDocument(get_object_vars($page), $entry->wikiid, $entry->course, $entry->groupid, $page->userid, $context->id); +// (Shirai140): The course name is not displayed when the search result is wiki (2009/05/29) +// (Shirai140): Modified from here +// $documents[] = new WikiSearchDocument(get_object_vars($page), $entry->wikiid, $entry->course, $entry->groupid, $page->userid, $context->id); + $documents[] = new WikiSearchDocument(get_object_vars($page), $entry->wikiid, $wiki->course, $entry->groupid, $page->userid, $context->id); +// (Shirai140): Modified to here } } } @@ -200,6 +211,12 @@ $entry = get_record('wiki_entries', 'id', $page->wiki); $coursemodule = get_field('modules', 'id', 'name', 'wiki'); $cm = get_record('course_modules', 'course', $entry->course, 'module', $coursemodule, 'instance', $entry->wikiid); +// (Shirai136): Add from here + if (empty($cm)) { + mtrace("Missing this wiki: Course=".$entry->course."/ WikiID=".$entry->wikiid); + return array(); + } +// (Shirai136): Add to here $context = get_context_instance(CONTEXT_MODULE, $cm->id); return new WikiSearchDocument(get_object_vars($page), $entry->wikiid, $entry->course, $entry->groupid, $page->userid, $context->id); } diff -Naru search_original/indexer.php search/indexer.php --- search_original/indexer.php 2009-05-20 21:10:49.503625000 +0900 +++ search/indexer.php 2009-06-08 14:49:12.590923300 +0900 @@ -33,6 +33,12 @@ /** * includes and requires */ +// (Shirai146): Enabling search/indexer.php to run at command line (2009/06/05) +// (Shirai146): Add from here + if (!isset($_SERVER['REMOTE_ADDR']) && isset($_SERVER['argv'][0])) { + chdir(dirname($_SERVER['argv'][0])); + } +// (Shirai146): Add to here require_once('../config.php'); require_once($CFG->dirroot.'/search/lib.php'); @@ -42,7 +48,25 @@ /// only administrators can index the moodle installation, because access to all pages is required +// (Shirai146): Add from here + if (isset($_SERVER['REMOTE_ADDR'])) { +// (Shirai146): Add to here require_login(); +// (Shirai146): Add from here + } else { + $_GET['areyousure'] = 'yes'; + define('FULLME', 'cron'); +/// emulate normal session + $SESSION = new object(); + $USER = get_admin(); /// Temporarily, to provide environment for this script + +/// ignore admins timezone, language and locale - use site deafult instead! + $USER->timezone = $CFG->timezone; + $USER->lang = ''; + $USER->theme = ''; + course_setup(SITEID); + } +// (Shirai146): Add to here if (empty($CFG->enableglobalsearch)) { error(get_string('globalsearchdisabled', 'search'));