How to rebuild context paths
Note: You are currently viewing documentation for Moodle 2.4. Up-to-date documentation for the latest stable version of Moodle may be available here: How to rebuild context paths.
This page requires updating. Please do so and remove this template when finished.
Sometimes, if something has gone wrong in your database, you will get an error like:
[Thu Jan 15 16:20:59 2009] [error] [client 188.8.131.52] PHP Notice: Context id 113 does not have valid path, please use build_context_path() line 375 of lib/accesslib.php: call to debugging() line 125 of mod/forum/index.php: call to has_capability() in /lib/weblib.php on line 6923, referer: mod/forum/index.php?id=2
This page explains how to follow the instruction to "please use build_context_path". You will need to create a simple PHP script to do this, then run it.
Before you start
This error should never happen, so the fact that it has may be a symptom of something more serious being wrong. If you are paranoid, you may wish to check your database for corruption before running the repair script below.
On the other hand, sometimes these things happens, so you could just run the script below then forget about it.
Step A: Create the script
On your server, create a file in the /admin folder called rebuildcontextpaths.php with the following content:
<?php require_once(dirname(__FILE__) . '/../config.php'); require_login(); require_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM)); $strRebuildContextPath = "Rebuild Context Path"; $PAGE->set_url('/admin/rebuildcontexpath.php'); $PAGE->set_title($strRebuildContextPath); $PAGE->set_heading($strRebuildContextPath); $PAGE->navbar->add($strRebuildContextPath); echo $OUTPUT->header(); echo '<p>Rebuilding context paths ...</p>'; build_context_path(true); echo '<p>Done</p>'; echo $OUTPUT->footer(); ?>
(You can either create this file on your own computer using a text editor like Notepad, then upload it to Moodle's /admin folder. Or you can edit the file directly on the server. It does not matter how you do it, just that you end up with the file there, with those contents.)
Step B: Run the script
Go to the URL .../admin/rebuildcontextpaths.php in your web browser (for example, if your Moodle site is at http://example.com/moodle/, then go to the URL http://example.com/moodle/admin/rebuildcontextpaths.php). You need to log in as an administrator. The script will run, and immediately print 'Rebuilding context paths ...'. Some time later (depending on how big your Moodle site is) it will print 'Done'.