diff --git a/CRM/Export/BAO/Export.php b/CRM/Export/BAO/Export.php index 57f5ba5f0903..0dc52e75dcaf 100644 --- a/CRM/Export/BAO/Export.php +++ b/CRM/Export/BAO/Export.php @@ -178,12 +178,8 @@ 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); - } - $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 e8dce0468f25..a78482ed9249 100644 --- a/CRM/Export/BAO/ExportProcessor.php +++ b/CRM/Export/BAO/ExportProcessor.php @@ -1553,7 +1553,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..7eeb83220927 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)); } diff --git a/tests/phpunit/CRM/Export/BAO/ExportTest.php b/tests/phpunit/CRM/Export/BAO/ExportTest.php index 189712d920b3..8c077f9edc4a 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( @@ -474,7 +474,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], @@ -547,11 +550,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, @@ -966,7 +969,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, @@ -1137,12 +1140,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) . ")", @@ -2670,12 +2677,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),