]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-13214 rebuild_course_cache fixes and speed improvements; merged from MOODLE_19_STABLE
authorskodak <skodak>
Fri, 1 Feb 2008 07:48:26 +0000 (07:48 +0000)
committerskodak <skodak>
Fri, 1 Feb 2008 07:48:26 +0000 (07:48 +0000)
course/lib.php
lib/filelib.php
mod/assignment/lib.php
mod/label/lib.php
mod/resource/lib.php

index 8f4ce3db2987b492f3a806a5ffb29c6128a57121..8f0c9dd3e6e9d871809ab6262b9c47db8e346d18 100644 (file)
@@ -1480,10 +1480,26 @@ function print_section_add_menus($course, $section, $modnames, $vertical=false,
     }
 }
 
-function rebuild_course_cache($courseid=0) {
+/**
+ * Rebuilds the cached list of course activities stored in the database
+ * @param int $courseid - id of course to rebuil, empty means all
+ * @param boolean $clearonly - only clear the modinfo fields, gets rebuild automatically on the fly
+ */
+function rebuild_course_cache($courseid=0, $clearonly=false) {
     global $COURSE;
-// Rebuilds the cached list of course activities stored in the database
-// If a courseid is not specified, then all are rebuilt
+
+    if ($clearonly) {
+        $courseselect = empty($courseid) ? "" : "id = $courseid";
+        set_field_select('course', 'modinfo', null, $courseselect);
+        // update cached global COURSE too ;-)
+        if ($courseid == $COURSE->id) {
+            $COURSE->modinfo = null; 
+        }
+        // reset the fast modinfo cache
+        $reset = 'reset';
+        get_fast_modinfo($reset);
+        return;
+    }
 
     if ($courseid) {
         $select = "id = '$courseid'";
@@ -1492,8 +1508,8 @@ function rebuild_course_cache($courseid=0) {
         @set_time_limit(0);  // this could take a while!   MDL-10954
     }
 
-    if ($courses = get_records_select("course", $select,'','id,fullname')) {
-        foreach ($courses as $course) {
+    if ($rs = get_recordset_select("course", $select,'','id,fullname')) {
+        while($course = rs_fetch_next_record($rs)) {
             $modinfo = serialize(get_array_of_activities($course->id));
             if (!set_field("course", "modinfo", $modinfo, "id", $course->id)) {
                 notify("Could not cache module information for course '" . format_string($course->fullname) . "'!");
@@ -1503,6 +1519,7 @@ function rebuild_course_cache($courseid=0) {
                 $COURSE->modinfo = $modinfo; 
             }
         }
+        rs_close($rs);
     }
     // reset the fast modinfo cache
     $reset = 'reset';
index f1beef95490f5227cbfeb7c14dbee948995c8ec7..92a8e70a4457ba7a3c86f5aaf016192ac0c0b8f0 100644 (file)
@@ -406,8 +406,10 @@ function get_mimetypes_array() {
  * @return string Requested piece of information from array
  */
 function mimeinfo($element, $filename) {
-    static $mimeinfo;
-    $mimeinfo=get_mimetypes_array();
+    static $mimeinfo = null;
+    if (is_null($mimeinfo)) {
+        $mimeinfo = get_mimetypes_array();
+    }
 
     if (eregi('\.([a-z0-9]+)$', $filename, $match)) {
         if (isset($mimeinfo[strtolower($match[1])][$element])) {
index e58e22c63950da9befd7140766d6c11769d2e92f..59ab2386ab0879116f69994b0b0f552d3befbef3 100644 (file)
@@ -21,7 +21,6 @@ class assignment_base {
     var $strsubmissions;
     var $strlastmodified;
     var $pagetitle;
-    var $currentgroup;
     var $usehtmleditor;
     var $defaultformat;
     var $context;
@@ -81,17 +80,8 @@ class assignment_base {
         $this->strlastmodified = get_string('lastmodified');
         $this->pagetitle = strip_tags($this->course->shortname.': '.$this->strassignment.': '.format_string($this->assignment->name,true));
 
-        // visibility
-        $context = get_context_instance(CONTEXT_MODULE, $cmid);
-        if (!$this->cm->visible and !has_capability('moodle/course:viewhiddenactivities', $context)) {
-            $pagetitle = strip_tags($this->course->shortname.': '.$this->strassignment);
-            $navigation = build_navigation('', $this->cm);
-
-            print_header($pagetitle, $this->course->fullname, $navigation,
-                         "", "", true, '', navmenu($this->course, $this->cm));
-            notice(get_string("activityiscurrentlyhidden"), "$CFG->wwwroot/course/view.php?id={$this->course->id}");
-        }
-        $this->currentgroup = groups_get_activity_group($this->cm);
+        // visibility handled by require_login() with $cm parameter
+        // get current group only when really needed
 
     /// Set up things for a HTML editor if it's needed
         if ($this->usehtmleditor = can_use_html_editor()) {
@@ -150,9 +140,7 @@ class assignment_base {
                      true, update_module_button($this->cm->id, $this->course->id, $this->strassignment),
                      navmenu($this->course, $this->cm));
 
-        $groupmode = groups_get_activity_groupmode($this->cm);
         groups_print_activity_menu($this->cm, 'view.php?id=' . $this->cm->id);
-        $this->currentgroup = groups_get_activity_group($this->cm); // must be done after the printing!
 
         echo '<div class="reportlink">'.$this->submittedlink().'</div>';
         echo '<div class="clearer"></div>';
@@ -305,7 +293,7 @@ class assignment_base {
             if ($allgroups and has_capability('moodle/site:accessallgroups', $context)) {
                 $group = 0;
             } else {
-                $group = $this->currentgroup;
+                $group = groups_get_activity_group($this->cm);
             }
             if ($count = $this->count_real_submissions($group)) {
                 $submitted = '<a href="submissions.php?id='.$this->cm->id.'">'.
@@ -2756,15 +2744,22 @@ function assignment_get_all_submissions($assignment, $sort="", $dir="DESC") {
 function assignment_get_coursemodule_info($coursemodule) {
     global $CFG;
 
-    if (! $assignment = get_record('assignment', 'id', $coursemodule->instance)) {
+    if (! $type = get_field('assignment', 'assignmenttype', 'id', $coursemodule->instance)) {
         return false;
     }
 
-    require_once("$CFG->dirroot/mod/assignment/type/$assignment->assignmenttype/assignment.class.php");
-    $assignmentclass = "assignment_$assignment->assignmenttype";
-    $ass = new $assignmentclass($coursemodule->id, $assignment);
+    $libfile = "$CFG->dirroot/mod/assignment/type/$type/assignment.class.php";
 
-    return $ass->get_coursemodule_info($coursemodule);
+    if (file_exists($libfile)) {
+        require_once($libfile);
+        $assignmentclass = "assignment_$type";
+        $ass = new $assignmentclass('staticonly');
+        return $ass->get_coursemodule_info($coursemodule);
+
+    } else {
+        debugging('Incorrect assignment type: '.$type);
+        return false;
+    }
 }
 
 
index 0422283fd0ed9e92d2b2d32851d43a7bb42b6025..e4425f26820f36b56ec0918980be51cd6b68395d 100644 (file)
@@ -64,15 +64,16 @@ function label_get_participants($labelid) {
     return false;
 }
 
+/**
+ * Given a course_module object, this function returns any
+ * "extra" information that may be needed when printing
+ * this activity in a course listing.
+ * See get_array_of_activities() in course/lib.php
+ */
 function label_get_coursemodule_info($coursemodule) {
-/// Given a course_module object, this function returns any 
-/// "extra" information that may be needed when printing
-/// this activity in a course listing.
-///
-/// See get_array_of_activities() in course/lib.php
-    if ($label = get_record("label", "id", $coursemodule->instance)) {
+    if ($content = get_field('label', 'content', 'id', $coursemodule->instance)) {
         $info = new object();
-        $info->extra = urlencode($label->content);
+        $info->extra = urlencode($content);
         return $info;
     } else {
         return null;
index 4ca2060058a73bafd324a6262a44436044237dd8..e89605dbd74b0f2157a4ae748848f1ab804e392d 100644 (file)
@@ -349,7 +349,7 @@ function resource_get_coursemodule_info($coursemodule) {
 
    $info = NULL;
 
-   if ($resource = get_record("resource", "id", $coursemodule->instance)) {
+   if ($resource = get_record("resource", "id", $coursemodule->instance, '', '', '', '', 'id, popup, reference, type')) {
        $info = new object();
        if (!empty($resource->popup)) {
            $info->extra =  urlencode("onclick=\"this.target='resource$resource->id'; return ".