Note: You are currently viewing documentation for Moodle 1.9. Up-to-date documentation for the latest stable version is available here: How to rebuild context paths.

How to rebuild context paths: Difference between revisions

From MoodleDocs
(→‎Step 1: create the script: coloring the code)
No edit summary
 
(9 intermediate revisions by one other user not shown)
Line 1: Line 1:
Sometimes, if something has gone wrong in your database, you will get an error like:
Sometimes, if something has gone wrong in your database, you will get an error like:


:[Thu Jan 15 16:20:59 2009] [error] [client 144.32.148.21] PHP Notice:  Context id 113 does not have valid path, please use build_context_path()
[Thu Jan 15 16:20:59 2009] [error] [client 144.32.148.21]  
:* line 375 of lib/accesslib.php: call to debugging()
PHP Notice:  Context id 113 does not have valid path, please use build_context_path()
:* line 125 of mod/forum/index.php: call to has_capability()
  line 375 of lib/accesslib.php: call to debugging()
:* in /lib/weblib.php on line 6923, referer: mod/forum/index.php?id=2
  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.
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==
== 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 [[How to check your database for corruption|check your database for corruption]] before running the repair script below.
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 [[How to check your database for corruption|check your database for corruption]] before running the repair script below.
Line 14: Line 15:
On the other hand, sometimes these things happens, so you could just run the script below then forget about it.
On the other hand, sometimes these things happens, so you could just run the script below then forget about it.


==Step 1: create the script==
== Step A: Create the script ==


On your server, create a file in the '''admin''' folder called '''rebuildcontextpaths.php''' with contents:
On your server, create a file in the '''/admin''' folder called '''rebuildcontextpaths.php''' with the following content:


<code php>
<code php>
<?php
<?php
require_once(dirname(__FILE__) . '/../config.php');
  require_once(dirname(__FILE__) . '/../config.php');
require_login();
  require_login();
require_capability('moodle/site:doanything', get_context_instance(CONTEXT_SYSTEM));
  require_capability('moodle/site:doanything', get_context_instance(CONTEXT_SYSTEM));
print_header();
  print_header();
echo '&lt;p>Rebuilding context paths ...&lt;/p>';
  echo '&lt;p>Rebuilding context paths ...&lt;/p>';
build_context_path(true);
  build_context_path(true);
echo '&lt;p>Done&lt;/p>';
  echo '&lt;p>Done&lt;/p>';
print_footer('empty');
  print_footer('empty');
?>
?>
</code>
</code>


(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.)
(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 2: run the script==
Code for Moodle 2.0.*
<code php>
 
<?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();
?>
</code>
 
== Step B: Run the script ==


Go to the URL .../admin/rebuildcontextpaths.php in your web browser (for example, if your Moodle site is at <nowiki>http://example.com/moodle/, then go to the URL http://example.com/moodle/admin/rebuildcontextpaths.php</nowiki>). 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'.
Go to the URL .../admin/rebuildcontextpaths.php in your web browser (for example, if your Moodle site is at <nowiki>http://example.com/moodle/, then go to the URL http://example.com/moodle/admin/rebuildcontextpaths.php</nowiki>). 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'.


==See also==
== See also ==
 
* [[Development:Roles#Context]]
* [[Development:Roles and modules#Context]]
* [[Administrator documentation]]
* [[Administrator documentation]]


[[Category: Administrator]]
[[Category: Administrator|Context path]]

Latest revision as of 18:32, 18 March 2011

Sometimes, if something has gone wrong in your database, you will get an error like:

[Thu Jan 15 16:20:59 2009] [error] [client 144.32.148.21] 
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:doanything', get_context_instance(CONTEXT_SYSTEM));
 print_header();
 echo '<p>Rebuilding context paths ...</p>';
 build_context_path(true);
 echo '<p>Done</p>';
 print_footer('empty');

?>

(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.)

Code for Moodle 2.0.*

<?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 '

Rebuilding context paths ...

';

build_context_path(true);

echo '

Done

';

echo $OUTPUT->footer(); ?>

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'.

See also