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, 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
Add custom tables that extend contacts to the list of contact references.
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.
No description
Get the metadata for the merge fields.
Get the details of the contact to be merged.
Merge location.
Dedupe a pair of contacts.
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 169
static array
getActiveRelTables(int $cid)
Returns the related tables groups for which a contact has any info entered.
at line 211
static
cidRefs()
Get array tables and fields that reference civicrm_contact.id.
This includes core tables, custom group tables, tables added by the merge hook and (somewhat randomly) the entity_tag table.
Refer to CRM-17454 for information on the danger of querying the information schema to derive this.
This function calls the merge hook but the entityTypes hook is the recommended way to add tables to this result.
at line 238
static
eidRefs()
Return tables and their fields referencing civicrm_contact.contact_id with entity_id
at line 261
static
locTables()
Return tables using locations.
at line 278
static
getMultiValueCustomSets(string $request)
We treat multi-valued custom sets as "related tables" similar to activities, contributions, etc.
at line 307
static
cpTables()
Tables which require custom processing should declare functions to call here.
Doing so will override normal processing.
at line 324
static
paymentTables()
Return payment related table.
at line 341
static array
paymentSql(string $tableName, int $mainContactId, int $otherContactId)
Return payment update Query.
at line 393
static array
operationSql(int $mainId, int $otherId, string $tableName, array $tableOperations = array(), string $mode = 'add')
at line 441
static
moveContactBelongings(int $mainId, int $otherId, bool $tables = FALSE, array $tableOperations = array())
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 551
static array
retrieveFields(array $main, array $other)
Load all non-empty fields for the contacts
at line 603
static array|bool
batchMerge(int $rgid, int $gid = NULL, string $mode = 'safe', int $batchLimit = 1, int $isSelected = 2, array $criteria = array(), bool $checkPermissions = TRUE)
Batch merge a set of contacts based on rule-group and group.
at line 624
static string
getJoinOnDedupeTable()
Get the string to join the prevnext cache to the dedupe table.
at line 641
static protected string
getWhereString(int $batchLimit, bool $isSelected)
Get where string for dedupe join.
at line 658
static
updateMergeStats(string $cacheKeyString, array $result = array())
Update the statistics for the merge set.
at line 698
static
resetMergeStats($cacheKeyString)
Delete information about merges for the given string.
at line 710
static array
getMergeStats(string $cacheKeyString)
Get merge outcome statistics.
at line 725
static string
getMergeStatsMsg(string $cacheKeyString)
Get merge statistics message.
at line 758
static array|bool
merge(array $dupePairs = array(), array $cacheParams = array(), string $mode = 'safe', bool $redirectForPerformance = FALSE, bool $checkPermissions = TRUE)
Merge given set of contacts. Performs core operation.
at line 837
static bool
skipMerge(int $mainId, int $otherId, array $migrationInfo, string $mode = 'safe', array $conflicts = array())
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 948
static bool
locationIsSame(array $mainAddress, array $comparisonAddress)
Compare 2 addresses to see if they are the same.
at line 967
static array
getLocationBlockInfo()
A function to build an array of information about location blocks that is required when merging location fields
at line 1057
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 1459
static bool
moveAllBelongings(int $mainId, int $otherId, $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 1758
static array
getContactFields()
Get fields in the contact table suitable for merging.
at line 1786
static
addMembershipToRealtedContacts(int $contactID)
Added for CRM-12695 Based on the contactID provided add/update membership(s) to related contacts
at line 1824
static
addCustomTablesExtendingContactsToCidRefs(array $cidRefs)
Add custom tables that extend contacts to the list of contact references.
CRM_Core_BAO_CustomGroup::getAllCustomGroupsByBaseEntity seems like a safe-ish function to be sure all are retrieved & we don't miss subtypes or inactive or multiples - the down side is it is not cached.
Further changes should be include tests in the CRM_Core_MergerTest class to ensure that disabled, subtype, multiple etc groups are still captured.
at line 1840
static
createMergeActivities(int $mainId, int $otherId)
Create activities tracking the merge on affected contacts.
at line 1885
static array
getDuplicatePairs(int $rule_group_id, int $group_id, bool $reloadCacheIfEmpty, int $batchLimit, bool $isSelected, array|string $orderByClause = '', bool $includeConflicts = TRUE, array $criteria = array(), bool $checkPermissions = TRUE)
Get Duplicate Pairs based on a rule for a group.
at line 1915
static string
getMergeCacheKeyString(int $rule_group_id, int $group_id, array $criteria = array(), bool $checkPermissions = TRUE)
Get the cache key string for the merge action.
at line 1940
static array
getSpecialValues(array $contact)
at line 1975
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 2000
static array
getMergeContactDetails(int $contact_id)
Get the details of the contact to be merged.
at line 2044
static
mergeLocations(int $mainId, int $otherId, array $locationMigrationInfo, 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 2179
static protected
dedupePair(array $migrationInfo, array $resultStats, array $deletedContacts, string $mode, bool $checkPermissions, int $mainId, int $otherId, string $cacheKeyString)
Dedupe a pair of contacts.