From f941d73aadead2798d262728679661e3ce5122f4 Mon Sep 17 00:00:00 2001 From: eileen Date: Sat, 27 Apr 2019 17:48:38 +1200 Subject: [PATCH] Extract get cfields function --- CRM/Dedupe/Merger.php | 63 +++++++++++++++++++++++++------------------ 1 file changed, 37 insertions(+), 26 deletions(-) diff --git a/CRM/Dedupe/Merger.php b/CRM/Dedupe/Merger.php index 798ef782339..5e194068174 100644 --- a/CRM/Dedupe/Merger.php +++ b/CRM/Dedupe/Merger.php @@ -1678,33 +1678,8 @@ public static function moveAllBelongings($mainId, $otherId, $migrationInfo, $che 'groupName' => 'postal_greeting', ]; CRM_Core_OptionGroup::lookupValues($submitted, $names, TRUE); - // fix custom fields so they're edible by createProfileContact() - $treeCache = []; - if (!array_key_exists($contactType, $treeCache)) { - $treeCache[$contactType] = CRM_Core_BAO_CustomGroup::getTree( - $contactType, - NULL, - NULL, - -1, - [], - NULL, - TRUE, - NULL, - FALSE, - FALSE - ); - } - - $cFields = []; - foreach ($treeCache[$contactType] as $key => $group) { - if (!isset($group['fields'])) { - continue; - } - foreach ($group['fields'] as $fid => $field) { - $cFields[$fid]['attributes'] = $field; - } - } + $cFields = self::getCustomFieldMetadata($contactType); if (!isset($submitted)) { $submitted = []; @@ -2423,4 +2398,40 @@ protected static function swapOutFieldsAffectedByQFZeroBug(&$migrationInfo) { } } + /** + * Get metadata for the custom fields for the merge. + * + * @param string $contactType + * + * @return array + */ + protected static function getCustomFieldMetadata($contactType) { + $treeCache = []; + if (!array_key_exists($contactType, $treeCache)) { + $treeCache[$contactType] = CRM_Core_BAO_CustomGroup::getTree( + $contactType, + NULL, + NULL, + -1, + [], + NULL, + TRUE, + NULL, + FALSE, + FALSE + ); + } + + $cFields = []; + foreach ($treeCache[$contactType] as $key => $group) { + if (!isset($group['fields'])) { + continue; + } + foreach ($group['fields'] as $fid => $field) { + $cFields[$fid]['attributes'] = $field; + } + } + return $cFields; + } + }