From 5b3a9e2a3746e4be7c2dcb8d75a2b6e3bc3f1146 Mon Sep 17 00:00:00 2001 From: Eileen McNaughton Date: Tue, 27 Dec 2022 11:15:29 +1300 Subject: [PATCH] Only call function when applicable Big whitespace change as IF is moved --- CRM/Dedupe/Merger.php | 126 +++++++++++++++++++++--------------------- 1 file changed, 63 insertions(+), 63 deletions(-) diff --git a/CRM/Dedupe/Merger.php b/CRM/Dedupe/Merger.php index 935ed72557..ca76a69c78 100644 --- a/CRM/Dedupe/Merger.php +++ b/CRM/Dedupe/Merger.php @@ -1783,7 +1783,9 @@ INNER JOIN civicrm_membership membership2 ON membership1.membership_type_id = m $submitted = []; } foreach ($submitted as $key => $value) { - $submitted = self::processCustomFields($mainId, $key, $cFields, $submitted, $value); + if (substr($key, 0, 7) === 'custom_') { + $submitted = self::processCustomFields($mainId, $key, $cFields, $submitted, $value); + } } // move view only custom fields CRM-5362 @@ -2203,77 +2205,75 @@ INNER JOIN civicrm_membership membership2 ON membership1.membership_type_id = m * @throws \CRM_Core_Exception */ protected static function processCustomFields($mainId, $key, $cFields, $submitted, $value) { - if (substr($key, 0, 7) === 'custom_') { - $fid = (int) substr($key, 7); - if (empty($cFields[$fid])) { - return $submitted; - } - $htmlType = $cFields[$fid]['attributes']['html_type']; - $isSerialized = CRM_Core_BAO_CustomField::isSerialized($cFields[$fid]['attributes']); - - if ($htmlType === 'File') { - // Handled in CustomField->move(). Tested in testMergeCustomFields. - unset($submitted["custom_$fid"]); - } - elseif (!$isSerialized && ($htmlType === 'Select Country' || $htmlType === 'Select State/Province')) { - // @todo Test in testMergeCustomFields disabled as this does not work, Handle in CustomField->move(). - $submitted[$key] = CRM_Core_BAO_CustomField::displayValue($value, $fid); - } - elseif ($htmlType === 'Select Date') { - if ($cFields[$fid]['attributes']['is_view']) { - $submitted[$key] = date('YmdHis', strtotime($submitted[$key])); - } - } - elseif ($isSerialized) { - // Merge values from both contacts for multivalue fields, CRM-4385 - // get the existing custom values from db. - $customParams = ['entityID' => $mainId, $key => TRUE]; - $customfieldValues = CRM_Core_BAO_CustomValueTable::getValues($customParams); - if (!empty($customfieldValues[$key])) { - $existingValue = explode(CRM_Core_DAO::VALUE_SEPARATOR, $customfieldValues[$key]); - if (is_array($existingValue) && !empty($existingValue)) { - $mergeValue = $submittedCustomFields = []; - if ($value === 'null') { - // CRM-19074 if someone has deliberately chosen to overwrite with 'null', respect it. - $submitted[$key] = $value; + $fid = (int) substr($key, 7); + if (empty($cFields[$fid])) { + return $submitted; + } + $htmlType = $cFields[$fid]['attributes']['html_type']; + $isSerialized = CRM_Core_BAO_CustomField::isSerialized($cFields[$fid]['attributes']); + + if ($htmlType === 'File') { + // Handled in CustomField->move(). Tested in testMergeCustomFields. + unset($submitted["custom_$fid"]); + } + elseif (!$isSerialized && ($htmlType === 'Select Country' || $htmlType === 'Select State/Province')) { + // @todo Test in testMergeCustomFields disabled as this does not work, Handle in CustomField->move(). + $submitted[$key] = CRM_Core_BAO_CustomField::displayValue($value, $fid); + } + elseif ($htmlType === 'Select Date') { + if ($cFields[$fid]['attributes']['is_view']) { + $submitted[$key] = date('YmdHis', strtotime($submitted[$key])); + } + } + elseif ($isSerialized) { + // Merge values from both contacts for multivalue fields, CRM-4385 + // get the existing custom values from db. + $customParams = ['entityID' => $mainId, $key => TRUE]; + $customfieldValues = CRM_Core_BAO_CustomValueTable::getValues($customParams); + if (!empty($customfieldValues[$key])) { + $existingValue = explode(CRM_Core_DAO::VALUE_SEPARATOR, $customfieldValues[$key]); + if (is_array($existingValue) && !empty($existingValue)) { + $mergeValue = $submittedCustomFields = []; + if ($value === 'null') { + // CRM-19074 if someone has deliberately chosen to overwrite with 'null', respect it. + $submitted[$key] = $value; + } + else { + if ($value) { + $submittedCustomFields = explode(CRM_Core_DAO::VALUE_SEPARATOR, $value); } - else { - if ($value) { - $submittedCustomFields = explode(CRM_Core_DAO::VALUE_SEPARATOR, $value); - } - // CRM-19653: overwrite or add the existing custom field value with dupicate contact's - // custom field value stored at $submittedCustomValue. - foreach ($submittedCustomFields as $k => $v) { - if ($v != '' && !in_array($v, $mergeValue)) { - $mergeValue[] = $v; - } + // CRM-19653: overwrite or add the existing custom field value with dupicate contact's + // custom field value stored at $submittedCustomValue. + foreach ($submittedCustomFields as $k => $v) { + if ($v != '' && !in_array($v, $mergeValue)) { + $mergeValue[] = $v; } + } - //keep state and country as array format. - //for checkbox and m-select format w/ VALUE_SEPARATOR - if (in_array($htmlType, ['CheckBox', 'Select'])) { - $submitted[$key] = CRM_Utils_Array::implodePadded($mergeValue); - } - else { - $submitted[$key] = $mergeValue; - } + //keep state and country as array format. + //for checkbox and m-select format w/ VALUE_SEPARATOR + if (in_array($htmlType, ['CheckBox', 'Select'])) { + $submitted[$key] = CRM_Utils_Array::implodePadded($mergeValue); + } + else { + $submitted[$key] = $mergeValue; } } } - elseif (in_array($htmlType, ['Select Country', 'Select State/Province'])) { - //we require submitted values should be in array format - if ($value) { - $mergeValueArray = explode(CRM_Core_DAO::VALUE_SEPARATOR, $value); - //hack to remove null values from array. - $mergeValue = []; - foreach ($mergeValueArray as $k => $v) { - if ($v != '') { - $mergeValue[] = $v; - } + } + elseif (in_array($htmlType, ['Select Country', 'Select State/Province'])) { + //we require submitted values should be in array format + if ($value) { + $mergeValueArray = explode(CRM_Core_DAO::VALUE_SEPARATOR, $value); + //hack to remove null values from array. + $mergeValue = []; + foreach ($mergeValueArray as $k => $v) { + if ($v != '') { + $mergeValue[] = $v; } - $submitted[$key] = $mergeValue; } + $submitted[$key] = $mergeValue; } } } -- 2.25.1