Skip to content

Commit

Permalink
Merge pull request #10393 from JMAConsulting/exportBatch
Browse files Browse the repository at this point in the history
[ready for core team to review] CRM-20614 Don't download export file until asked
  • Loading branch information
colemanw authored Dec 21, 2017
2 parents 61618e0 + 555f69c commit 3d023ea
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
5 changes: 4 additions & 1 deletion CRM/Batch/BAO/Batch.php
Original file line number Diff line number Diff line change
Expand Up @@ -594,8 +594,10 @@ public static function displayTotals($actual, $expected) {
* Associated array of batch ids.
* @param string $exportFormat
* Export format.
* @param bool $downloadFile
* Download export file?.
*/
public static function exportFinancialBatch($batchIds, $exportFormat) {
public static function exportFinancialBatch($batchIds, $exportFormat, $downloadFile) {
if (empty($batchIds)) {
CRM_Core_Error::fatal(ts('No batches were selected.'));
return;
Expand All @@ -615,6 +617,7 @@ public static function exportFinancialBatch($batchIds, $exportFormat) {
CRM_Core_Error::fatal("Could not locate exporter: $exporterClass");
}
$export = array();
$exporter->_isDownloadFile = $downloadFile;
foreach ($batchIds as $batchId) {
// export only batches whose status is set to Exported.
$result = civicrm_api3('Batch', 'getcount', array(
Expand Down
9 changes: 9 additions & 0 deletions CRM/Financial/BAO/ExportFormat.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@ abstract class CRM_Financial_BAO_ExportFormat {
*/
static protected $_template;

/**
* Download Exported file.
* @var boolean
*/
public $_isDownloadFile;

/**
* Class constructor.
*/
Expand Down Expand Up @@ -141,6 +147,9 @@ public static function format($s, $type = 'string') {
}

public function initiateDownload() {
if (!$this->_isDownloadFile) {
return NULL;
}
$config = CRM_Core_Config::singleton();
// zip files if more than one.
if (count($this->_downloadFile) > 1) {
Expand Down
7 changes: 6 additions & 1 deletion CRM/Financial/Form/Export.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@ class CRM_Financial_Form_Export extends CRM_Core_Form {
*/
protected $_exportFormat;

/**
* Download export File.
*/
protected $_downloadFile = TRUE;

/**
* Build all the data structures needed to build the form.
*/
Expand Down Expand Up @@ -175,7 +180,7 @@ public function postProcess() {
CRM_Batch_BAO_Batch::create($batchParams);
}

CRM_Batch_BAO_Batch::exportFinancialBatch($batchIds, $this->_exportFormat);
CRM_Batch_BAO_Batch::exportFinancialBatch($batchIds, $this->_exportFormat, $this->_downloadFile);
}

}

0 comments on commit 3d023ea

Please sign in to comment.