本文整理汇总了PHP中rebuild_course_cache函数的典型用法代码示例。如果您正苦于以下问题:PHP rebuild_course_cache函数的具体用法?PHP rebuild_course_cache怎么用?PHP rebuild_course_cache使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了rebuild_course_cache函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: xmldb_label_upgrade
function xmldb_label_upgrade($oldversion)
{
global $CFG, $DB;
$dbman = $DB->get_manager();
// Moodle v2.2.0 release upgrade line
// Put any upgrade step following this
// Moodle v2.3.0 release upgrade line
// Put any upgrade step following this
// Moodle v2.4.0 release upgrade line
// Put any upgrade step following this
if ($oldversion < 2013021400) {
// find all courses that contain labels and reset their cache
$modid = $DB->get_field_sql("SELECT id FROM {modules} WHERE name=?", array('label'));
if ($modid) {
$courses = $DB->get_fieldset_sql('SELECT DISTINCT course ' . 'FROM {course_modules} WHERE module=?', array($modid));
foreach ($courses as $courseid) {
rebuild_course_cache($courseid, true);
}
}
// label savepoint reached
upgrade_mod_savepoint(true, 2013021400, 'label');
}
// Moodle v2.5.0 release upgrade line.
// Put any upgrade step following this.
// Moodle v2.6.0 release upgrade line.
// Put any upgrade step following this.
return true;
}
示例2: page_20_migrate
/**
* Migrate page module data from 1.9 resource_old table to new page table
* @return void
*/
function page_20_migrate()
{
global $CFG, $DB;
require_once "{$CFG->libdir}/filelib.php";
require_once "{$CFG->libdir}/resourcelib.php";
require_once "{$CFG->dirroot}/course/lib.php";
if (!file_exists("{$CFG->dirroot}/mod/resource/db/upgradelib.php")) {
// bad luck, somebody deleted resource module
return;
}
require_once "{$CFG->dirroot}/mod/resource/db/upgradelib.php";
// create resource_old table and copy resource table there if needed
if (!resource_20_prepare_migration()) {
// no modules or fresh install
return;
}
$fs = get_file_storage();
if ($candidates = $DB->get_recordset('resource_old', array('type' => 'html', 'migrated' => 0))) {
foreach ($candidates as $candidate) {
page_20_migrate_candidate($candidate, $fs, FORMAT_HTML);
}
$candidates->close();
}
if ($candidates = $DB->get_recordset('resource_old', array('type' => 'text', 'migrated' => 0))) {
foreach ($candidates as $candidate) {
page_20_migrate_candidate($candidate, $fs, $candidate->reference);
}
$candidates->close();
}
// clear all course modinfo caches
rebuild_course_cache(0, true);
}
示例3: xmldb_ezproxy_upgrade
function xmldb_ezproxy_upgrade($oldversion = 0)
{
global $CFG, $THEME, $db;
$result = true;
/// And upgrade begins here. For each one, you'll need one
/// block of code similar to the next one. Please, delete
/// this comment lines once this file start handling proper
/// upgrade code.
if ($result && $oldversion < 2009042403) {
/// Rebuild the course cache of every course which uses one of these modules in it to get
/// the new link.
if ($courseids = get_records_menu('ezproxy', '', '', 'course ASC', 'id, course')) {
/// Just get the unique course ID values.
$courseids = array_unique(array_values($courseids));
if (!empty($courseids)) {
require_once $CFG->dirroot . '/course/lib.php';
foreach ($courseids as $courseid) {
rebuild_course_cache($courseid);
// Does not return a bool
}
}
}
}
if ($result && $oldversion < 2009042404) {
$table = new XMLDBTable('ezproxy');
$field = new XMLDBField('serverurl');
$field->setAttributes(XMLDB_TYPE_TEXT, 'big', null, null, null, null, null, '', 'name');
$result = change_field_type($table, $field);
}
return $result;
}
示例4: widgetspace_20_migrate
/**
* Migrate widgetspace module data from 1.9 resource_old table to new widgetspace table
* @return void
*/
function widgetspace_20_migrate()
{
global $CFG, $DB;
require_once "{$CFG->libdir}/filelib.php";
require_once "{$CFG->libdir}/resourcelib.php";
require_once "{$CFG->dirroot}/course/lib.php";
if (!file_exists("{$CFG->dirroot}/mod/resource/db/upgradelib.php")) {
// bad luck, somebody deleted resource module
return;
}
require_once "{$CFG->dirroot}/mod/resource/db/upgradelib.php";
// create resource_old table and copy resource table there if needed
if (!resource_20_prepare_migration()) {
// no modules or fresh install
return;
}
$fs = get_file_storage();
$candidates = $DB->get_recordset('resource_old', array('type' => 'html', 'migrated' => 0));
foreach ($candidates as $candidate) {
widgetspace_20_migrate_candidate($candidate, $fs, FORMAT_HTML);
}
$candidates->close();
$candidates = $DB->get_recordset('resource_old', array('type' => 'text', 'migrated' => 0));
foreach ($candidates as $candidate) {
//there might be some rubbish instead of format int value
$format = (int) $candidate->reference;
if ($format < 0 or $format > 4) {
$format = FORMAT_MOODLE;
}
widgetspace_20_migrate_candidate($candidate, $fs, $format);
}
$candidates->close();
// clear all course modinfo caches
rebuild_course_cache(0, true);
}
示例5: test_renderarray
/**
* This function tests the render_menu() method's ability to display
* the menus properly and handle a number of special cases that should
* arise.
*
* Note: for some reason (I think the cache gets flushed), all of the
* section tests must go in here.
*
*/
public function test_renderarray()
{
global $DB;
$courseid = $this->testcourseid;
$course = $DB->get_record('course', array('id' => $courseid));
rebuild_course_cache($courseid);
$section = 1;
$thissection = $DB->get_record('course_sections', array('course' => $courseid, 'section' => $section));
$cm = new collapsed_menu($course, $section, false);
$cm->render_menu();
// Answers are below.
$labelids = array($this->section1labelids[1], $this->section1labelids[2], $this->section1labelids[3], $this->section1labelids[0], $this->section1labelids[4]);
$closeids = array("N" . $this->section1labelids[2], "N" . $this->section1labelids[3], "N" . $this->section1labelids[4], "N" . $this->section1labelids[4], "N" . $this->section1contentids[8]);
$depthindices = array(2, 2, 2, 1, 1);
$depthvalues = array(2, 2, 2, 0, 0);
$numlabels = 5;
// Test labelinfo values.
$labelinfo = $cm->get_label_info();
for ($i = 0; $i < $numlabels; $i++) {
$this->assertEquals($labelinfo->labelid[$i], $labelids[$i]);
$this->assertEquals($labelinfo->closeid[$i], $closeids[$i]);
$this->assertEquals($labelinfo->depthindex[$i], $depthindices[$i]);
$this->assertEquals($labelinfo->depthvalue[$i], $depthvalues[$i]);
}
// Now for mod depths: answers.
$modids = array($this->section1contentids[0], $this->section1contentids[1], $this->section1contentids[2], $this->section1contentids[3], $this->section1contentids[4], $this->section1contentids[5], $this->section1contentids[6], $this->section1contentids[7], $this->section1contentids[8]);
$depths = array(0, 0, 0, 1, 0, 0, 0, 0, 0);
$nummods = 9;
// Test the moddepth values.
$moddepths = $cm->get_mod_depths();
for ($i = 0; $i < $nummods; $i++) {
$this->assertEquals($moddepths->modid[$i], $modids[$i]);
$this->assertEquals($moddepths->moddepth[$i], $depths[$i]);
}
// Change section to 2, it tests the "inclusive" label end.
$section = 2;
$thissection = $DB->get_record('course_sections', array('course' => $courseid, 'section' => $section));
$cm = new collapsed_menu($course, $section, false);
$cm->render_menu();
$labelinfo = $cm->get_label_info();
$this->assertEquals($labelinfo->labelid[0], $this->section2labelids[0]);
$this->assertEquals($labelinfo->closeid[0], "I" . $this->section2contentids[0]);
// Go with section 3 next -> this section "reverses" the last entries.
$section = 3;
$thissection = $DB->get_record('course_sections', array('course' => $courseid, 'section' => $section));
$cm = new collapsed_menu($course, $section, false);
$cm->render_menu();
$labelids = array($this->section3labelids[0], $this->section3labelids[2], $this->section3labelids[3], $this->section3labelids[1], $this->section3labelids[4], $this->section3labelids[6], $this->section3labelids[5], $this->section3labelids[7], $this->section3labelids[8]);
$closeids = array("N" . $this->section3labelids[1], "N" . $this->section3labelids[3], "N" . $this->section3labelids[4], "N" . $this->section3labelids[4], "N" . $this->section3labelids[5], "N" . $this->section3labelids[7], "I" . $this->section3contentids[0], "I" . $this->section3contentids[0], "I" . $this->section3contentids[0]);
$depthindices = array(1, 2, 2, 1, 1, 2, 1, 2, 3);
$depthvalues = array(0, 1, 1, 0, 0, 1, 0, 1, 2);
$numlabels = 9;
$labelinfo = $cm->get_label_info();
for ($i = 0; $i < $numlabels; $i++) {
$this->assertEquals($labelinfo->labelid[$i], $labelids[$i]);
$this->assertEquals($labelinfo->closeid[$i], $closeids[$i]);
$this->assertEquals($labelinfo->depthindex[$i], $depthindices[$i]);
$this->assertEquals($labelinfo->depthvalue[$i], $depthvalues[$i]);
}
}
示例6: create_section
/**
* Create a section.
*/
public static function create_section($course, $section)
{
global $DB;
$section = (object) $section;
$section->course = $course->id;
$DB->insert_record('course_sections', $section);
rebuild_course_cache($course->id, true);
}
示例7: resource_upgrade
function resource_upgrade($oldversion)
{
// This function does anything necessary to upgrade
// older versions to match current functionality
global $CFG;
if ($oldversion < 2004013101) {
modify_database("", "INSERT INTO prefix_log_display (module, action, mtable, field) VALUES ('resource', 'update', 'resource', 'name');");
modify_database("", "INSERT INTO prefix_log_display (module, action, mtable, field) VALUES ('resource', 'add', 'resource', 'name');");
}
if ($oldversion < 2004071000) {
table_column("resource", "", "popup", "text", "", "", "", "", "alltext");
if ($resources = get_records_select("resource", "type='3' OR type='5'", "", "id, alltext")) {
foreach ($resources as $resource) {
$resource->popup = addslashes($resource->alltext);
$resource->alltext = "";
if (!update_record("resource", $resource)) {
notify("Error updating popup field for resource id = {$resource->id}");
}
}
}
require_once "{$CFG->dirroot}/course/lib.php";
rebuild_course_cache();
}
if ($oldversion < 2004071300) {
table_column("resource", "", "options", "varchar", "255", "", "", "", "popup");
}
if ($oldversion < 2004071303) {
table_column("resource", "type", "type", "varchar", "30", "", "", "", "");
modify_database("", "UPDATE prefix_resource SET type='reference' WHERE type='1';");
modify_database("", "UPDATE prefix_resource SET type='file', options='frame' WHERE type='2';");
modify_database("", "UPDATE prefix_resource SET type='file' WHERE type='3';");
modify_database("", "UPDATE prefix_resource SET type='text', options='0' WHERE type='4';");
modify_database("", "UPDATE prefix_resource SET type='file' WHERE type='5';");
modify_database("", "UPDATE prefix_resource SET type='html' WHERE type='6';");
modify_database("", "UPDATE prefix_resource SET type='file' WHERE type='7';");
modify_database("", "UPDATE prefix_resource SET type='text', options='3' WHERE type='8';");
modify_database("", "UPDATE prefix_resource SET type='directory' WHERE type='9';");
}
if ($oldversion < 2004080801) {
modify_database("", "UPDATE prefix_resource SET alltext=reference,type='html' WHERE type='reference';");
rebuild_course_cache();
}
if ($oldversion < 2004111200) {
//drop first to avoid conflicts when upgrading
execute_sql("DROP INDEX {$CFG->prefix}resource_course_idx;", false);
modify_database('', 'CREATE INDEX prefix_resource_course_idx ON prefix_resource (course);');
}
if ($oldversion < 2005041100) {
// replace wiki-like with markdown
include_once "{$CFG->dirroot}/lib/wiki_to_markdown.php";
$wtm = new WikiToMarkdown();
$wtm->update('resource', 'alltext', 'options');
}
////// DO NOT ADD NEW THINGS HERE!! USE upgrade.php and the lib/ddllib.php functions.
return true;
}
示例8: folder_20_migrate
/**
* Migrate folder module data from 1.9 resource_old table to new older table
* @return void
*/
function folder_20_migrate()
{
global $CFG, $DB;
require_once "{$CFG->libdir}/filelib.php";
require_once "{$CFG->dirroot}/course/lib.php";
if (!file_exists("{$CFG->dirroot}/mod/resource/db/upgradelib.php")) {
// bad luck, somebody deleted resource module
return;
}
require_once "{$CFG->dirroot}/mod/resource/db/upgradelib.php";
// create resource_old table and copy resource table there if needed
if (!resource_20_prepare_migration()) {
// no modules or fresh install
return;
}
if (!($candidates = $DB->get_recordset('resource_old', array('type' => 'directory', 'migrated' => 0)))) {
return;
}
$fs = get_file_storage();
foreach ($candidates as $candidate) {
upgrade_set_timeout();
$directory = '/' . trim($candidate->reference, '/') . '/';
$directory = str_replace('//', '/', $directory);
$folder = new object();
$folder->course = $candidate->course;
$folder->name = $candidate->name;
$folder->intro = $candidate->intro;
$folder->introformat = $candidate->introformat;
$folder->revision = 1;
$folder->timemodified = time();
if (!($folder = resource_migrate_to_module('folder', $candidate, $folder))) {
continue;
}
// copy files in given directory, skip moddata and backups!
$context = get_context_instance(CONTEXT_MODULE, $candidate->cmid);
$coursecontext = get_context_instance(CONTEXT_COURSE, $candidate->course);
$files = $fs->get_directory_files($coursecontext->id, 'course_content', 0, $directory, true, true);
$file_record = array('contextid' => $context->id, 'filearea' => 'folder_content', 'itemid' => 0);
foreach ($files as $file) {
$path = $file->get_filepath();
if (stripos($path, '/backupdata/') === 0 or stripos($path, '/moddata/') === 0) {
// do not publish protected data!
continue;
}
$relpath = substr($path, strlen($directory) - 1);
// keep only subfolder paths
$file_record['filepath'] = $relpath;
$fs->create_file_from_storedfile($file_record, $file);
}
}
$candidates->close();
// clear all course modinfo caches
rebuild_course_cache(0, true);
}
示例9: create_instance
/**
* Create new assign module instance
* @param array|stdClass $record
* @param array $options (mostly course_module properties)
* @return stdClass activity record with extra cmid field
*/
public function create_instance($record = null, array $options = null) {
global $CFG;
require_once("$CFG->dirroot/mod/assign/lib.php");
$this->instancecount++;
$i = $this->instancecount;
$record = (object)(array)$record;
$options = (array)$options;
if (empty($record->course)) {
throw new coding_exception('module generator requires $record->course');
}
$defaultsettings = array(
'name' => get_string('pluginname', 'assign').' '.$i,
'intro' => 'Test assign ' . $i,
'introformat' => FORMAT_MOODLE,
'alwaysshowdescription' => 1,
'submissiondrafts' => 1,
'requiresubmissionstatement' => 0,
'sendnotifications' => 0,
'sendlatenotifications' => 0,
'duedate' => 0,
'allowsubmissionsfromdate' => 0,
'grade' => 100,
'cutoffdate' => 0,
'teamsubmission' => 0,
'requireallteammemberssubmit' => 0,
'teamsubmissiongroupingid' => 0,
'blindmarking' => 0,
'cmidnumber' => '',
'attemptreopenmethod' => 'none',
'maxattempts' => -1
);
foreach ($defaultsettings as $name => $value) {
if (!isset($record->{$name})) {
$record->{$name} = $value;
}
}
$record->coursemodule = $this->precreate_course_module($record->course, $options);
$id = assign_add_instance($record, null);
rebuild_course_cache($record->course, true);
return $this->post_add_instance($id, $record->coursemodule);
}
示例10: FN_update_course
function FN_update_course($form, $oldformat = false)
{
global $CFG;
/// Updates course specific variables.
/// Variables are: 'showsection0', 'showannouncements'.
$config_vars = array('showsection0', 'showannouncements', 'sec0title', 'showhelpdoc', 'showclassforum', 'showclasschat', 'logo', 'mycourseblockdisplay', 'showgallery', 'gallerydefault', 'usesitegroups', 'mainheading', 'topicheading', 'activitytracking', 'ttmarking', 'ttgradebook', 'ttdocuments', 'ttstaff', 'defreadconfirmmess', 'usemandatory', 'expforumsec');
foreach ($config_vars as $config_var) {
if ($varrec = get_record('course_config_FN', 'courseid', $form->id, 'variable', $config_var)) {
$varrec->value = $form->{$config_var};
update_record('course_config_FN', $varrec);
} else {
$varrec->courseid = $form->id;
$varrec->variable = $config_var;
$varrec->value = $form->{$config_var};
insert_record('course_config_FN', $varrec);
}
}
/// We need to have the sections created ahead of time for the weekly nav to work,
/// so check and create here.
if (!($sections = get_all_sections($form->id))) {
$sections = array();
}
for ($i = 0; $i <= $form->numsections; $i++) {
if (empty($sections[$i])) {
$section = new Object();
$section->course = $form->id;
// Create a new section structure
$section->section = $i;
$section->summary = "";
$section->visible = 1;
if (!($section->id = insert_record("course_sections", $section))) {
notify("Error inserting new section!");
}
}
}
/// Check for a change to an FN format. If so, set some defaults as well...
if ($oldformat != 'FN') {
/// Set the news (announcements) forum to no force subscribe, and no posts or discussions.
require_once $CFG->dirroot . '/mod/forum/lib.php';
$news = forum_get_course_forum($form->id, 'news');
$news->open = 0;
$news->forcesubscribe = 0;
update_record('forum', $news);
}
rebuild_course_cache($form->id);
}
示例11: execute
public function execute()
{
global $CFG;
require_once $CFG->dirroot . '/lib/modinfolib.php';
$options = $this->expandedOptions;
if (!isset($this->arguments[0]) && !$options['all']) {
cli_error("Either run with -a for all courses or provide course id as an argument.");
}
if (isset($this->arguments[0])) {
rebuild_course_cache($this->arguments[0]);
echo "Succesfully rebuilt cache for course " . $this->arguments[0] . "\n";
}
if ($options['all']) {
rebuild_course_cache();
exit("Succesfully rebuilt all course caches\n");
}
}
示例12: FN_update_course
function FN_update_course($form, $oldformat = false, $resubmission = false)
{
global $CFG, $DB, $OUTPUT;
$config_vars = array('showsection0', 'sec0title', 'mainheading', 'topicheading', 'maxtabs');
foreach ($config_vars as $config_var) {
if ($varrec = $DB->get_record('course_config_fn', array('courseid' => $form->id, 'variable' => $config_var))) {
$varrec->value = $form->{$config_var};
$DB->update_record('course_config_fn', $varrec);
} else {
$varrec->courseid = $form->id;
$varrec->variable = $config_var;
$varrec->value = $form->{$config_var};
$DB->insert_record('course_config_fn', $varrec);
}
}
/// We need to have the sections created ahead of time for the weekly nav to work,
/// so check and create here.
if (!($sections = get_all_sections($form->id))) {
$sections = array();
}
for ($i = 0; $i <= $form->numsections; $i++) {
if (empty($sections[$i])) {
$section = new Object();
$section->course = $form->id;
// Create a new section structure
$section->section = $i;
$section->summary = "";
$section->visible = 1;
if (!($section->id = $DB->insert_record("course_sections", $section))) {
$OUTPUT->notification("Error inserting new section!");
}
}
}
/// Check for a change to an FN format. If so, set some defaults as well...
if ($oldformat != 'FN') {
/// Set the news (announcements) forum to no force subscribe, and no posts or discussions.
require_once $CFG->dirroot . '/mod/forum/lib.php';
$news = forum_get_course_forum($form->id, 'news');
$news->open = 0;
$news->forcesubscribe = 0;
$DB->update_record('forum', $news);
}
rebuild_course_cache($form->id);
}
示例13: addsection_action
/**
* Add a new section with the provided title and (optional) summary
*
* @return string
*/
public function addsection_action()
{
global $CFG, $PAGE, $DB;
require_once $CFG->dirroot . '/course/lib.php';
$sectioname = required_param('newsection', PARAM_TEXT);
$summary = optional_param('summary', '', PARAM_RAW);
require_sesskey();
$courseid = $PAGE->context->get_course_context()->instanceid;
$course = course_get_format($courseid)->get_course();
$course->numsections++;
course_get_format($course)->update_course_format_options(array('numsections' => $course->numsections));
course_create_sections_if_missing($course, range(0, $course->numsections));
$modinfo = get_fast_modinfo($course);
$section = $modinfo->get_section_info($course->numsections, MUST_EXIST);
$DB->set_field('course_sections', 'name', $sectioname, array('id' => $section->id));
$DB->set_field('course_sections', 'summary', $summary, array('id' => $section->id));
$DB->set_field('course_sections', 'summaryformat', FORMAT_HTML, array('id' => $section->id));
rebuild_course_cache($course->id);
redirect(course_get_url($course, $section->section));
}
示例14: customlabel_update_instance
/**
* Given an object containing all the necessary data,
* (defined by the form in mod.html) this function
* will update an existing instance with new data.
*/
function customlabel_update_instance($customlabel)
{
global $CFG;
$oldinstance = get_record('customlabel', 'id', $customlabel->instance);
if ($oldinstance->labelclass != $customlabel->labelclass) {
$customlabel->content = '';
$customlabel->name = '';
} else {
$customlabel->content = json_encode($customlabel);
$instance = customlabel_load_class($customlabel);
$instance->process_form_fields();
$instance->preprocess_data();
$customlabel->name = $instance->get_name();
}
$customlabel->timemodified = time();
$customlabel->id = $customlabel->instance;
$customlabel = customlabel_addslashes_fields($customlabel);
$result = update_record('customlabel', $customlabel);
// needed to update modinfo
rebuild_course_cache();
return $result;
}
示例15: xmldb_forumng_upgrade
/**
* Forum database upgrade script.
* @package mod
* @subpackage forumng
* @copyright 2011 The Open University
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
function xmldb_forumng_upgrade($oldversion = 0)
{
global $CFG, $THEME, $DB;
$dbman = $DB->get_manager();
if ($oldversion < 2012070900) {
// Changed format of modinfo cache, so need to rebuild all courses.
rebuild_course_cache(0, true);
upgrade_mod_savepoint(true, 2012070900, 'forumng');
}
if ($oldversion < 2012102601) {
// Define field gradingscale to be added to forumng.
$table = new xmldb_table('forumng');
$field = new xmldb_field('gradingscale', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0', 'grading');
// Launch add field gradingscale.
if (!$dbman->field_exists($table, $field)) {
$dbman->add_field($table, $field);
}
// Changed format of modinfo cache, so need to rebuild all courses.
rebuild_course_cache(0, true);
// ForumNG savepoint reached.
upgrade_mod_savepoint(true, 2012102601, 'forumng');
}
return true;
}