From cedeaa5cda7f29930417bdddaf2a5dd17ad73793 Mon Sep 17 00:00:00 2001 From: eileen Date: Fri, 26 Oct 2018 00:34:43 +1300 Subject: [PATCH] Fix double handling of fields with unique names. The relationship array is being built with 'names' & the main array with 'unique names' which later need to be wrangled back into sync. Do relationships the same as main array --- CRM/Export/BAO/Export.php | 7 +------ tests/phpunit/CRM/Export/BAO/ExportTest.php | 11 +++++++++-- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/CRM/Export/BAO/Export.php b/CRM/Export/BAO/Export.php index 3f7f906aa0..00214262af 100644 --- a/CRM/Export/BAO/Export.php +++ b/CRM/Export/BAO/Export.php @@ -1123,16 +1123,11 @@ WHERE id IN ( $deleteIDString ) */ public static function mergeSameHousehold($exportTempTable, &$sqlColumns, $prefix) { $prefixColumn = $prefix . '_'; - $allKeys = array_keys($sqlColumns); $replaced = array(); // name map of the non standard fields in header rows & sql columns $mappingFields = array( 'civicrm_primary_id' => 'id', - 'contact_source' => 'source', - 'current_employer_id' => 'employer_id', - 'contact_is_deleted' => 'is_deleted', - 'name' => 'address_name', 'provider_id' => 'im_service_provider', 'phone_type_id' => 'phone_type', ); @@ -1413,7 +1408,7 @@ WHERE {$whereClause}"; $headerName = $field . '-' . 'current_employer'; } else { - $headerName = $field . '-' . $queryFields[$relationField]['name']; + $headerName = $field . '-' . $relationField; } } diff --git a/tests/phpunit/CRM/Export/BAO/ExportTest.php b/tests/phpunit/CRM/Export/BAO/ExportTest.php index 985c434d3c..ff368a31d7 100644 --- a/tests/phpunit/CRM/Export/BAO/ExportTest.php +++ b/tests/phpunit/CRM/Export/BAO/ExportTest.php @@ -423,7 +423,7 @@ class CRM_Export_BAO_ExportTest extends CiviUnitTestCase { * Test exporting relationships. */ public function testExportRelationships() { - $organization1 = $this->organizationCreate(['organization_name' => 'Org 1', 'legal_name' => 'pretty legal']); + $organization1 = $this->organizationCreate(['organization_name' => 'Org 1', 'legal_name' => 'pretty legal', 'contact_source' => 'friend who took a law paper once']); $organization2 = $this->organizationCreate(['organization_name' => 'Org 2', 'legal_name' => 'well dodgey']); $contact1 = $this->individualCreate(['employer_id' => $organization1, 'first_name' => 'one']); $contact2 = $this->individualCreate(['employer_id' => $organization2, 'first_name' => 'one']); @@ -432,6 +432,7 @@ class CRM_Export_BAO_ExportTest extends CiviUnitTestCase { ['Individual', 'first_name', ''], ['Individual', $employerRelationshipTypeID . '_a_b', 'organization_name', ''], ['Individual', $employerRelationshipTypeID . '_a_b', 'legal_name', ''], + ['Individual', $employerRelationshipTypeID . '_a_b', 'contact_source', ''], ]; list($tableName, $sqlColumns, $headerRows) = CRM_Export_BAO_Export::exportComponents( FALSE, @@ -456,6 +457,7 @@ class CRM_Export_BAO_ExportTest extends CiviUnitTestCase { $this->assertEquals('one', $dao->first_name); $this->assertEquals('Org 1', $dao->{$employerRelationshipTypeID . '_a_b_organization_name'}); $this->assertEquals('pretty legal', $dao->{$employerRelationshipTypeID . '_a_b_legal_name'}); + $this->assertEquals('friend who took a law paper once', $dao->{$employerRelationshipTypeID . '_a_b_contact_source'}); $dao->fetch(); $this->assertEquals('Org 2', $dao->{$employerRelationshipTypeID . '_a_b_organization_name'}); @@ -475,6 +477,7 @@ class CRM_Export_BAO_ExportTest extends CiviUnitTestCase { ['Individual', $houseHoldTypeID . '_a_b', 'city', ''], ['Individual', 'city', ''], ['Individual', 'state_province', ''], + ['Individual', 'contact_source', ''], ]; list($tableName, $sqlColumns, $headerRows) = CRM_Export_BAO_Export::exportComponents( FALSE, @@ -499,18 +502,21 @@ class CRM_Export_BAO_ExportTest extends CiviUnitTestCase { $this->assertEquals('ME', $dao->state_province); $this->assertEquals($householdID, $dao->civicrm_primary_id); $this->assertEquals($householdID, $dao->civicrm_primary_id); + $this->assertEquals('household sauce', $dao->contact_source); } $this->assertEquals([ 0 => 'City', 1 => 'State', - 2 => 'Household ID', + 2 => 'Contact Source', + 3 => 'Household ID', ], $headerRows); $this->assertEquals( [ 'city' => 'city varchar(64)', 'state_province' => 'state_province varchar(64)', 'civicrm_primary_id' => 'civicrm_primary_id varchar(16)', + 'contact_source' => 'contact_source varchar(255)', ], $sqlColumns); } @@ -999,6 +1005,7 @@ class CRM_Export_BAO_ExportTest extends CiviUnitTestCase { protected function setUpHousehold() { $this->setUpContactExportData(); $householdID = $this->householdCreate([ + 'source' => 'household sauce', 'api.Address.create' => [ 'city' => 'Portland', 'state_province_id' => 'Maine', -- 2.25.1