Also add the field cacherev to the lists of default fields in course retrieval functions
SET visibleold=visible, visible=0
WHERE module=?";
$DB->execute($sql, array($module->id));
- // clear the course modinfo cache for courses
- // where we just uninstalld something
- $sql = "UPDATE {course}
- SET modinfo=''
- WHERE id IN (SELECT DISTINCT course
+ // Increment course.cacherev for courses where we just made something invisible.
+ // This will force cache rebuilding on the next request.
+ increment_revision_number('course', 'cacherev',
+ "id IN (SELECT DISTINCT course
FROM {course_modules}
- WHERE visibleold=1 AND module=?)";
- $DB->execute($sql, array($module->id));
+ WHERE visibleold=1 AND module=?)",
+ array($module->id));
admin_get_root(true, false); // settings not required - only pages
}
}
$DB->set_field("modules", "visible", "1", array("id"=>$module->id)); // Show main module
$DB->set_field('course_modules', 'visible', '1', array('visibleold'=>1, 'module'=>$module->id)); // Get the previous saved visible state for the course module.
- // clear the course modinfo cache for courses
- // where we just made something visible
- $sql = "UPDATE {course}
- SET modinfo = ''
- WHERE id IN (SELECT DISTINCT course
+ // Increment course.cacherev for courses where we just made something visible.
+ // This will force cache rebuilding on the next request.
+ increment_revision_number('course', 'cacherev',
+ "id IN (SELECT DISTINCT course
FROM {course_modules}
- WHERE visible=1 AND module=?)";
- $DB->execute($sql, array($module->id));
+ WHERE visible=1 AND module=?)",
+ array($module->id));
admin_get_root(true, false); // settings not required - only pages
}
$limit = block_course_overview_get_max_user_courses();
- $courses = enrol_get_my_courses('id, shortname, fullname, modinfo, sectioncache');
+ $courses = enrol_get_my_courses();
$site = get_site();
if (array_key_exists($site->id,$courses)) {
$strcancel= get_string('cancel');
$stractivityclipboard = $USER->activitycopyname;
}
- // Casting $course->modinfo to string prevents one notice when the field is null.
$editbuttons = '';
if ($ismoving) {
$strcancel= get_string('cancel');
$stractivityclipboard = $USER->activitycopyname;
}
- // Casting $course->modinfo to string prevents one notice when the field is null.
$editbuttons = '';
if ($ismoving) {
$DB->set_field('course_modules', 'instance', $instanceid, array('id' => $this->cm->id));
// Rebuild the course cache after update action
rebuild_course_cache($this->course->id, true);
- $this->course->modinfo = null; // Otherwise we will just get the old version back again.
$sectionid = course_add_cm_to_section($this->course, $this->cm->id, $this->section);
'numsections' => 5),
array('createsections' => true));
- // Ensure all 6 (0-5) sections were created and modinfo/sectioninfo cache works properly
+ // Ensure all 6 (0-5) sections were created and course content cache works properly
$sectionscreated = array_keys(get_fast_modinfo($course)->get_section_info_all());
$this->assertEquals(range(0, $course->numsections), $sectionscreated);
$this->assertEquals($cmids[0], $sequence);
// Add a second, this time using courseid variant of parameters.
+ $coursecacherev = $DB->get_field('course', 'cacherev', array('id' => $course->id));
course_add_cm_to_section($course->id, $cmids[1], 1);
$sequence = $DB->get_field('course_sections', 'sequence', array('course' => $course->id, 'section' => 1));
$this->assertEquals($cmids[0] . ',' . $cmids[1], $sequence);
- // Check modinfo was not rebuilt (important for performance if calling
- // repeatedly).
- $this->assertNull($DB->get_field('course', 'modinfo', array('id' => $course->id)));
+ // Check that modinfo cache was reset but not rebuilt (important for performance if calling repeatedly).
+ $this->assertGreaterThan($coursecacherev, $DB->get_field('course', 'cacherev', array('id' => $course->id)));
+ $this->assertEmpty(cache::make('core', 'coursemodinfo')->get($course->id));
// Add one to section that doesn't exist (this might rebuild modinfo).
course_add_cm_to_section($course, $cmids[2], 2);
$course = (array)$course;
$this->assertEquals($basefields, array_keys($course), '', 0, 10, true);
- $courses = enrol_get_all_users_courses($user2->id, false, 'modinfo');
+ $courses = enrol_get_all_users_courses($user2->id, false, 'timecreated');
$course = reset($courses);
- $this->assertTrue(property_exists($course, 'modinfo'));
+ $this->assertTrue(property_exists($course, 'timecreated'));
$courses = enrol_get_all_users_courses($user2->id, false, null, 'id DESC');
$this->assertEquals(array($course3->id, $course2->id, $course1->id), array_keys($courses));
}
}
- // clear course.modinfo for courses that used this module
- $sql = "UPDATE {course}
- SET modinfo=''
- WHERE id IN (SELECT DISTINCT course
+ // Increment course.cacherev for courses that used this module.
+ // This will force cache rebuilding on the next request.
+ increment_revision_number('course', 'cacherev',
+ "id IN (SELECT DISTINCT course
FROM {course_modules}
- WHERE module=?)";
- $DB->execute($sql, array($module->id));
+ WHERE module=?)",
+ array($module->id));
// delete all the course module records
$DB->delete_records('course_modules', array('module' => $module->id));
$ctxselect = context_helper::get_preload_record_columns_sql('ctx');
$fields = array('c.id', 'c.category', 'c.sortorder',
'c.shortname', 'c.fullname', 'c.idnumber',
- 'c.startdate', 'c.visible');
+ 'c.startdate', 'c.visible', 'c.cacherev');
if (!empty($options['summary'])) {
$fields[] = 'c.summary';
$fields[] = 'c.summaryformat';
* was called with option 'summary'. Otherwise will be retrieved from DB on first request
* @property-read string $format Course format. Retrieved from DB on first request
* @property-read int $showgrades Retrieved from DB on first request
- * @property-read string $sectioncache Retrieved from DB on first request
- * @property-read string $modinfo Retrieved from DB on first request
* @property-read int $newsitems Retrieved from DB on first request
* @property-read int $startdate
* @property-read int $marker Retrieved from DB on first request
* @property-read int $requested Retrieved from DB on first request
* @property-read int $enablecompletion Retrieved from DB on first request
* @property-read int $completionnotify Retrieved from DB on first request
+ * @property-read int $cacherev
*
* @package core
* @subpackage course
$ccjoin = "LEFT JOIN {context} ctx ON (ctx.instanceid = c.id AND ctx.contextlevel = :contextlevel)";
$params['contextlevel'] = CONTEXT_COURSE;
- $fields = array_diff(array_keys($DB->get_columns('course')), array('modinfo', 'sectioncache'));
- $sql = "SELECT c.".join(',c.',$fields)." $ccselect
+ $sql = "SELECT c.* $ccselect
FROM {course} c
$ccjoin
WHERE $searchcond AND c.id <> ".SITEID."
$basefields = array('id', 'category', 'sortorder',
'shortname', 'fullname', 'idnumber',
'startdate', 'visible',
- 'groupmode', 'groupmodeforce');
+ 'groupmode', 'groupmodeforce', 'cacherev');
if (empty($fields)) {
$fields = $basefields;
$oldcourse = new stdClass();
$oldcourse->id = $course->id;
$oldcourse->summary = '';
- $oldcourse->modinfo = null;
+ $oldcourse->cacherev = 0;
$oldcourse->legacyfiles = 0;
$oldcourse->enablecompletion = 0;
if (!empty($options['keep_groups_and_groupings'])) {