diff --git a/CRM/Export/BAO/Export.php b/CRM/Export/BAO/Export.php index 198c0a8342cd..b192d59efbb5 100644 --- a/CRM/Export/BAO/Export.php +++ b/CRM/Export/BAO/Export.php @@ -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. @@ -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}"; @@ -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); } @@ -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)) {