]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-19342 - small fixes from Tatsuva Shirai + UTF-8 global straighten up
authordiml <diml>
Sat, 30 May 2009 22:11:53 +0000 (22:11 +0000)
committerdiml <diml>
Sat, 30 May 2009 22:11:53 +0000 (22:11 +0000)
16 files changed:
search/Zend/Search/Lucene.php
search/documents/assignment_document.php
search/documents/chat_document.php
search/documents/data_document.php
search/documents/forum_document.php
search/documents/glossary_document.php
search/documents/label_document.php
search/documents/lesson_document.php
search/documents/physical_doc.php
search/documents/physical_odt.php
search/documents/physical_ppt.php
search/documents/resource_document.php
search/documents/user_document.php
search/documents/wiki_document.php
search/query.php
search/querylib.php

index 0cd4d8a12c14189cc307239edf63fea06cf98f7e..3b9fd8e97263201d73ba0e3f57975554ab34b621 100644 (file)
@@ -62,6 +62,7 @@ require_once "Zend/Search/Lucene/Index/SegmentInfoPriorityQueue.php";
 
 /** Zend_Search_Lucene_LockManager */
 require_once "Zend/Search/Lucene/LockManager.php";
+//require_once "Zend/Search/Lucene/SoftLockManager.php";
 
 
 
@@ -409,7 +410,7 @@ class Zend_Search_Lucene implements Zend_Search_Lucene_Interface
         Zend_Search_Lucene_LockManager::obtainReadLock($this->_directory);
         
         // Escalate read lock to prevent current generation index files to be deleted while opening process is not done 
-//        Zend_Search_Lucene_LockManager::escalateReadLock($this->_directory);
+        Zend_Search_Lucene_LockManager::escalateReadLock($this->_directory);
         
         
         $this->_generation = self::getActualGeneration($this->_directory);
@@ -452,7 +453,7 @@ class Zend_Search_Lucene implements Zend_Search_Lucene_Interface
         }
         
         // De-escalate read lock to prevent current generation index files to be deleted while opening process is not done 
