Browse files

MDL-27481 profiling - prevent data to be sent to DB before it is avai…

…lable
  • Loading branch information...
1 parent de58499 commit 68fabb5c7eae858ee1034be610f0403b736befcc @stronk7 stronk7 committed May 12, 2011
Showing with 9 additions and 1 deletion.
  1. +9 −1 lib/xhprof/xhprof_moodle.php
View
10 lib/xhprof/xhprof_moodle.php
@@ -152,7 +152,7 @@ function profiling_start() {
* Stop profiling, gathering results and storing them
*/
function profiling_stop() {
- global $CFG, $SCRIPT;
+ global $CFG, $DB, $SCRIPT;
// If profiling isn't available, nothing to stop
if (!extension_loaded('xhprof') || !function_exists('xhprof_enable')) {
@@ -176,6 +176,14 @@ function profiling_stop() {
profiling_is_running(false);
$data = xhprof_disable();
+ // We only save the run after ensuring the DB table exists
+ // (this prevents problems with profiling runs enabled in
+ // config.php before Moodle is installed. Rare but...
+ $tables = $DB->get_tables();
+ if (!in_array('profiling', $tables)) {
+ return false;
+ }
+
$run = new moodle_xhprofrun();
$run->prepare_run($script);
$runid = $run->save_run($data, null);

0 comments on commit 68fabb5

Please sign in to comment.