Skip to content

Commit

Permalink
Extract get cfields function
Browse files Browse the repository at this point in the history
  • Loading branch information
eileenmcnaughton committed Apr 27, 2019
1 parent 1acd98e commit a7369a0
Showing 1 changed file with 37 additions and 26 deletions.
63 changes: 37 additions & 26 deletions CRM/Dedupe/Merger.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [];
Expand Down Expand Up @@ -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;
}

}

0 comments on commit a7369a0

Please sign in to comment.