Skip to content

Commit

Permalink
Move payment header handling out of the per-row iteration
Browse files Browse the repository at this point in the history
  • Loading branch information
eileenmcnaughton committed Nov 12, 2018
1 parent 1933e1a commit d142831
Showing 1 changed file with 21 additions and 34 deletions.
55 changes: 21 additions & 34 deletions CRM/Export/BAO/Export.php
Original file line number Diff line number Diff line change
Expand Up @@ -428,11 +428,23 @@ public static function exportComponents(
}
}

$addPaymentHeader = FALSE;
$componentDetails = array();
$setHeader = TRUE;

$rowCount = self::EXPORT_ROW_COUNT;
$offset = 0;
// we write to temp table often to avoid using too much memory
$tempRowCount = 100;

$count = -1;

// for CRM-3157 purposes
$i18n = CRM_Core_I18n::singleton();

list($outputColumns, $headerRows, $sqlColumns, $metadata) = self::getExportStructureArrays($returnProperties, $processor);
$addPaymentHeader = FALSE;
$paymentDetails = array();
if ($processor->isExportPaymentFields()) {

// get payment related in for event and members
$paymentDetails = CRM_Contribute_BAO_Contribution::getContributionDetails($exportMode, $ids);
//get all payment headers.
Expand All @@ -442,32 +454,16 @@ public static function exportComponents(
$paymentHeaders = $processor->getcomponentPaymentFields();
if (!empty($paymentDetails)) {
$addPaymentHeader = TRUE;
// @todo rather than do this for every single row do it before the loop starts.
// where other header definitions take place.
$headerRows = array_merge($headerRows, $paymentHeaders);
foreach (array_keys($paymentHeaders) as $paymentHdr) {
self::sqlColumnDefn($processor, $sqlColumns, $paymentHdr);
}
}
}
// If we have selected specific payment fields, leave the payment headers
// as an empty array; the headers for each selected field will be added
// elsewhere.
else {
$paymentHeaders = array();
}
$nullContributionDetails = array_fill_keys(array_keys($paymentHeaders), NULL);
}

$componentDetails = array();
$setHeader = TRUE;

$rowCount = self::EXPORT_ROW_COUNT;
$offset = 0;
// we write to temp table often to avoid using too much memory
$tempRowCount = 100;

$count = -1;

// for CRM-3157 purposes
$i18n = CRM_Core_I18n::singleton();

list($outputColumns, $headerRows, $sqlColumns, $metadata) = self::getExportStructureArrays($returnProperties, $processor);

$limitReached = FALSE;
while (!$limitReached) {
$limitQuery = "{$queryString} LIMIT {$offset}, {$rowCount}";
Expand Down Expand Up @@ -532,16 +528,6 @@ public static function exportComponents(
}
}

// add payment headers if required
if ($addPaymentHeader && $processor->isExportPaymentFields()) {
// @todo rather than do this for every single row do it before the loop starts.
// where other header definitions take place.
$headerRows = array_merge($headerRows, $paymentHeaders);
foreach (array_keys($paymentHeaders) as $paymentHdr) {
self::sqlColumnDefn($processor, $sqlColumns, $paymentHdr);
}
}

if ($setHeader) {
$exportTempTable = self::createTempTable($sqlColumns);
}
Expand All @@ -554,6 +540,7 @@ public static function exportComponents(
// information, if appropriate.
if ($addPaymentHeader) {
if (!$processor->isExportSpecifiedPaymentFields()) {
$nullContributionDetails = array_fill_keys(array_keys($processor->getcomponentPaymentFields()), NULL);
if ($processor->isExportPaymentFields()) {
$paymentData = CRM_Utils_Array::value($row[$paymentTableId], $paymentDetails);
if (!is_array($paymentData) || empty($paymentData)) {
Expand Down

0 comments on commit d142831

Please sign in to comment.