From 68fabb5c7eae858ee1034be610f0403b736befcc Mon Sep 17 00:00:00 2001 From: "Eloy Lafuente (stronk7)" Date: Thu, 12 May 2011 02:04:13 +0200 Subject: [PATCH] MDL-27481 profiling - prevent data to be sent to DB before it is available --- lib/xhprof/xhprof_moodle.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/xhprof/xhprof_moodle.php b/lib/xhprof/xhprof_moodle.php index 853e5f50d3b..28c41f30065 100644 --- a/lib/xhprof/xhprof_moodle.php +++ b/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);