From 08b000992b37d28ec5bda903080a8991ae09dc46 Mon Sep 17 00:00:00 2001 From: Camilo Rodriguez Date: Mon, 21 Aug 2017 18:10:44 +0000 Subject: [PATCH] CRM-20858: Remove Try/Catch Blocks that Ignored Caught Exceptions The try catch blocks were apparently added because not all fields passed were custom fields, generating exceptions when the API call was made to obtain its option group. This happened because actually all fields selected for merge were being inserted into the $submittedCustomFields array, instead of just custom fields. Plus, obtaining the field's ID on a field that was not custom rendered strange strings to be used on search of the field, as this ID is obtained by getting a substring from the field's key, that should have the format 'move_custom_' (fields that are not custom don't have that format). --- CRM/Dedupe/Merger.php | 38 ++++++++++++-------------------------- 1 file changed, 12 insertions(+), 26 deletions(-) diff --git a/CRM/Dedupe/Merger.php b/CRM/Dedupe/Merger.php index e09ef11d04..3a3204c379 100755 --- a/CRM/Dedupe/Merger.php +++ b/CRM/Dedupe/Merger.php @@ -1489,19 +1489,18 @@ INNER JOIN civicrm_membership membership2 ON membership1.membership_type_id = m if ($value == $qfZeroBug) { $value = '0'; } - if ((in_array(substr($key, 5), CRM_Dedupe_Merger::getContactFields()) || - substr($key, 0, 12) == 'move_custom_') && - $value != NULL - ) { + + if (substr($key, 0, 12) == 'move_custom_' && $value != NULL) { $submitted[substr($key, 5)] = $value; $submittedCustomFields[] = substr($key, 12); } - + elseif (in_array(substr($key, 5), CRM_Dedupe_Merger::getContactFields()) && $value != NULL) { + $submitted[substr($key, 5)] = $value; + } // Set up initial information for handling migration of location blocks elseif (substr($key, 0, 14) == 'move_location_' and $value != NULL) { $locationMigrationInfo[$key] = $value; } - elseif (substr($key, 0, 15) == 'move_rel_table_' and $value == '1') { $moveTables = array_merge($moveTables, $relTables[substr($key, 5)]['tables']); if (array_key_exists('operation', $migrationInfo)) { @@ -1777,28 +1776,15 @@ INNER JOIN civicrm_membership membership2 ON membership1.membership_type_id = m foreach ($customFieldIDs as $fieldID) { if (!empty($fieldID)) { - $customField = NULL; - try { - $customField = civicrm_api3('custom_field', 'getsingle', array( - 'id' => $fieldID, + $customField = civicrm_api3('custom_field', 'getsingle', array( + 'id' => $fieldID, + 'is_active' => TRUE, + )); + if (!civicrm_error($customField) && !empty($customField['custom_group_id'])) { + $customGroup = civicrm_api3('custom_group', 'getsingle', array( + 'id' => $customField['custom_group_id'], 'is_active' => TRUE, )); - } - catch (CiviCRM_API3_Exception $e) { - continue; - } - if (!civicrm_error($customField) && !empty($customField['custom_group_id'])) { - $customGroup = NULL; - try { - $customGroup = civicrm_api3('custom_group', 'getsingle', array( - 'id' => $customField['custom_group_id'], - 'is_active' => TRUE, - )); - } - catch (CiviCRM_API3_Exception $e) { - // just ignore and continue - continue; - } if (!civicrm_error($customGroup) && !empty($customGroup['table_name'])) { $customTableToCopyValues[] = $customGroup['table_name']; -- 2.25.1