-//        Zend_Search_Lucene_LockManager::escalateReadLock($this->_directory);
+        Zend_Search_Lucene_LockManager::deEscalateReadLock($this->_directory);
     }
 
     /**
index 8712d752378f1153c3eb2a45ab3db89ade37d941..caf5f007a54ca0e03a39f3ad2e9e6237458c0c7a 100644 (file)
@@ -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
 * @version Moodle 2.0
@@ -230,7 +231,9 @@ function assignment_single_document($id, $itemtype) {
         }
     } elseif ($itemtype == 'submission') {
         if ($submission = $DB->get_record('assignment_submissions', array('id' => $id))){
-            $assignment = $DB->get_record('assignment', array('id' => $submission->assignment));
+            if (!$assignment = $DB->get_record('assignment', array('id' => $submission->assignment))){
+                return null;
+            }
         } else {
             return null;
         }
@@ -308,6 +311,8 @@ function assignment_check_text_access($path, $itemtype, $this_id, $user, $group_
     $context = $DB->get_record('context', array('id' => $context_id));
     $cm = $DB->get_record('course_modules', array('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;
index d17edc5e1298f795d961fe8f8b97bd48565d5789..dd8962242b062ae2dc4536b22c351d82e79d2bf2 100644 (file)
@@ -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
 * @version Moodle 2.0
@@ -272,6 +273,8 @@ function chat_check_text_access($path, $itemtype, $this_id, $user, $group_id, $c
     $context = $DB->get_record('context', array('id' => $context_id));
     $cm = $DB->get_record('course_modules', array('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 chat ";
         return false;
index a05bf67a768af4267a988ba024ba2128bae3d32b..8fafd52233f9420e4750ac2699e4cc720b2f778c 100644 (file)
@@ -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
 * @version Moodle 2.0
@@ -82,7 +83,7 @@ class DataCommentSearchDocument extends SearchDocument {
         //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'];
@@ -205,7 +206,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) {
     
@@ -232,6 +233,8 @@ function data_get_content_for_index(&$database) {
     if ($records_comments){
         foreach($records_comments as $aComment){
             $aComment->title = $recordsTitle[$aComment->recordid];
+            $authoruser = $DB->get_record('user', array('id' => $aComment->userid));
+            $aComment->author = fullname($authoruser);
             $documents[] = new DataCommentSearchDocument(get_object_vars($aComment), $database->course, $context->id);
         }
     }
@@ -257,7 +260,7 @@ function data_single_document($id, $itemtype) {
         $cm = $DB->get_record('course_modules', array('course' => $record_course, 'module' => $coursemodule, 'instance' => $recordMetaData->dataid));
         $context = get_context_instance(CONTEXT_MODULE, $cm->id);
         // 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
@@ -290,6 +293,8 @@ function data_single_document($id, $itemtype) {
         $comment->title = $DB->get_field('search_document', 'title', array('docid' => $record->id, 'itemtype' => 'record'));
         $comment->dataid = $record->dataid;
         $comment->groupid = $record->groupid;
+        $authoruser = $DB->get_record('user', array('id' => $comment->userid));
+        $comment->author = fullname($authoruser);
         // make document
         return new DataCommentSearchDocument(get_object_vars($comment), $record_course, $context->id);
     } else {
@@ -356,6 +361,8 @@ function data_check_text_access($path, $itemtype, $this_id, $user, $group_id, $c
     $context = $DB->get_record('context', array('id' => $context_id));
     $cm = $DB->get_record('course_modules', array('id' => $context->instanceid));
 
+    if (empty($cm)) return false; // Shirai 20090530 - MDL19342 - course module might have been delete
+
     if (!$cm->visible && !has_capability('moodle/course:viewhiddenactivities', $context)) {
         if (!empty($CFG->search_access_debug)) echo "search reject : hidden database ";
         return false;
index 259b0782f990a255c4262999cb0eb965a8c2de05..8e5c939c009e215d8a5435746acf64fa29db2828 100644 (file)
@@ -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
 * @version Moodle 2.0
@@ -291,8 +292,9 @@ function forum_check_text_access($path, $itemtype, $this_id, $user, $group_id, $
     $discussion = $DB->get_record('forum_discussions', array('id' => $post->discussion));
     $context = $DB->get_record('context', array('id' => $context_id));
     $cm = $DB->get_record('course_modules', array('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 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 forum resource ";
         return false;
index 034897ae25b7439d824c00ea143a93be2b2d7083..b923866b31f371d186e9ab3f3ba7f53551f55e4b 100644 (file)
@@ -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
 * @version Moodle 2.0
@@ -246,6 +247,8 @@ function glossary_check_text_access($path, $itemtype, $this_id, $user, $group_id
     $context = $DB->get_record('context', array('id' => $context_id));
     $cm = $DB->get_record('course_modules', array('id' => $context->instanceid));
 
+    if (empty($cm)) return false; // Shirai 20090530 - MDL19342 - course module might have been delete
+
     if (!$cm->visible && !has_capability('moodle/course:viewhiddenactivities', $context)) {
         return false;
     }
index 915d22f624d30abdae68b0b16ca52ea07eb3c53d..7c9bcef3d77535d7de77f3891edf9b33767dac62 100644 (file)
@@ -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
 * @version Moodle 2.0
@@ -158,6 +159,9 @@ function label_check_text_access($path, $itemtype, $this_id, $user, $group_id, $
     $r = $DB->get_record('label', array('id' => $this_id));
     $module_context = $DB->get_record('context', array('id' => $context_id));
     $cm = $DB->get_record('course_modules', array('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 englobing course is visible
index cc874a31d3c727d73cccf8180a8968cb9882858a..54759a942802ae43f341359ffd4b81d491cf5a93 100644 (file)
@@ -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
 * @version Moodle 2.0
@@ -182,6 +183,8 @@ function lesson_check_text_access($path, $itemtype, $this_id, $user, $group_id,
     $context = $DB->get_record('context', array('id' => $context_id));
     $cm = $DB->get_record('course_modules', array('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 lesson ";
         return false;
index 8c002d1315c50d81b87763935fc4193c71197e05..2679800c5dacfd993125991b2ef70e9ee5da8294 100644 (file)
@@ -36,7 +36,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 : executable not found at '.$moodleroot.$CFG->block_search_word_to_text_cmd);
         } else {
             if ($directfile == ''){
                 $file = escapeshellarg("{$CFG->dataroot}/{$resource->course}/{$resource->reference}");
index adde07fd0a7c94818bc4e002ea508d83577b68a7..e7539a099807bbbe3dc829bd297ebc0c9d903d2a 100644 (file)
@@ -36,7 +36,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 : exectuable not found at '.$moodleroot.$CFG->block_search_odt_to_text_cmd);
         } else {
             if ($directfile == ''){
                 $file = escapeshellarg("{$CFG->dataroot}/{$resource->course}/{$resource->reference}");
index 2332b29b10999bc77b312dd6b184c7908acfb4ef..7dd14e6c8b4fcee6192fb1414308ac10566d84b1 100644 (file)
@@ -90,7 +90,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');
     return $indextext;
 }
 ?>
\ No newline at end of file
index 271e3181141ee7f193d45a304b703a4576341699..ffa0422c18c93dc316dd9fd58ee32a43c43da250 100644 (file)
@@ -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
 * @version Moodle 2.0
@@ -89,7 +90,7 @@ function resource_get_content_for_index(&$notneeded) {
             id as trueid,
             r.*
         FROM 
-            {resource} r
+            {resource} as r
         WHERE 
             alltext != '' AND 
             alltext != ' ' AND 
@@ -126,9 +127,9 @@ function resource_get_content_for_index(&$notneeded) {
                r.type as type,
                r.timemodified as timemodified
             FROM 
-                {resource} r,
-                {course_modules} cm,
-                {modules} m
+                {resource} as r,
+                {course_modules} as cm,
+                {modules} as m
             WHERE 
                r.type = 'file' AND
                cm.instance = r.id AND
@@ -239,9 +240,9 @@ function resource_single_document($id, $itemtype) {
            r.type as type,
            r.timemodified as timemodified
         FROM 
-            {resource} r,
-            {course_modules} cm,
-            {modules} m
+            {resource} as r,
+            {course_modules} as cm,
+            {modules} as m
         WHERE 
             cm.instance = r.id AND
             cm.course = r.course AND
@@ -312,6 +313,9 @@ function resource_check_text_access($path, $itemtype, $this_id, $user, $group_id
     $r = $DB->get_record('resource', array('id' => $this_id));
     $module_context = $DB->get_record('context', array('id' => $context_id));
     $cm = $DB->get_record('course_modules', array('id' => $module_context->instanceid));
+
+    if (empty($cm)) return false; // Shirai 20090530 - MDL19342 - course module might have been delete
+
     $course = $DB->get_record('course', array('id' => $r->course));
     $course_context = get_context_instance(CONTEXT_COURSE, $r->course);
 
index a77faaaaf5a51b6b159bc2d005c2895dd98647eb..5df1e340fd27a54369a491d7f44d2ee6b17f0f1e 100644 (file)
@@ -51,7 +51,7 @@ class UserSearchDocument extends SearchDocument {
         // 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);
     } 
 }
 
@@ -77,18 +77,20 @@ class UserPostSearchDocument extends SearchDocument {
         $user               = $DB->get_record('user', array('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);
     } 
 }
 
@@ -125,7 +127,7 @@ class UserBlogAttachmentSearchDocument extends SearchDocument {
         // 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);
     } 
 }
 
@@ -143,7 +145,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 = $DB->get_record('post', array('id' => $itemid));
         if (!$CFG->slasharguments){
index dd30807587e3a6ff579de4727bf433398088185a..d3c6cc809f3e11669eccd77bfbf944a1ae990336 100644 (file)
@@ -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
 * @version Moodle 2.0
@@ -264,6 +265,9 @@ function wiki_check_text_access($path, $itemtype, $this_id, $user, $group_id, $c
     $course = $DB->get_record('course', array('id' => $entry->course));
     $context = $DB->get_record('context', array('id' => $context_id));
     $cm = $DB->get_record('course_modules', array('id' => $context->instanceid));
+
+    if (empty($cm)) return false; // Shirai 20090530 - MDL19342 - course module might have been delete
+
     if (!$cm->visible && !has_capability('moodle/course:viewhiddenactivities', $context)) {
         if (!empty($CFG->search_access_debug)) echo "search reject : hidden wiki ";
         return false;
index 68990e56b5d2ea2250fe01085a8663867bcf6d50..5da64bfdfc2fb4449cfc080bb77d5417e1f8d78b 100644 (file)
@@ -7,7 +7,6 @@
     * @subpackage search_engine
     * @author Michael Champanis (mchampan) [cynnical@gmail.com], Valery Fremaux [valery.fremaux@club-internet.fr] > 1.8
     * @date 2008/03/31
-    * @version prepared for 2.0
     * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
     *
     * The query page - accepts a user-entered query string and returns results.
         } 
         
         // add module restriction
-        $doctypestr = get_string('doctype', 'search');
-        $titlestr = get_string('title', 'search');
-        $authorstr = get_string('author', 'search');
+        $doctypestr = 'doctype';
+        $titlestr = 'title';
+        $authorstr = 'author';
         if ($adv->module != 'all') {
             $query_string .= " +{$doctypestr}:".$adv->module;
         } 
     ?>
     </form>
     <br/>
-    <div class="mdl-align">
+    
+    <div align="center">
     <?php
     print_string('searching', 'search') . ': ';
     
             foreach ($hits as $listing) {  
                 
                 if ($listing->doctype == 'user'){ // A special handle for users                    
-                    $icon = print_user_picture ($listing->author, 0, true, 0, true, false) ;
+                    $icon = print_user_picture ($listing->userid, 0, true, 0, true, false) ;
                 } else {
                     $iconpath = $CFG->modpixpath.'/'.$listing->doctype.'/icon.gif';
                     $icon = "<img align=\"top\" src=\"".$iconpath."\" class=\"activityicon\" alt=\"\"/>";
         }     
         print_box_end();
     ?>
-    <div class="mdl-align">
+    <div align="center">
     <?php 
         print_string('ittook', 'search');
         search_stopwatch(); 
index 8591be9ccd53843c830e6cf7b7ccedc0acce4d10..c5f4e318f086b24c8293fe6a7510f2761f8bb2c0 100644 (file)
@@ -7,7 +7,6 @@
 * @subpackage search_engine
 * @author Michael Champanis (mchampan) [cynnical@gmail.com], Valery Fremaux [valery.fremaux@club-internet.fr] > 1.8
 * @date 2008/03/31
-* @version prepared for 2.0
 * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
 */
 
@@ -278,6 +277,7 @@ class SearchQuery {
                     $resultdoc->doctype = $hit->doctype;
                     $resultdoc->author  = $hit->author;
                     $resultdoc->courseid = $hit->course_id;
+                    $resultdoc->userid = $hit->user_id;
                     
                     //and store it
                     $resultdocs[] = clone($resultdoc);
@@ -326,12 +326,12 @@ class SearchQuery {
     */
     public function page_numbers() {
       $pages  = $this->total_pages();
-      $query  = htmlentities($this->term);
+      $query = htmlentities($this->term,ENT_NOQUOTES,'utf-8');
       $page   = $this->pagenumber;
       $next   = get_string('next', 'search');
       $back   = get_string('back', 'search');
 
-      $ret = "<div class='mdl-align' id='search_page_links'>";
+      $ret = "<div align='center' id='search_page_links'>";
 
       //Back is disabled if we're on page 1
       if ($page > 1) {
@@ -492,4 +492,4 @@ class SearchQuery {
       return $this->results_per_page;
     }
 }
-?>
+?>
\ No newline at end of file