@@ -289,7 +289,14 @@ public function __construct($course, $userid) { // hmm, something is wrong - let's fix it rebuild_course_cache($course->id); $course->sectioncache = $DB->get_field('course', 'sectioncache', array('id'=>$course->id)); - $sectioncache = unserialize($course->sectioncache); + // MDL-41896 Error writing to database when multiple sections inline images + // so if we could not store the sectioncache we need to build it again + if (!$course->sectioncache) { + $sectioncache = course_modinfo::build_section_cache($course->id); + } else { + $sectioncache = unserialize($course->sectioncache); + } + if (!is_array($sectioncache)) { // If it still fails, abort debugging('Problem with "sectioncache" data for this course'); @@ -1454,9 +1461,21 @@ function rebuild_course_cache($courseid=0, $clearonly=false) { foreach ($rs as $course) { $modinfo = serialize(get_array_of_activities($course->id)); $sectioncache = serialize(course_modinfo::build_section_cache($course->id)); - $updateobj = (object)array('id' => $course->id, - 'modinfo' => $modinfo, 'sectioncache' => $sectioncache); - $DB->update_record("course", $updateobj); + // MDL-41896 Error writing to database when multiple sections inline images + // if updating sectioncache and too big don't store it but build it each time + // Need to find someway of configing this as actual value set in DB e.g. 16M = 16777216 + $maxsectioncache=1048576; // 1Mb + if (strlen($sectioncache)<$maxsectioncache) { + $updateobj = (object)array('id' => $course->id, + 'modinfo' => $modinfo, 'sectioncache' => $sectioncache); + $DB->update_record("course", $updateobj); + } else { + // Too large to cache in sectioncache will need regeneration each time + $updateobj = (object)array('id' => $course->id, + 'modinfo' => $modinfo, 'sectioncache' => null); + $DB->update_record("course", $updateobj); + } + // update cached global COURSE too ;-) if ($course->id == $COURSE->id) { $COURSE->modinfo = $modinfo;