CRM_Dedupe_Merger
class CRM_Dedupe_Merger
Methods
FIXME: consider creating a common structure with cidRefs() and eidRefs() FIXME: the sub-pages references by the URLs should be loaded dynamically on the merge form instead
Returns the related tables groups for which a contact has any info entered.
Get array tables and fields that reference civicrm_contact.id.
Return tables and their fields referencing civicrm_contact.contact_id with entity_id
Return tables using locations.
We treat multi-valued custom sets as "related tables" similar to activities, contributions, etc.
Tables which require custom processing should declare functions to call here.
Return payment related table.
Return payment update Query.
No description
Based on the provided two contact_ids and a set of tables, remove the belongings of the other contact and of their relations.
Based on the provided two contact_ids and a set of tables, move the belongings of the other contact to the main one.
Load all non-empty fields for the contacts
Batch merge a set of contacts based on rule-group and group.
Get the string to join the prevnext cache to the dedupe table.
Get where string for dedupe join.
Update the statistics for the merge set.
Delete information about merges for the given string.
Get merge outcome statistics.
Get merge statistics message.
Merge given set of contacts. Performs core operation.
A function which uses various rules / algorithms for choosing which contact to bias to when there's a conflict (to handle "gotchas"). Plus the safest route to merge.
Compare 2 addresses to see if they are the same.
A function to build an array of information about location blocks that is required when merging location fields
A function to build an array of information required by merge function and the merge UI.
Based on the provided two contact_ids and a set of tables, move the belongings of the other contact to the main one - be it Location / CustomFields or Contact .
Get fields in the contact table suitable for merging.
Added for CRM-12695 Based on the contactID provided add/update membership(s) to related contacts
Create activities tracking the merge on affected contacts.
Get Duplicate Pairs based on a rule for a group.
Get the cache key string for the merge action.
Get the metadata for the merge fields.
Get the details of the contact to be merged.
Merge location.
Dedupe a pair of contacts.
Replace the pseudo QFKey with zero if it is present.
Honestly - what DOES this do - hopefully some refactoring will reveal it's purpose.
Get metadata for the custom fields for the merge.
Get conflicts for proposed merge pair.
No description
Get any duplicate merge pairs that have been previously cached.
No description
Details
at line 41
static array
relTables()
FIXME: consider creating a common structure with cidRefs() and eidRefs() FIXME: the sub-pages references by the URLs should be loaded dynamically on the merge form instead
at line 193
static array
getActiveRelTables(int $cid)
Returns the related tables groups for which a contact has any info entered.
at line 232
static
cidRefs()
Get array tables and fields that reference civicrm_contact.id.
This function calls the merge hook and only exists to wrap the DAO function to support that deprecated call. The entityTypes hook is the recommended way to add tables to this result.
I thought about adding another hook to alter tableReferences but decided it was unclear if there are use cases not covered by entityTables and instead we should wait & see.
at line 251
static
eidRefs()
Return tables and their fields referencing civicrm_contact.contact_id with entity_id
at line 274
static
locTables()
Return tables using locations.
at line 292
static array
getMultiValueCustomSets(string $request)
We treat multi-valued custom sets as "related tables" similar to activities, contributions, etc.
at line 332
static
cpTables()
Tables which require custom processing should declare functions to call here.
Doing so will override normal processing.
at line 350
static
paymentTables()
Return payment related table.
at line 367
static array
paymentSql(string $tableName, int $mainContactId, int $otherContactId)
Return payment update Query.
at line 419
static array
operationSql(int $mainId, int $otherId, string $tableName, array $tableOperations = [], string $mode = 'add')
at line 465
static
removeContactBelongings(int $otherID, bool $tables)
Based on the provided two contact_ids and a set of tables, remove the belongings of the other contact and of their relations.
at line 496
static
moveContactBelongings(int $mainId, int $otherId, bool $tables = FALSE, array $tableOperations = [], array $customTableToCopyFrom = NULL)
Based on the provided two contact_ids and a set of tables, move the belongings of the other contact to the main one.
at line 635
static array
retrieveFields(array $main, array $other)
Load all non-empty fields for the contacts
at line 704
static array|bool
batchMerge(int $rgid, int $gid = NULL, string $mode = 'safe', int $batchLimit = 1, int $isSelected = 2, array $criteria = [], bool $checkPermissions = TRUE, bool|NULL $reloadCacheIfEmpty = NULL, int $searchLimit = 0)
Batch merge a set of contacts based on rule-group and group.
at line 735
static string
getJoinOnDedupeTable()
Get the string to join the prevnext cache to the dedupe table.
at line 751
static protected string
getWhereString(bool $isSelected)
Get where string for dedupe join.
at line 765
static
updateMergeStats(string $cacheKeyString, array $result = [])
Update the statistics for the merge set.
at line 803
static
resetMergeStats($cacheKeyString)
Delete information about merges for the given string.
at line 817
static array
getMergeStats(string $cacheKeyString)
Get merge outcome statistics.
at line 832
static string
getMergeStatsMsg(array $stats)
Get merge statistics message.
at line 874
static array|bool
merge(array $dupePairs = [], array $cacheParams = [], string $mode = 'safe', bool $redirectForPerformance = FALSE, bool $checkPermissions = TRUE)
Merge given set of contacts. Performs core operation.
at line 950
static bool
skipMerge(int $mainId, int $otherId, array $migrationInfo, string $mode = 'safe', array $conflicts = [])
A function which uses various rules / algorithms for choosing which contact to bias to when there's a conflict (to handle "gotchas"). Plus the safest route to merge.
at line 969
static bool
locationIsSame(array $mainAddress, array $comparisonAddress)
Compare 2 addresses to see if they are the same.
at line 988
static array
getLocationBlockInfo()
A function to build an array of information about location blocks that is required when merging location fields
at line 1078
static array|bool|int
getRowsElementsAndInfo(int $mainId, int $otherId, bool $checkPermissions = TRUE)
A function to build an array of information required by merge function and the merge UI.
at line 1455
static bool
moveAllBelongings(int $mainId, int $otherId, array $migrationInfo, bool $checkPermissions = TRUE)
Based on the provided two contact_ids and a set of tables, move the belongings of the other contact to the main one - be it Location / CustomFields or Contact .
. related info. A superset of moveContactBelongings() function.
at line 1668
static array
getContactFields()
Get fields in the contact table suitable for merging.
at line 1696
static
addMembershipToRealtedContacts(int $contactID)
Added for CRM-12695 Based on the contactID provided add/update membership(s) to related contacts
at line 1730
static
createMergeActivities(int $mainId, int $otherId)
Create activities tracking the merge on affected contacts.
at line 1788
static array
getDuplicatePairs(int $rule_group_id, int $group_id, bool $reloadCacheIfEmpty, int $batchLimit, bool $isSelected, bool $includeConflicts = TRUE, array $criteria = [], bool $checkPermissions = TRUE, int $searchLimit = 0, int $isForceNewSearch = 0)
Get Duplicate Pairs based on a rule for a group.
at line 1817
static string
getMergeCacheKeyString(int $rule_group_id, int $group_id, array $criteria, bool $checkPermissions, int $searchLimit)
Get the cache key string for the merge action.
at line 1846
static array
getMergeFieldsMetadata()
Get the metadata for the merge fields.
This is basically the contact metadata, augmented with fields to represent email greeting, postal greeting & addressee.
at line 1871
static array
getMergeContactDetails(int $contact_id)
Get the details of the contact to be merged.
at line 1913
static
mergeLocations(int $mainId, int $otherId, array $migrationInfo)
Merge location.
Based on the data in the $locationMigrationInfo merge the locations for 2 contacts.
The data is in the format received from the merge form (which is a fairly confusing format).
It is converted into an array of DAOs which is passed to the alterLocationMergeData hook before saving or deleting the DAOs. A new hook is added to allow these to be altered after they have been calculated and before saving because - the existing format & hook combo is so confusing it is hard for developers to change & inherently fragile - passing to a hook right before save means calculations only have to be done once - the existing pattern of passing dissimilar data to the same (merge) hook with a different 'type' is just ugly.
The use of the new hook is tested, including the fact it is called before contributions are merged, as this is likely to be significant data in merge hooks.
at line 2053
static protected bool|array
dedupePair(array $dupes, string $mode = 'safe', bool $checkPermissions = TRUE, string $cacheKeyString = NULL)
Dedupe a pair of contacts.
at line 2099
static protected
swapOutFieldsAffectedByQFZeroBug(array $migrationInfo)
Replace the pseudo QFKey with zero if it is present.
at line 2127
static protected array
processCustomFields($mainId, $key, $cFields, $submitted, $value)
Honestly - what DOES this do - hopefully some refactoring will reveal it's purpose.
Update this function formats fields in preparation for them to be submitted to the 'ProfileContactCreate action. This is a lot of code to do this & for - for some fields it fails - e.g Country - per testMergeCustomFields.
Goal is to move all custom field handling into 'move' functions on the various BAO with an underlying DAO function. For custom fields it has been started on the BAO.
at line 2230
static protected array
getCustomFieldMetadata(string $contactType)
Get metadata for the custom fields for the merge.
at line 2279
static array
getConflicts(array $migrationInfo, int $mainId, int $otherId, string $mode)
Get conflicts for proposed merge pair.
at line 2393
static protected mixed
formatConflictArray(array $conflicts, array $migrationInfo, $toKeepContactLocationBlocks, $toRemoveContactLocationBlocks, $toKeepID, $toRemoveID)
at line 2450
static protected array
getCachedDuplicateMatches(int $rule_group_id, int $group_id, int $batchLimit, bool $isSelected, bool $includeConflicts, array $criteria, int $checkPermissions, int $searchLimit = 0)
Get any duplicate merge pairs that have been previously cached.