Commit a0bc3d1a authored by David Metzler's avatar David Metzler
Browse files

Write xml file as you go.

parent 4487de1f
......@@ -9,6 +9,7 @@ class FrxDocument {
public $format;
public $content_type='';
public $charset = 'UTF-8';
public $allowDirectOutput = FALSE;
public function loadCSSFiles($format) {
......
......@@ -883,7 +883,7 @@ class FrxEditor {
*
* @return unknown
*/
function report($parms = array(), $print = FALSE, $no_cache=FALSE) {
function report($parms = array(), $print = FALSE, $no_cache=FALSE, $filename='') {
global $user;
global $language;
$this->field_ids = array();
......@@ -910,6 +910,12 @@ class FrxEditor {
$cached_data = FALSE;
$cache = array();
$o = Frx::Document($format);
$this->frxReport->allowDirectWrite = $o->allowDirectOutput;
if ($this->frxReport->allowDirectWrite && $filename) {
$this->frxReport->file = fopen($filename, 'w');
}
/**
* Allow modules to alter the parameters of a report.
* @param unknown_type $report_name
......@@ -967,9 +973,19 @@ class FrxEditor {
'links' => $this->documentLinks(),
'content' => array('#markup' => $r->html . $links),
);
$o = Frx::Document($format);
if ($this->frxReport->file) {
$this->frxReport->writeBuffer();
fclose($this->frxReport->file);
return '';
}
if ($o) {
$output = $o->render($r, $format, $content);
if ($filename) {
file_put_contents($filename, $output);
return '';
}
if ($print) {
$printed = $o->output($output);
}
......
......@@ -39,6 +39,8 @@ class FrxReport {
public $link_mode = '';
public $xpathQuery;
public $frx_attributes = array(); // Saved attributes from prior call.
public $file; // File handle for the forena code
public $allowDirectWrite = FALSE; //Determine whether we can output directly.
public $preview_mode = FALSE; // This will make the report renderer put in editing controls when TRUE
......@@ -706,6 +708,15 @@ class FrxReport {
return $rows;
}
public function writeBuffer() {
if ($this->allowDirectWrite) {
if ($this->file) {
fwrite($this->file, $this->html);
$this->html = '';
}
}
}
}
......@@ -10,6 +10,7 @@ class FrxXMLDoc extends FrxDocument {
public $root_attributes = array();
public function __construct() {
$this->allowDirectOutput = TRUE;
$this->content_type = 'application/xml';
$skin = Frx::Data()->getContext('skin');
if (isset($skin['FrxXMLDoc']['rootElementName'])) {
......
......@@ -53,7 +53,7 @@ function drush_forena_report($report_uri, $filename='') {
}
if ($filename) {
drupal_set_message(t('Writing report %s to %f.', array('%s' => $report_name, '%f' => $filename)));
file_put_contents($filename, forena_report($report_name, $parms, FALSE));
forena_report($report_name, $parms, FALSE, $filename);
}
else {
drupal_set_message(t('Generating report %s.', array('%s' => $report_name)));
......
......@@ -898,7 +898,7 @@ function forena_include_data_tables() {
*
* @return unknown
*/
function forena_report($name_in, $parms = NULL, $print = TRUE) {
function forena_report($name_in, $parms = NULL, $print = TRUE, $filename='') {
require_once('forena.common.inc');
$desc = Frx::Menu()->parseURL($name_in);
$time = @new DateTime($value);
......@@ -918,7 +918,7 @@ function forena_report($name_in, $parms = NULL, $print = TRUE) {
$report_name = $desc['name'];
// Load dataTable plugin if possible.
//forena_include_data_tables();
$content = Frx::Editor($name_in, FALSE)->report($parms, $print, FALSE);
$content = Frx::Editor($name_in, FALSE)->report($parms, $print, FALSE, $filename);
$m_path = drupal_get_path('module', 'forena');
if ($content) {
......
......@@ -68,6 +68,8 @@ class FrxRenderer {
* Walks the nodes rendering the report.
*/
public function renderDomNode(DOMNode $dom_node, &$o) {
// Write out buffer if we've gotten too big
if ( $this->frxReport->allowDirectWrite && strlen($this->frxReport->html) > 100000) $this->frxReport->writeBuffer();
$continue = TRUE;
$is_data_block = FALSE;
//$o = '';
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment