diff --git a/plugins/views_data_export_plugin_display_export.inc b/plugins/views_data_export_plugin_display_export.inc index b9077c0..860ddc6 100644 --- a/plugins/views_data_export_plugin_display_export.inc +++ b/plugins/views_data_export_plugin_display_export.inc @@ -41,6 +41,11 @@ class views_data_export_plugin_display_export extends views_plugin_display_feed var $errors = array(); /** + * A boolean to ensure that the query build process is not recursive. + */ + protected $building = FALSE; + + /** * Return the type of styles we require. */ function get_style_type() { return 'data_export'; } @@ -159,8 +164,36 @@ class views_data_export_plugin_display_export extends views_plugin_display_feed * Determine if this view should run as a batch or not. */ function is_batched() { - // The source of this option may change in the future. - return ($this->get_option('use_batch') == 'batch') && empty($this->view->live_preview); + if (($this->get_option('use_batch') == 'batch') && empty($this->view->live_preview) && !$this->building) { + // If the batched_execution_state is already set, batch is in progress. + if ($this->batched_execution_state) { + return TRUE; + } + + // Build the query here. + $this->building = TRUE; + $this->view->build(); + $this->building = FALSE; + + // Find the total exportable row count. + if (!isset($this->total_export_row_count)) { + $count_query = $this->view->query->query()->countQuery(); + $result = $count_query->execute()->fetchAssoc(); + $this->total_export_row_count = intval($result['expression']); + } + + // If there are more rows than the batch size, we use batch mode. + if ($this->total_export_row_count > intval($this->options['segment_size'])) { + return TRUE; + } + else { + $this->set_option('use_batch', 'no_batch'); + return FALSE; + } + } + else { + return FALSE; + } } /**