Permalink
Browse files

MDL-19342 - small fixes from Tatsuva Shirai + UTF-8 global straighten up

  • Loading branch information...
diml
diml committed May 30, 2009
1 parent 902ec3c commit 29dc93d1cdb05047bc2fdd4e78e8d501bccf24af
@@ -779,7 +779,7 @@ public function setMergeFactor($mergeFactor)
public function find($query)
{
if (is_string($query)) {
- $query = Zend_Search_Lucene_Search_QueryParser::parse($query);
+ $query = Zend_Search_Lucene_Search_QueryParser::parse($query, 'UTF-8');
}
if (!$query instanceof Zend_Search_Lucene_Search_Query) {
@@ -6,6 +6,7 @@
* @category core
* @subpackage document_wrappers
* @author Valery Fremaux [valery.fremaux@club-internet.fr] > 1.8
+* @contributor Tatsuva Shirai 20090530
* @date 2008/03/31
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
*
@@ -301,6 +302,8 @@ function assignment_check_text_access($path, $itemtype, $this_id, $user, $group_
$context = get_record('context', 'id', $context_id);
$cm = get_record('course_modules', 'id', $context->instanceid);
+ if (empty($cm)) return false; // Shirai 20090530 - MDL19342 - course module might have been delete
+
if (!$cm->visible and !has_capability('moodle/course:viewhiddenactivities', $context)){
if (!empty($CFG->search_access_debug)) echo "search reject : hidden assignment ";
return false;
@@ -6,6 +6,7 @@
* @category core
* @subpackage document_wrappers
* @author Valery Fremaux [valery.fremaux@club-internet.fr] > 1.8
+* @contributor Tatsuva Shirai 20090530
* @date 2008/03/31
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
*
@@ -89,6 +90,10 @@ function chat_get_session_tracks($chat_id, $fromtime = 0, $totime = 0) {
$course = get_record('course', 'id', $chat->course);
$coursemodule = get_field('modules', 'id', 'name', 'data');
$cm = get_record('course_modules', 'course', $course->id, 'module', $coursemodule, 'instance', $chat->id);
+ if (empty($cm)) { // Shirai 20090530
+ mtrace("Missing this chat: Course=".$chat->course."/ ChatID=".$chat_id);
+ return array();
+ }
$groupmode = groupmode($course, $cm);
$fromtimeclause = ($fromtime) ? "AND timestamp >= {$fromtime}" : '';
@@ -260,8 +265,7 @@ function chat_check_text_access($path, $itemtype, $this_id, $user, $group_id, $c
$chat = get_record('chat', 'id', $chat_id);
$context = get_record('context', 'id', $context_id);
$cm = get_record('course_modules', 'id', $context->instanceid);
- // $cm = get_coursemodule_from_instance('chat', $chat->id, $chat->course);
- // $context = get_context_instance(CONTEXT_MODULE, $cm->id);
+ if (empty($cm)) return false; // Shirai 20090530 - MDL19342 - course module might have been delete
if (!$cm->visible and !has_capability('moodle/course:viewhiddenactivities', $context)){
if (!empty($CFG->search_access_debug)) echo "search reject : hidden chat ";
@@ -6,6 +6,7 @@
* @category core
* @subpackage document_wrappers
* @author Valery Fremaux [valery.fremaux@club-internet.fr] > 1.8
+* @contributor Tatsuva Shirai 20090530
* @date 2008/03/31
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
*
@@ -79,7 +80,7 @@ public function __construct(&$comment, $course_id, $context_id) {
//remove '(ip.ip.ip.ip)' from data record author field
$doc->author = preg_replace('/\(.*?\)/', '', $comment['author']);
$doc->contents = $comment['content'];
- $doc->url = data_make_link($data_id, $comment['recordid']);
+ $doc->url = data_make_link($comment['dataid'], $comment['recordid']);
// module specific information; optional
$data->database = $comment['dataid'];
@@ -196,7 +197,7 @@ function data_get_content_for_index(&$database) {
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
// getting records for indexing
- $records_content = data_get_records($database->id, 'text');
+ $records_content = data_get_records($database->id, 'text,textarea');
if ($records_content){
foreach(array_keys($records_content) as $aRecordId) {
@@ -222,7 +223,9 @@ function data_get_content_for_index(&$database) {
$records_comments = data_get_comments($database->id);
if ($records_comments){
foreach($records_comments as $aComment){
- $aComment->title = $recordsTitles[$aComment->recordid];
+ $aComment->title = $recordTitles[$aComment->recordid];
+ $authoruser = get_record('user', 'id', $aComment->userid);
+ $aComment->author = fullname($authoruser);
$documents[] = new DataCommentSearchDocument(get_object_vars($aComment), $database->course, $context->id);
}
}
@@ -247,7 +250,7 @@ function data_single_document($id, $itemtype) {
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
// get text fields ids in this data (computable fields)
// compute text
- $recordData = data_get_records($recordMetaData->dataid, 'text', $id);
+ $recordData = data_get_records($recordMetaData->dataid, 'text,textarea', $id);
if ($recordData){
$dataArray = array_values($recordData);
$record_content = $dataArray[0]; // We cannot have more than one record here
@@ -280,6 +283,8 @@ function data_single_document($id, $itemtype) {
$comment->title = get_field('search_document', 'title', 'docid', $record->id, 'itemtype', 'record');
$comment->dataid = $record->dataid;
$comment->groupid = $record->groupid;
+ $authoruser = get_record('user', 'id', $comment->userid);
+ $comment->author = fullname($authoruser);
// make document
return new DataCommentSearchDocument(get_object_vars($comment), $record_course, $context->id);
} else {
@@ -345,8 +350,7 @@ function data_check_text_access($path, $itemtype, $this_id, $user, $group_id, $c
$data = get_record('data', 'id', $record->dataid);
$context = get_record('context', 'id', $context_id);
$cm = get_record('course_modules', 'id', $context->instanceid);
- // $cm = get_coursemodule_from_instance('data', $data->id, $data->course);
- // $context = get_context_instance(CONTEXT_MODULE, $cm->id);
+ if (empty($cm)) return false; // Shirai 20093005 - MDL19342 - course module might have been delete
if (!$cm->visible and !has_capability('moodle/course:viewhiddenactivities', $context)) {
if (!empty($CFG->search_access_debug)) echo "search reject : hidden database ";
@@ -6,6 +6,7 @@
* @category core
* @subpackage document_wrappers
* @author Michael Campanis (mchampan) [cynnical@gmail.com], Valery Fremaux [valery.fremaux@club-internet.fr] > 1.8
+* @contributor Tatsuva Shirai on UTF-8 multibyte fixing
* @date 2008/03/31
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
*
@@ -16,6 +17,66 @@
/**
*
*/
+abstract class SearchDocument extends Zend_Search_Lucene_Document {
+ public function __construct(&$doc, &$data, $course_id, $group_id, $user_id, $path, $additional_keyset = null) {
+
+ $encoding = 'UTF-8';
+
+ //document identification and indexing
+ $this->addField(Zend_Search_Lucene_Field::Keyword('docid', $doc->docid, $encoding));
+ //document type : the name of the Moodle element that manages it
+ $this->addField(Zend_Search_Lucene_Field::Keyword('doctype', $doc->documenttype, $encoding));
+ //allows subclassing information from complex modules.
+ $this->addField(Zend_Search_Lucene_Field::Keyword('itemtype', $doc->itemtype, $encoding));
+ //caches the course context.
+ $this->addField(Zend_Search_Lucene_Field::Keyword('course_id', $course_id, $encoding));
+ //caches the originator's group.
+ $this->addField(Zend_Search_Lucene_Field::Keyword('group_id', $group_id, $encoding));
+ //caches the originator if any
+ $this->addField(Zend_Search_Lucene_Field::Keyword('user_id', $user_id, $encoding));
+ // caches the context of this information. i-e, the context in which this information
+ // is being produced/attached. Speeds up the "check for access" process as context in
+ // which the information resides (a course, a module, a block, the site) is stable.
+ $this->addField(Zend_Search_Lucene_Field::UnIndexed('context_id', $doc->contextid, $encoding));
+
+ //data for document
+ $this->addField(Zend_Search_Lucene_Field::Text('title', $doc->title, $encoding));
+ $this->addField(Zend_Search_Lucene_Field::Text('author', $doc->author, $encoding));
+ $this->addField(Zend_Search_Lucene_Field::UnStored('contents', $doc->contents, $encoding));
+ $this->addField(Zend_Search_Lucene_Field::UnIndexed('url', $doc->url, $encoding));
+ $this->addField(Zend_Search_Lucene_Field::UnIndexed('date', $doc->date, $encoding));
+
+ //additional data added on a per-module basis
+ $this->addField(Zend_Search_Lucene_Field::Binary('data', serialize($data)));
+
+ // adding a path allows the document to know where to find specific library calls
+ // for checking access to a module or block content. The Lucene records should only
+ // be responsible to bring back to that call sufficient and consistent information
+ // in order to perform the check.
+ $this->addField(Zend_Search_Lucene_Field::UnIndexed('path', $path, $encoding));
+ /*
+ // adding a capability set required for viewing. -1 if no capability required.
+ // the capability required for viewing is depending on the local situation
+ // of the document. each module should provide this information when pushing
+ // out search document structure. Although capability model should be kept flat
+ // there is no exclusion some module or block developpers use logical combinations
+ // of multiple capabilities in their code. This possibility should be left open here.
+ $this->addField(Zend_Search_Lucene_Field::UnIndexed('capabilities', $caps));
+ */
+
+ /*
+ // Additional key set allows a module to ask for extensible criteria based search
+ // depending on the module internal needs.
+ */
+ if (!empty($additional_keyset)){
+ foreach($additional_keyset as $keyname => $keyvalue){
+ $this->addField(Zend_Search_Lucene_Field::Keyword($keyname, $keyvalue, $encoding));
+ }
+ }
+ }
+}
+
+/*
abstract class SearchDocument extends Zend_Search_Lucene_Document {
public function __construct(&$doc, &$data, $course_id, $group_id, $user_id, $path, $additional_keyset = null) {
//document identification and indexing
@@ -63,13 +124,13 @@ public function __construct(&$doc, &$data, $course_id, $group_id, $user_id, $pat
/*
// Additional key set allows a module to ask for extensible criteria based search
// depending on the module internal needs.
- */
+ *
if (!empty($additional_keyset)){
foreach($additional_keyset as $keyname => $keyvalue){
$this->addField(Zend_Search_Lucene_Field::Keyword($keyname, $keyvalue));
}
}
}
-}
+}*/
?>
@@ -5,6 +5,7 @@
* @package search
* @category core
* @subpackage document_wrappers
+* @contributor Tatsuva Shirai 20090530
* @author Michael Campanis (mchampan) [cynnical@gmail.com], Valery Fremaux [valery.fremaux@club-internet.fr] > 1.8
* @date 2008/03/31
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
@@ -278,8 +279,8 @@ function forum_check_text_access($path, $itemtype, $this_id, $user, $group_id, $
$discussion = get_record('forum_discussions', 'id', $post->discussion);
$context = get_record('context', 'id', $context_id);
$cm = get_record('course_modules', 'id', $context->instanceid);
- // $cm = get_coursemodule_from_instance('forum', $discussion->forum, $discussion->course);
- // $context = get_context_instance(CONTEXT_MODULE, $cm->id);
+ if (empty($cm)) return false; // Shirai 20093005 - MDL19342 - course module might have been delete
+
if (!$cm->visible and !has_capability('moodle/course:viewhiddenactivities', $context)){
if (!empty($CFG->search_access_debug)) echo "search reject : hidden forum resource ";
return false;
@@ -6,6 +6,7 @@
* @category core
* @subpackage document_wrappers
* @author Valery Fremaux [valery.fremaux@club-internet.fr] > 1.9
+* @contributor Tatsuva Shirai 20090530
* @date 2008/03/31
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
*
@@ -154,6 +155,8 @@ function label_check_text_access($path, $itemtype, $this_id, $user, $group_id, $
$r = get_record('label', 'id', $this_id);
$module_context = get_record('context', 'id', $context_id);
$cm = get_record('course_modules', 'id', $module_context->instanceid);
+ if (empty($cm)) return false; // Shirai 20093005 - MDL19342 - course module might have been delete
+
$course_context = get_context_instance(CONTEXT_COURSE, $r->course);
//check if englobing course is visible
@@ -6,6 +6,7 @@
* @category core
* @subpackage document_wrappers
* @author Michael Campanis (mchampan) [cynnical@gmail.com], Valery Fremaux [valery.fremaux@club-internet.fr] > 1.8
+* @contributor Tatsuva Shirai 20090530
* @date 2008/03/31
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
*
@@ -172,9 +173,7 @@ function lesson_check_text_access($path, $itemtype, $this_id, $user, $group_id,
$lesson = get_record('lesson', 'id', $page->lessonid);
$context = get_record('context', 'id', $context_id);
$cm = get_record('course_modules', 'id', $context->instanceid);
- // $lesson = get_record('lesson', 'id', $page->lessonid);
- // $cm = get_coursemodule_from_instance('lesson', $page->lessonid, $lesson->course);
- // $context = get_context_instance(CONTEXT_MODULE, $cm->id);
+ if (empty($cm)) return false; // Shirai 20093005 - MDL19342 - course module might have been delete
if (!$cm->visible and !has_capability('moodle/course:viewhiddenactivities', $context)){
if (!empty($CFG->search_access_debug)) echo "search reject : hidden lesson ";
@@ -6,6 +6,7 @@
* @category core
* @subpackage document_wrappers
* @author Valery Fremaux [valery.fremaux@club-internet.fr] > 1.8
+* @contributor Tatsuva Shirai 20090530
* @date 2008/03/31
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
*
@@ -29,7 +30,7 @@ function get_text_for_indexing_doc(&$resource, $directfile = ''){
// 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 : exectuable not found.');
+ mtrace('Error with MSWord to text converter command : exectutable not found at '.$moodleroot.$CFG->block_search_word_to_text_cmd);
} else {
if ($directfile == ''){
$file = escapeshellarg("{$CFG->dataroot}/{$resource->course}/{$resource->reference}");
@@ -6,6 +6,7 @@
* @category core
* @subpackage document_wrappers
* @author Valery Fremaux [valery.fremaux@club-internet.fr] > 1.8
+* @contributor Tatsuva Shirai 20090530
* @date 2008/03/31
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
*
@@ -29,7 +30,7 @@ function get_text_for_indexing_odt(&$resource, $directfile = ''){
// just call pdftotext over stdout and capture the output
if (!empty($CFG->block_search_odt_to_text_cmd)){
if (!file_exists("{$moodleroot}{$CFG->block_search_odt_to_text_cmd}")){
- mtrace('Error with OpenOffice ODT to text converter command : exectuable not found.');
+ mtrace('Error with OpenOffice ODT to text converter command : executable not found at'.$moodleroot.$CFG->block_search_odt_to_text_cmd);
} else {
if ($directfile == ''){
$file = escapeshellarg("{$CFG->dataroot}/{$resource->course}/{$resource->reference}");
@@ -6,6 +6,7 @@
* @category core
* @subpackage document_wrappers
* @author Valery Fremaux [valery.fremaux@club-internet.fr] > 1.8
+* @contributor Tatsuva Shirai 20090530
* @date 2008/03/31
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
*
@@ -88,7 +89,7 @@ function get_text_for_indexing_ppt(&$resource, $directfile = ''){
$indextext = shorten($text, $CFG->block_search_limit_index_body);
}
- $indextext = mb_convert_encoding($indextext, 'UTF8', 'auto');
+ $indextext = mb_convert_encoding($indextext, 'UTF-8', 'auto'); // Shirai 20090530 - MDL19342
return $indextext;
}
?>
@@ -6,6 +6,7 @@
* @category core
* @subpackage document_wrappers
* @author Michael Campanis (mchampan) [cynnical@gmail.com], Valery Fremaux [valery.fremaux@club-internet.fr] > 1.8
+* @contributor Tatsuva Shirai 20090530
* @date 2008/03/31
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
*
@@ -307,6 +308,7 @@ function resource_check_text_access($path, $itemtype, $this_id, $user, $group_id
$r = get_record('resource', 'id', $this_id);
$module_context = get_record('context', 'id', $context_id);
$cm = get_record('course_modules', 'id', $module_context->instanceid);
+ if (empty($cm)) return false; // Shirai 20090530 - MDL19342 - course module might have been delete
$course_context = get_context_instance(CONTEXT_COURSE, $r->course);
//check if course is visible
@@ -6,6 +6,7 @@
* @category core
* @subpackage document_wrappers
* @author Valery Fremaux [valery.fremaux@club-internet.fr] > 1.8
+* @contributor Tatsuva Shirai 20090530
* @date 2008/03/31
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
*
@@ -48,7 +49,8 @@ public function __construct(&$userhash, $user_id, $context_id) {
// module specific information; optional
// construct the parent class
- parent::__construct($doc, $data, 0, 0, 0, PATH_FOR_SEARCH_TYPE_USER);
+ // Shirai : User pictures are not displayed in results of blogs (2009/05/29) MDL19341
+ parent::__construct($doc, $data, 0, 0, $user_id, PATH_FOR_SEARCH_TYPE_USER);;
}
}
@@ -71,18 +73,20 @@ public function __construct(&$post, $user_id, $context_id) {
$user = get_record('user', 'id', $user_id);
// we cannot call userdate with relevant locale at indexing time.
- $doc->title = get_string('post').': '.fullname($user);
+ // $doc->title = get_string('post').': '.fullname($user);
+ $doc->title = $post['subject'];
$doc->date = $post['created'];
//remove '(ip.ip.ip.ip)' from chat author list
$doc->author = fullname($user);
$doc->contents = $post['description'];
- $doc->url = user_make_link($user_id, 'post');
+ // $doc->url = user_make_link($user_id, 'post');
+ $doc->url = user_make_link($post['id'], 'post');
// module specific information; optional
// construct the parent class
- parent::__construct($doc, $data, 0, 0, 0, PATH_FOR_SEARCH_TYPE_USER);
+ parent::__construct($doc, $data, 0, 0, $user_id, PATH_FOR_SEARCH_TYPE_USER);
}
}
@@ -116,7 +120,7 @@ public function __construct(&$post, $context_id) {
// module specific information; optional
// construct the parent class
- parent::__construct($doc, $data, 0, 0, 0, PATH_FOR_SEARCH_TYPE_USER);
+ parent::__construct($doc, $data, 0, 0, $post['userid'], PATH_FOR_SEARCH_TYPE_USER);
}
}
@@ -134,7 +138,7 @@ function user_make_link($itemid, $itemtype) {
if ($itemtype == 'user'){
return $CFG->wwwroot.'/user/view.php?id='.$itemid;
} elseif ($itemtype == 'post') {
- return $CFG->wwwroot.'/blog/index.php?userid='.$itemid;
+ return $CFG->wwwroot.'/blog/index.php?postid='.$itemid;
} elseif ($itemtype == 'attachment') {
$post = get_record('post', 'id', $itemid);
if (!$CFG->slasharguments){
Oops, something went wrong.

0 comments on commit 29dc93d

Please sign in to comment.