Skip to content

Commit

Permalink
Merge pull request #14800 from colemanw/mapperKeys
Browse files Browse the repository at this point in the history
[REF] [EXPORT] Alter CRM_Export_BAO_Export::exportComponents
  • Loading branch information
eileenmcnaughton authored Jul 12, 2019
2 parents 110cb51 + 7d0e773 commit b4a39e3
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 23 deletions.
6 changes: 1 addition & 5 deletions CRM/Export/BAO/Export.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion CRM/Export/BAO/ExportProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
12 changes: 6 additions & 6 deletions CRM/Export/Form/Map.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
Expand Down Expand Up @@ -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'),
Expand Down
33 changes: 22 additions & 11 deletions tests/phpunit/CRM/Export/BAO/ExportTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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],
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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) . ")",
Expand Down Expand Up @@ -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),
Expand Down

0 comments on commit b4a39e3

Please sign in to comment.