本文整理汇总了PHP中course_modinfo::build_course_cache方法的典型用法代码示例。如果您正苦于以下问题:PHP course_modinfo::build_course_cache方法的具体用法?PHP course_modinfo::build_course_cache怎么用?PHP course_modinfo::build_course_cache使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类course_modinfo
的用法示例。
在下文中一共展示了course_modinfo::build_course_cache方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: rebuild_course_cache
/**
* Rebuilds or resets the cached list of course activities stored in MUC.
*
* rebuild_course_cache() must NEVER be called from lib/db/upgrade.php.
* At the same time course cache may ONLY be cleared using this function in
* upgrade scripts of plugins.
*
* During the bulk operations if it is necessary to reset cache of multiple
* courses it is enough to call {@link increment_revision_number()} for the
* table 'course' and field 'cacherev' specifying affected courses in select.
*
* Cached course information is stored in MUC core/coursemodinfo and is
* validated with the DB field {course}.cacherev
*
* @global moodle_database $DB
* @param int $courseid id of course to rebuild, empty means all
* @param boolean $clearonly only clear the cache, gets rebuild automatically on the fly.
* Recommended to set to true to avoid unnecessary multiple rebuilding.
*/
function rebuild_course_cache($courseid=0, $clearonly=false) {
global $COURSE, $SITE, $DB, $CFG;
// Function rebuild_course_cache() can not be called during upgrade unless it's clear only.
if (!$clearonly && !upgrade_ensure_not_running(true)) {
$clearonly = true;
}
// Destroy navigation caches
navigation_cache::destroy_volatile_caches();
if (class_exists('format_base')) {
// if file containing class is not loaded, there is no cache there anyway
format_base::reset_course_cache($courseid);
}
$cachecoursemodinfo = cache::make('core', 'coursemodinfo');
if (empty($courseid)) {
// Clearing caches for all courses.
increment_revision_number('course', 'cacherev', '');
$cachecoursemodinfo->purge();
course_modinfo::clear_instance_cache();
// Update global values too.
$sitecacherev = $DB->get_field('course', 'cacherev', array('id' => SITEID));
$SITE->cachrev = $sitecacherev;
if ($COURSE->id == SITEID) {
$COURSE->cacherev = $sitecacherev;
} else {
$COURSE->cacherev = $DB->get_field('course', 'cacherev', array('id' => $COURSE->id));
}
} else {
// Clearing cache for one course, make sure it is deleted from user request cache as well.
increment_revision_number('course', 'cacherev', 'id = :id', array('id' => $courseid));
$cachecoursemodinfo->delete($courseid);
course_modinfo::clear_instance_cache($courseid);
// Update global values too.
if ($courseid == $COURSE->id || $courseid == $SITE->id) {
$cacherev = $DB->get_field('course', 'cacherev', array('id' => $courseid));
if ($courseid == $COURSE->id) {
$COURSE->cacherev = $cacherev;
}
if ($courseid == $SITE->id) {
$SITE->cachrev = $cacherev;
}
}
}
if ($clearonly) {
return;
}
if ($courseid) {
$select = array('id'=>$courseid);
} else {
$select = array();
core_php_time_limit::raise(); // this could take a while! MDL-10954
}
$rs = $DB->get_recordset("course", $select,'','id,'.join(',', course_modinfo::$cachedfields));
// Rebuild cache for each course.
foreach ($rs as $course) {
course_modinfo::build_course_cache($course);
}
$rs->close();
}