Merge branch 'w13_MDL-26990_21_missingrebuild' of git://github.com/skodak/moodle

This commit is contained in:
Eloy Lafuente (stronk7) 2011-03-28 16:07:20 +02:00
commit a226727238
2 changed files with 52 additions and 50 deletions

View File

@ -1880,56 +1880,6 @@ function get_category_or_system_context($categoryid) {
}
}
/**
* Rebuilds the cached list of course activities stored in the database
* @param int $courseid - id of course to rebuild, 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, $DB, $OUTPUT;
// Destroy navigation caches
navigation_cache::destroy_volatile_caches();
if ($clearonly) {
if (empty($courseid)) {
$courseselect = array();
} else {
$courseselect = array('id'=>$courseid);
}
$DB->set_field('course', 'modinfo', null, $courseselect);
// update cached global COURSE too ;-)
if ($courseid == $COURSE->id or empty($courseid)) {
$COURSE->modinfo = null;
}
// reset the fast modinfo cache
$reset = 'reset';
get_fast_modinfo($reset);
return;
}
if ($courseid) {
$select = array('id'=>$courseid);
} else {
$select = array();
@set_time_limit(0); // this could take a while! MDL-10954
}
$rs = $DB->get_recordset("course", $select,'','id,fullname');
foreach ($rs as $course) {
$modinfo = serialize(get_array_of_activities($course->id));
$DB->set_field("course", "modinfo", $modinfo, array("id"=>$course->id));
// update cached global COURSE too ;-)
if ($course->id == $COURSE->id) {
$COURSE->modinfo = $modinfo;
}
}
$rs->close();
// reset the fast modinfo cache
$reset = 'reset';
get_fast_modinfo($reset);
}
/**
* Gets the child categories of a given courses category. Uses a static cache
* to make repeat calls efficient.

View File

@ -1080,6 +1080,58 @@ function get_fast_modinfo(&$course, $userid=0) {
return $cache[$course->id];
}
/**
* Rebuilds the cached list of course activities stored in the database
* @param int $courseid - id of course to rebuild, 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, $DB, $CFG;
// Destroy navigation caches
navigation_cache::destroy_volatile_caches();
if ($clearonly) {
if (empty($courseid)) {
$courseselect = array();
} else {
$courseselect = array('id'=>$courseid);
}
$DB->set_field('course', 'modinfo', null, $courseselect);
// update cached global COURSE too ;-)
if ($courseid == $COURSE->id or empty($courseid)) {
$COURSE->modinfo = null;
}
// reset the fast modinfo cache
$reset = 'reset';
get_fast_modinfo($reset);
return;
}
require_once("$CFG->dirroot/course/lib.php");
if ($courseid) {
$select = array('id'=>$courseid);
} else {
$select = array();
@set_time_limit(0); // this could take a while! MDL-10954
}
$rs = $DB->get_recordset("course", $select,'','id,fullname');
foreach ($rs as $course) {
$modinfo = serialize(get_array_of_activities($course->id));
$DB->set_field("course", "modinfo", $modinfo, array("id"=>$course->id));
// update cached global COURSE too ;-)
if ($course->id == $COURSE->id) {
$COURSE->modinfo = $modinfo;
}
}
$rs->close();
// reset the fast modinfo cache
$reset = 'reset';
get_fast_modinfo($reset);
}
/**
* Class that is the return value for the _get_coursemodule_info module API function.