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

This commit is contained in:
Eloy Lafuente (stronk7)
2011-05-12 02:04:13 +02:00
parent de584990c6
commit 68fabb5c7e
+9 -1
View File
@@ -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);