diff --git a/CRM/Export/BAO/Export.php b/CRM/Export/BAO/Export.php index e8ca6622618d..06ab07ed9902 100644 --- a/CRM/Export/BAO/Export.php +++ b/CRM/Export/BAO/Export.php @@ -177,10 +177,6 @@ public static function exportComponents( isset($exportParams['postal_mailing_export']['postal_mailing_export']) && $exportParams['postal_mailing_export']['postal_mailing_export'] == 1 ); - $mappedFields = []; - foreach ((array) $fields as $field) { - $mappedFields[] = CRM_Core_BAO_Mapping::getMappingParams([], $field); - } if (!$selectAll && $componentTable && !empty($exportParams['additional_group'])) { // If an Additional Group is selected, then all contacts in that group are @@ -192,7 +188,7 @@ public static function exportComponents( ); } - $processor = new CRM_Export_BAO_ExportProcessor($exportMode, $mappedFields, $queryOperator, $mergeSameHousehold, $isPostalOnly, $mergeSameAddress); + $processor = new CRM_Export_BAO_ExportProcessor($exportMode, $fields, $queryOperator, $mergeSameHousehold, $isPostalOnly, $mergeSameAddress); if ($moreReturnProperties) { $processor->setAdditionalRequestedReturnProperties($moreReturnProperties); } diff --git a/CRM/Export/BAO/ExportProcessor.php b/CRM/Export/BAO/ExportProcessor.php index 8e994ddc8459..b714d32e160b 100644 --- a/CRM/Export/BAO/ExportProcessor.php +++ b/CRM/Export/BAO/ExportProcessor.php @@ -1556,7 +1556,7 @@ public function determineReturnProperties() { $returnProperties = []; foreach ($this->getRequestedFields() as $key => $value) { $fieldName = $value['name']; - $locationName = CRM_Core_PseudoConstant::getName('CRM_Core_BAO_Address', 'location_type_id', $value['location_type_id']); + $locationName = !empty($value['location_type_id']) ? CRM_Core_PseudoConstant::getName('CRM_Core_BAO_Address', 'location_type_id', $value['location_type_id']) : NULL; $relationshipTypeKey = !empty($value['relationship_type_id']) ? $value['relationship_type_id'] . '_' . $value['relationship_direction'] : NULL; if (!$fieldName || $this->isHouseholdMergeRelationshipTypeKey($relationshipTypeKey)) { continue; diff --git a/CRM/Export/Form/Map.php b/CRM/Export/Form/Map.php index ea955205cb4a..38b961ae6b9d 100644 --- a/CRM/Export/Form/Map.php +++ b/CRM/Export/Form/Map.php @@ -183,14 +183,14 @@ public function postProcess() { $mapperKeys = $params['mapper'][1]; - $checkEmpty = 0; - foreach ($mapperKeys as $value) { - if ($value[0]) { - $checkEmpty++; + $mappedFields = []; + foreach ((array) $mapperKeys as $field) { + if (!empty($field[1])) { + $mappedFields[] = CRM_Core_BAO_Mapping::getMappingParams([], $field); } } - if (!$checkEmpty) { + if (!$mappedFields) { $this->set('mappingId', NULL); CRM_Utils_System::redirect(CRM_Utils_System::url($currentPath, '_qf_Map_display=true' . $urlParams)); } @@ -220,7 +220,7 @@ public function postProcess() { $this->get('componentIds'), (array) $this->get('queryParams'), $this->get(CRM_Utils_Sort::SORT_ORDER), - $mapperKeys, + $mappedFields, $this->get('returnProperties'), $this->get('exportMode'), $this->get('componentClause'), diff --git a/tests/phpunit/CRM/Export/BAO/ExportTest.php b/tests/phpunit/CRM/Export/BAO/ExportTest.php index f0c15879c28f..81cee323d40f 100644 --- a/tests/phpunit/CRM/Export/BAO/ExportTest.php +++ b/tests/phpunit/CRM/Export/BAO/ExportTest.php @@ -229,8 +229,8 @@ public function testExportComponentsMembership() { public function testExportComponentsActivity() { $this->setUpActivityExportData(); $selectedFields = [ - ['Individual', 'display_name'], - ['Individual', '5_a_b', 'display_name'], + ['contact_type' => 'Individual', 'name' => 'display_name'], + ['contact_type' => 'Individual', 'relationship_type_id' => '5', 'relationship_direction' => 'a_b', 'name' => 'display_name'], ]; list($tableName) = CRM_Export_BAO_Export::exportComponents( @@ -465,7 +465,10 @@ public function testExportPseudoFieldCampaign() { $this->setUpContributionExportData(); $campaign = $this->callAPISuccess('Campaign', 'create', ['title' => 'Big campaign']); $this->callAPISuccess('Contribution', 'create', ['campaign_id' => 'Big_campaign', 'id' => $this->contributionIDs[0]]); - $selectedFields = [['Individual', 'gender_id'], ['Contribution', 'contribution_campaign_title']]; + $selectedFields = [ + ['contact_type' => 'Individual', 'name' => 'gender_id'], + ['contact_type' => 'Contribution', 'name' => 'contribution_campaign_title'], + ]; list($tableName, $sqlColumns) = CRM_Export_BAO_Export::exportComponents( TRUE, $this->contactIDs[1], @@ -538,11 +541,11 @@ public function testExportRelationshipsMergeToHousehold($includeHouseHold) { $this->contactIDs[] = $householdID; } $selectedFields = [ - ['Individual', $houseHoldTypeID . '_a_b', 'state_province', ''], - ['Individual', $houseHoldTypeID . '_a_b', 'city', ''], - ['Individual', 'city', ''], - ['Individual', 'state_province', ''], - ['Individual', 'contact_source', ''], + ['contact_type' => 'Individual', 'relationship_type_id' => $houseHoldTypeID, 'relationship_direction' => 'a_b', 'name' => 'state_province', 'location_type_id' => ''], + ['contact_type' => 'Individual', 'relationship_type_id' => $houseHoldTypeID, 'relationship_direction' => 'a_b', 'name' => 'city', 'location_type_id' => ''], + ['contact_type' => 'Individual', 'name' => 'city', 'location_type_id' => ''], + ['contact_type' => 'Individual', 'name' => 'state_province', 'location_type_id' => ''], + ['contact_type' => 'Individual', 'name' => 'contact_source', 'location_type_id' => ''], ]; list($tableName, $sqlColumns, $headerRows) = CRM_Export_BAO_Export::exportComponents( FALSE, @@ -957,7 +960,7 @@ public function testExportMasterAddress() { //export the master address for contact B $selectedFields = [ - ['Individual', 'master_id', 1], + ['contact_type' => 'Individual', 'name' => 'master_id', 'location_type_id' => 1], ]; list($tableName, $sqlColumns) = CRM_Export_BAO_Export::exportComponents( TRUE, @@ -1128,12 +1131,16 @@ protected function setUpHousehold() { */ protected function doExport($selectedFields, $id, $exportMode = CRM_Export_Form_Select::CONTACT_EXPORT) { $ids = (array) $id; + $mappedFields = []; + foreach ((array) $selectedFields as $field) { + $mappedFields[] = CRM_Core_BAO_Mapping::getMappingParams([], $field); + } list($tableName, $sqlColumns) = CRM_Export_BAO_Export::exportComponents( TRUE, $ids, [], NULL, - $selectedFields, + $mappedFields, NULL, $exportMode, "contact_a.id IN (" . implode(',', $ids) . ")", @@ -2661,12 +2668,16 @@ protected function doExportTest($params) { $this->startCapturingOutput(); try { $defaultClause = (empty($params['ids']) ? NULL : "contact_a.id IN (" . implode(',', $params['ids']) . ")"); + $mappedFields = []; + foreach (CRM_Utils_Array::value('fields', $params, []) as $field) { + $mappedFields[] = CRM_Core_BAO_Mapping::getMappingParams([], $field); + } CRM_Export_BAO_Export::exportComponents( CRM_Utils_Array::value('selectAll', $params, (empty($params['fields']))), CRM_Utils_Array::value('ids', $params, []), CRM_Utils_Array::value('params', $params, []), CRM_Utils_Array::value('order', $params), - CRM_Utils_Array::value('fields', $params), + $mappedFields, CRM_Utils_Array::value('moreReturnProperties', $params), CRM_Utils_Array::value('exportMode', $params, CRM_Export_Form_Select::CONTACT_EXPORT), CRM_Utils_Array::value('componentClause', $params, $defaultClause),