From 9df4ae4189398b5d7b46b72b9cbbe942f2cef255 Mon Sep 17 00:00:00 2001 From: David Monllao Date: Thu, 21 Apr 2016 14:47:09 +0800 Subject: [PATCH] MDL-51603 dataformats: coding_exception if output buffering --- lib/dataformatlib.php | 4 ++-- lib/tablelib.php | 6 ++---- lib/upgrade.txt | 1 + report/log/index.php | 4 ---- 4 files changed, 5 insertions(+), 10 deletions(-) diff --git a/lib/dataformatlib.php b/lib/dataformatlib.php index f192ef82d44..36b51731002 100644 --- a/lib/dataformatlib.php +++ b/lib/dataformatlib.php @@ -38,8 +38,8 @@ */ function download_as_dataformat($filename, $dataformat, $columns, $iterator, $callback = null) { - if (!NO_OUTPUT_BUFFERING) { - throw new coding_exception("NO_OUTPUT_BUFFERING must be set to true before calling download_as_dataformat"); + if (ob_get_length()) { + throw new coding_exception("Output can not be buffered before calling download_as_dataformat"); } $classname = 'dataformat_' . $dataformat . '\writer'; diff --git a/lib/tablelib.php b/lib/tablelib.php index d33942c3ce1..ce3ff202fe5 100644 --- a/lib/tablelib.php +++ b/lib/tablelib.php @@ -1704,10 +1704,8 @@ class table_dataformat_export_format extends table_default_export_format_parent public function __construct(&$table, $dataformat) { parent::__construct($table); - if (!NO_OUTPUT_BUFFERING) { - // Ideally this would throw a coding exception but we are more forgiving here due - // to the large amount of code already using table_sql. - debugging("NO_OUTPUT_BUFFERING should be set to true before downloading", DEBUG_DEVELOPER); + if (ob_get_length()) { + throw new coding_exception("Output can not be buffered before instantiating table_dataformat_export_format"); } $classname = 'dataformat_' . $dataformat . '\writer'; diff --git a/lib/upgrade.txt b/lib/upgrade.txt index 172d9c2eab7..c9129594734 100644 --- a/lib/upgrade.txt +++ b/lib/upgrade.txt @@ -116,6 +116,7 @@ information provided here is intended especially for developers. * behat_util::is_server_running() is removed, please use behat_util::check_server_status() instead. * Behat\Mink\Selector\SelectorsHandler::xpathLiteral() method is deprecated use behat_context_helper::escape instead when building Xpath, or pass the unescaped value when using the named selector.', +* table_sql download process is using the new data formats plugin which you can't use if you are buffering any output === 3.0 === diff --git a/report/log/index.php b/report/log/index.php index 79bcff15520..d5e00ee29df 100644 --- a/report/log/index.php +++ b/report/log/index.php @@ -22,10 +22,6 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -if (!empty($_GET['download'])) { - define('NO_OUTPUT_BUFFERING', true); -} - require('../../config.php'); require_once($CFG->dirroot.'/course/lib.php'); require_once($CFG->dirroot.'/report/log/locallib.php');