Skip to content

Commit

Permalink
Merge branch 'wip-MDL-36789-m24' of git://github.com/marinaglancy/moo…
Browse files Browse the repository at this point in the history
…dle into MOODLE_24_STABLE
  • Loading branch information
Damyon Wiese committed Aug 19, 2013
2 parents 2f64dd6 + b9f0a2b commit c937077
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions lib/modinfolib.php
Expand Up @@ -242,7 +242,7 @@ public function get_section_info($sectionnumber, $strictness = IGNORE_MISSING) {
* @param int $userid User ID
*/
public function __construct($course, $userid) {
global $CFG, $DB;
global $CFG, $DB, $COURSE, $SITE;

// Check modinfo field is set. If not, build and load it.
if (empty($course->modinfo) || empty($course->sectioncache)) {
Expand Down Expand Up @@ -287,9 +287,29 @@ public function __construct($course, $userid) {
}
}

// If we haven't already preloaded contexts for the course, do it now
// If we haven't already preloaded contexts for the course, do it now.
// Modules are also cached here as long as it's the first time this course has been preloaded.
preload_course_contexts($course->id);

// Quick integrity check: as a result of race conditions modinfo may not be regenerated after the change.
// It is especially dangerous if modinfo contains the deleted course module, as it results in fatal error.
// We can check it very cheap by validating the existence of module context.
if ($course->id == $COURSE->id || $course->id == $SITE->id) {
// Only verify current course (or frontpage) as pages with many courses may not have module contexts cached.
// (Uncached modules will result in a very slow verification).
foreach ($info as $mod) {
if (!context_module::instance($mod->cm, IGNORE_MISSING)) {
debugging('Course cache integrity check failed: course module with id '. $mod->cm.
' does not have context. Rebuilding cache for course '. $course->id);
rebuild_course_cache($course->id);
$this->course = $DB->get_record('course', array('id' => $course->id), '*', MUST_EXIST);
$info = unserialize($this->course->modinfo);
$sectioncache = unserialize($this->course->sectioncache);
break;
}
}
}

// Loop through each piece of module data, constructing it
$modexists = array();
foreach ($info as $mod) {
Expand Down

0 comments on commit c937077

Please sign in to comment.