# This patch file was generated by NetBeans IDE
# This patch can be applied using context Tools: Apply Diff Patch action on respective folder.
# It uses platform neutral UTF-8 encoding.
# Above lines and this line are ignored by the patching process.
Index: moodle/search/documents/assignment_document.php
--- moodle/search/documents/assignment_document.php Base (1.7)
+++ moodle/search/documents/assignment_document.php Locally Modified (Based On 1.7)
@@ -30,7 +30,7 @@
     /**
     * constructor
     */
-    public function __construct(&$assignmentitem, $assignment_module_id, $itemtype, $course_id, $owner_id, $context_id) {
+    public function __construct(&$assignmentitem, $assignment_module_id, $itemtype, $course_id, $owner_id, $context_id , $submissionoffset = null) {
         // generic information; required
         $doc->docid         = $assignmentitem['id'];
         $doc->documenttype  = SEARCH_TYPE_ASSIGNMENT;
@@ -43,8 +43,13 @@
 
         //remove '(ip.ip.ip.ip)' from chat author list
         $doc->author        = $assignmentitem['authors'];
-        $doc->contents      = $assignmentitem['description'];
+        if ($itemtype == 'intro') {
+            $doc->contents      = $assignmentitem['intro'];
         $doc->url           = assignment_make_link($assignment_module_id, $itemtype, $owner_id);
+        } else {
+            $doc->contents      = $assignmentitem['data1'];
+            $doc->url           = assignment_make_link($assignment_module_id, $itemtype, $owner_id, $submissionoffset);
+        }
 
         // module specific information; optional
         $data->assignment         = $assignment_module_id;
@@ -64,12 +69,16 @@
 * @uses CFG
 * @return a well formed link to session display
 */
-function assignment_make_link($cm_id, $itemtype, $owner) {
+function assignment_make_link($cm_id, $itemtype, $owner, $submissionoffset=null) {
     global $CFG;
 
-    if ($itemtype == 'description')
+    if ($itemtype == 'intro') {
         return $CFG->wwwroot.'/mod/assignment/view.php?id='.$cm_id;
+    } else {
+        return $CFG->wwwroot.'/mod/assignment/submissions.php?id='.$cm_id.'&userid='.$owner.'&mode=single&offset='.$submissionoffset;
+        //?id=80&userid=4&mode=single&filter=0&offset=1
 }
+}
 
 /**
 * part of search engine API
@@ -102,11 +111,13 @@
 
         $assignment->authors = '';
         $assignment->date = $assignment->timemodified;
-        $documents[] = new AssignmentSearchDocument(get_object_vars($assignment), $cm->id, 'description', $assignment->course, null, $context->id);
+        $documents[] = new AssignmentSearchDocument(get_object_vars($assignment), $cm->id, 'intro', $assignment->course, null, $context->id);
 
         $submissions = assignment_get_all_submissions($assignment);
         if ($submissions){
+            $submissionoffset=-1;
             foreach($submissions as $submission){
+                $submissionoffset++;
                 $owner = $DB->get_record('user', array('id' => $submission->userid));
                 $submission->authors = fullname($owner);
                 $submission->assignmenttype = $assignment->assignmenttype;
@@ -140,7 +151,7 @@
                 if ($submitted->source = 'text'){
                     $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);
+                    $documents[] = new AssignmentSearchDocument(get_object_vars($submission), $cm->id, 'submission', $assignment->course, $submission->userid, $context->id, $submissionoffset);
                     mtrace("finished online submission for {$submission->authors} in assignment {$assignment->name}");
                 } elseif ($submitted->source = 'files'){
                     $SUBMITTED = opendir($submitted->path);
Index: moodle/search/documents/chat_document.php
--- moodle/search/documents/chat_document.php Base (1.14)
+++ moodle/search/documents/chat_document.php Locally Modified (Based On 1.14)
@@ -100,7 +100,7 @@
     $fromtimeclause = ($fromtime) ? "AND timestamp >= {$fromtime}" : '';
     $totimeclause = ($totime) ? "AND timestamp <= {$totime}" : '';
     $tracks = array();
-    $messages = $DB->get_records_select('chat_messages', "chatid = ':chatid' :from :to", array('chatid' => $chat_id, 'from' => $fromtimeclause, 'to' => $totimeclause), 'timestamp DESC');
+    $messages = $DB->get_records_select('chat_messages', "chatid = :chatid :from :to", array('chatid' => $chat_id, 'from' => $fromtimeclause, 'to' => $totimeclause), 'timestamp DESC');
     if ($messages){
         // splits discussions against groups
         $groupedMessages = array();
Index: moodle/search/documents/data_document.php
--- moodle/search/documents/data_document.php Base (1.14)
+++ moodle/search/documents/data_document.php Locally Modified (Based On 1.14)
@@ -161,16 +161,15 @@
           c.id,
           r.groupid,
           c.userid,
-          c.recordid,
+          c.itemid,
           c.content,
-          c.created,
-          c.modified,
+          c.timecreated,
           r.dataid
        FROM
-          {data_comments} as c,
           {data_records} as r 
+       JOIN
+          {comments} as c ON c.contextid = r.id
        WHERE
-          c.recordid = r.id AND
           r.dataid = ?
     ";
     $comments = $DB->get_records_sql($query, array($database_id));
@@ -232,7 +231,7 @@
     $records_comments = data_get_comments($database->id);
     if ($records_comments){
         foreach($records_comments as $aComment){
-            $aComment->title = $recordsTitle[$aComment->recordid];
\ No newline at end of file
+            $aComment->title = $recordsTitle[$aComment->itemid];
\ No newline at end of file
             $authoruser = $DB->get_record('user', array('id' => $aComment->userid));
             $aComment->author = fullname($authoruser);
             $documents[] = new DataCommentSearchDocument(get_object_vars($aComment), $database->course, $context->id);
Index: moodle/search/documents/glossary_document.php
--- moodle/search/documents/glossary_document.php Base (1.17)
+++ moodle/search/documents/glossary_document.php Locally Modified (Based On 1.17)
@@ -74,19 +74,19 @@
         global $DB;
         
         // generic information; required
-        $doc->docid     = $entry['id'];
+        $doc->docid     = $entry['itemid'];
         $doc->documenttype  = SEARCH_TYPE_GLOSSARY;
         $doc->itemtype      = 'comment';
         $doc->contextid     = $context_id;
 
         $doc->title     = get_string('commenton', 'search') . ' ' . $entry['concept'];
-        $doc->date      = $entry['timemodified'];
+        $doc->date      = $entry['timecreated'];
 
         if ($entry['userid'])
             $user = $DB->get_record('user', array('id' => $entry['userid']));
         $doc->author    = ($user ) ? $user->firstname.' '.$user->lastname : '' ;
-        $doc->contents  = strip_tags($entry['entrycomment']);
-        $doc->url       = glossary_make_link($entry['entryid']);
+        $doc->contents  = strip_tags($entry['content']);
+        $doc->url       = glossary_make_link($entry['itemid']);
         
         // module specific information; optional
         $data->glossary = $glossary_id;
@@ -104,6 +104,7 @@
 */
 function glossary_make_link($entry_id) {
     global $CFG;
+    require_once($CFG->dirroot.'/search/querylib.php');
 
     //links directly to entry
     // return $CFG->wwwroot.'/mod/glossary/showentry.php?eid='.$entry_id;
@@ -158,7 +159,14 @@
     
     // index comments
     if (count($entryIds)){
-        $comments = $DB->get_records_list('glossary_comments', 'entryid', $entryIds);
\ No newline at end of file
+        list($entryidssql, $params) = $DB->get_in_or_equal($entryIds, SQL_PARAMS_NAMED);
+        $params['ctxid'] = $context->id;
+        $sql = "SELECT *
+                  FROM {comments}
+                 WHERE contextid = :ctxid 
+                    AND itemid $entryidssql";
+        $comments = $DB->get_recordset_sql($sql, $params);
+
\ No newline at end of file
         if ($comments){
             foreach($comments as $comment) {
                 if (strlen($comment->entrycomment) > 0) {
Index: moodle/search/documents/label_document.php
--- moodle/search/documents/label_document.php Base (1.5)
+++ moodle/search/documents/label_document.php Locally Modified (Based On 1.5)
@@ -39,7 +39,7 @@
         $doc->title     = strip_tags($label['name']);
         $doc->date      = $label['timemodified'];
         $doc->author    = '';
-        $doc->contents  = strip_tags($label['content']);
\ No newline at end of file
+        $doc->contents  = strip_tags($label['intro']);
\ No newline at end of file
         $doc->url       = label_make_link($label['course']);
         
         // module specific information; optional
Index: moodle/search/documents/resource_document.php
--- moodle/search/documents/resource_document.php Base (1.23)
+++ moodle/search/documents/resource_document.php Locally Modified (Based On 1.23)
@@ -83,14 +83,23 @@
 function resource_get_content_for_index(&$notneeded) {
     global $CFG, $DB;
 
+
     // starting with Moodle native resources
     $documents = array();
+
+    $dbman = $DB->get_manager();
+    if (!$dbman->table_exists('resource_old')) {
+        return $documents;
+    }
+
+    // the resources have been moved into modules of their own. indexing need to be created for these.
+    // for a temporary fix (until MDL-24856 is fixed) pointing this query to a table that is copy of the old resource table schema.
     $query = "
         SELECT 
             id as trueid,
             r.*
         FROM 
-            {resource} as r
+            {resource_old} as r
         WHERE 
             alltext != '' AND 
             alltext != ' ' AND 
@@ -127,7 +136,7 @@
                r.type as type,
                r.timemodified as timemodified
             FROM 
-                {resource} as r,
\ No newline at end of file
+                {resource_old} as r,
\ No newline at end of file
                 {course_modules} as cm,
                 {modules} as m
             WHERE 
Index: moodle/search/documents/wiki_document.php
--- moodle/search/documents/wiki_document.php Base (1.21)
+++ moodle/search/documents/wiki_document.php Locally Modified (Based On 1.21)
@@ -40,15 +40,15 @@
         $doc->itemtype      = 'standard';
         $doc->contextid     = $context_id;
 
-        $doc->title     = $page['pagename'];
-        $doc->date      = $page['lastmodified'];
+        $doc->title     = $page['title'];
+        $doc->date      = $page['timemodified'];
         //remove '(ip.ip.ip.ip)' from wiki author field
-        $doc->author    = preg_replace('/\(.*?\)/', '', $page['author']);
-        $doc->contents  = $page['content'];
-        $doc->url       = wiki_make_link($wiki_id, $page['pagename'], $page['version']);
+        $doc->author    = $page['author'];
+        $doc->contents  = $page['cachedcontent'];
+        $doc->url       = wiki_make_link($page['id']);
 
         // module specific information; optional
-        $data->version  = $page['version'];
+        //$data->version  = $page['version'];
         $data->wiki     = $wiki_id;
 
         // construct the parent class
@@ -72,10 +72,10 @@
 * @param int $version
 * @uses $CFG
 */
-function wiki_make_link($wikiId, $title, $version) {
+function wiki_make_link($pageid) {
     global $CFG;
 
-    return $CFG->wwwroot.'/mod/wiki/view.php?wid='.$wikiId.'&amp;page='.wiki_name_convert($title).'&amp;version='.$version;
+    return $CFG->wwwroot.'/mod/wiki/view.php?pageid='.$pageid;
 }
 
 /**
@@ -89,19 +89,21 @@
 function wiki_get_latest_page(&$entry, $pagename, $version = 0) {
     global $DB;
 
-    $pagename = $pagename;
+    $params = array('title' => $pagename, 'subwikiid' => $entry->id);
 
     if ($version > 0 && is_int($version)) {
         $versionclause = "AND ( version = :version )";
+        $sort   = 'version DESC';
+        $params['version'] = $version;
     } else {
         $versionclause = '';
+        $sort   = '';
     }
 
-    $select = "( pagename = ':pagename' ) AND wiki = :wikiid $versionclause ";
-    $sort   = 'version DESC';
+    $select = "( title = :title ) AND subwikiid = :subwikiid $versionclause ";
 
     //change this to recordset_select, as per http://docs.moodle.org/en/Datalib_Notes
-    if ($result_arr = $DB->get_records_select('wiki_pages', $select, array('pagename' => $pagename, 'wikiid' => $entry->id, 'version' => $version), $sort, '*', 0, 1)) {
+    if ($result_arr = $DB->get_records_select('wiki_pages', $select, $params, $sort, '*', 0, 1)) {
         foreach ($result_arr as $obj) {
             $result_obj = $obj;
         }
@@ -146,10 +148,10 @@
     $pages = array();
 
     //http://moodle.org/bugs/bug.php?op=show&bugid=5877&pos=0
-    if ($ids = $DB->get_records('wiki_pages', array('wiki' => $entry->id), '', 'distinct pagename')) {
-        if ($pagesets = $DB->get_records('wiki_pages', array('wiki' => $entry->id), '', 'distinct pagename')) {
+    if ($ids = $DB->get_records('wiki_pages', array('subwikiid' => $entry->id), '', 'distinct title')) {
+        if ($pagesets = $DB->get_records('wiki_pages', array('subwikiid' => $entry->id), '', 'distinct title')) {
             foreach ($pagesets as $aPageset) {
-                $pages[] = wiki_get_latest_page($entry, $aPageset->pagename);
+                $pages[] = wiki_get_latest_page($entry, $aPageset->title);
             }
         } else {
             return false;
@@ -177,10 +179,11 @@
 * @return an array of searchable deocuments
 */
 function wiki_get_content_for_index(&$wiki) {
-    global $DB;
+    global $CFG, $DB;
+    require_once($CFG->dirroot . '/mod/wiki/locallib.php');
 
     $documents = array();
-    $entries = wiki_get_entries($wiki);
+    $entries = wiki_get_subwikis($wiki->id);
     if ($entries){
         $coursemodule = $DB->get_field('modules', 'id', array('name' => 'wiki'));
         $cm = $DB->get_record('course_modules', array('course' => $wiki->course, 'module' => $coursemodule, 'instance' => $wiki->id));
@@ -194,8 +197,10 @@
             $pages = wiki_get_latest_pages($entry);
             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);
\ No newline at end of file
+                    if (strlen($page->title) > 0) {
+                        $owner = $DB->get_record('user', array('id' => $page->userid));
+                        $page->author = fullname($owner);
+                        $documents[] = new WikiSearchDocument(get_object_vars($page), $entry->wikiid, $wiki->course, $entry->groupid, $page->userid, $context->id);
\ No newline at end of file
                     }
                 }
             }
Index: moodle/search/indexer.php
--- moodle/search/indexer.php Base (1.30)
+++ moodle/search/indexer.php Locally Modified (Based On 1.30)
@@ -26,10 +26,6 @@
 * to the 'dbid' field in the index
 * */
 
-//this'll take some time, set up the environment
-@set_time_limit(0);
-@ob_implicit_flush(true);
-@ob_end_flush();
 
 /**
 * includes and requires
@@ -37,6 +33,11 @@
 require_once('../config.php');
 require_once($CFG->dirroot.'/search/lib.php');
 
+//this'll take some time, set up the environment
+@set_time_limit(0);
+@ob_implicit_flush(true);
+@ob_end_flush();
+
     ini_set('include_path', $CFG->dirroot.DIRECTORY_SEPARATOR.'search'.PATH_SEPARATOR.ini_get('include_path'));
 
 /// only administrators can index the moodle installation, because access to all pages is required
@@ -158,6 +159,10 @@
                                 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;
+                                    }
\ No newline at end of file
                                     //object to insert into db
                                     $dbid = $dbcontrol->addDocument($document);
                                     
Index: moodle/search/indexersplash.php
--- moodle/search/indexersplash.php Base (1.27)
+++ moodle/search/indexersplash.php Locally Modified (Based On 1.27)
@@ -48,6 +48,7 @@
         $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'));
Index: moodle/search/stats.php
--- moodle/search/stats.php Base (1.35)
+++ moodle/search/stats.php Locally Modified (Based On 1.35)
@@ -107,7 +107,8 @@
         }
 
         echo html_writer::table($admin_table);
-        echo $OUTPUT->spacer(array('height'=>20, 'br'=>true)); // should be done with CSS instead
+        $spacer = array('height'=>20, 'br'=>true);
+        echo $OUTPUT->spacer($spacer); // should be done with CSS instead
         echo $OUTPUT->heading($solutionsstr);
 
         unset($admin_table->data);
