From c89254818b501493be2d0b93f94f2af14fe9bed8 Mon Sep 17 00:00:00 2001 From: eileen Date: Thu, 13 Dec 2018 19:14:16 +1300 Subject: [PATCH] Fix export extra column on merge-same-address --- CRM/Export/BAO/Export.php | 11 ++++++++++- tests/phpunit/CRM/Export/BAO/ExportTest.php | 3 ++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/CRM/Export/BAO/Export.php b/CRM/Export/BAO/Export.php index ec79ac0266..b10d81c33e 100644 --- a/CRM/Export/BAO/Export.php +++ b/CRM/Export/BAO/Export.php @@ -418,6 +418,14 @@ INSERT INTO {$componentTable} SELECT distinct gc.contact_id FROM civicrm_group_c list($outputColumns, $metadata) = self::getExportStructureArrays($returnProperties, $processor); + if (!empty($exportParams['merge_same_address']['temp_columns'])) { + // @todo - this is a temp fix - ideally later we don't set stuff only to unset it. + // test exists covering this... + foreach (array_keys($exportParams['merge_same_address']['temp_columns']) as $field) { + $processor->setColumnAsCalculationOnly($field); + } + } + $paymentDetails = []; if ($processor->isExportPaymentFields()) { // get payment related in for event and members @@ -512,7 +520,7 @@ INSERT INTO {$componentTable} SELECT distinct gc.contact_id FROM civicrm_group_c } else { // return tableName sqlColumns headerRows in test context - return array($exportTempTable, $sqlColumns, $headerRows); + return array($exportTempTable, $sqlColumns, $headerRows, $processor); } // delete the export temp table and component table @@ -807,6 +815,7 @@ WHERE id IN ( $deleteIDString ) } // unset temporary columns that were added for postal mailing format + // @todo - this part is pretty close to ready to be removed.... if (!empty($exportParams['merge_same_address']['temp_columns'])) { $unsetKeys = array_keys($sqlColumns); foreach ($unsetKeys as $headerKey => $sqlColKey) { diff --git a/tests/phpunit/CRM/Export/BAO/ExportTest.php b/tests/phpunit/CRM/Export/BAO/ExportTest.php index bc3dd2743a..f93a6e0a4b 100644 --- a/tests/phpunit/CRM/Export/BAO/ExportTest.php +++ b/tests/phpunit/CRM/Export/BAO/ExportTest.php @@ -1021,7 +1021,7 @@ class CRM_Export_BAO_ExportTest extends CiviUnitTestCase { )); //export and merge contacts with same address - list($tableName) = CRM_Export_BAO_Export::exportComponents( + list($tableName, $sqlColumns, $headerRows, $processor) = CRM_Export_BAO_Export::exportComponents( TRUE, array($contactA['id'], $contactB['id']), array(), @@ -1043,6 +1043,7 @@ class CRM_Export_BAO_ExportTest extends CiviUnitTestCase { ) ); + $this->assertTrue(!in_array('state_province_id', $processor->getHeaderRows())); $greeting = CRM_Core_DAO::singleValueQuery("SELECT email_greeting FROM {$tableName}"); //Assert email_greeting is not merged -- 2.25.1