Fix export extra column on merge-same-address
authoreileen <emcnaughton@wikimedia.org>
Thu, 13 Dec 2018 06:14:16 +0000 (19:14 +1300)
committereileen <emcnaughton@wikimedia.org>
Thu, 13 Dec 2018 06:14:16 +0000 (19:14 +1300)
CRM/Export/BAO/Export.php
tests/phpunit/CRM/Export/BAO/ExportTest.php

index ec79ac0266bf6990d924df3f5aa7c805f6ff2dbe..b10d81c33e440061c65f4d1cf141043ba7ebe5ba 100644 (file)
@@ -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) {
index bc3dd2743ab474d143f72602ca9c802b7cdf6e3e..f93a6e0a4b601e0b10478d87cae10fc86f52fb74 100644 (file)
@@ -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