Have a question about CiviCRM? Get it answered quickly at the new CiviCRM Stack Exchange Q+A siteThis forum was archived on 25 November 2017. Learn more.How to get involved.What to do if you think you've found a bug.
function mergeContacts($keeper, $duplicate) {// clean input$keeper = (int)$keeper;$duplicate = (int)$duplicate;// check $duplicate to see if complex data attached:(need a list of tables here) ??? basic question is what records are unsafe to automatically merge?if ($UnsafeRecordsFound) { $message = "Sorry, unable to merge $duplicate into $keeper because one or more records exist in the following tables: ( $MatchingTableList ). Please use the tradional <a href='@todo url in her with $duplicate & $keeper>CiviCRM de-duping screen</a> or delete the records and try again."); $success = FALSE;} else { foreach (table in tablist) { run sql: "UPDATE $table SET $idFieldName = $keeper WHERE $idFieldName = $duplicate;" // todo build a report in here to advise what table had affected rows } run sql: "UPDATE civicrm_contact SET deleted = 1 WHERE contact_id = $duplicate;" // todo check this $success = TRUE;}return ( array($success => $success, message => $message)}
SELECT `TABLE_NAME` FROM `COLUMNS` WHERE `COLUMN_NAME` = 'contact_id' AND `TABLE_SCHEMA` = 'au_drupal'SELECT TABLE_NAMEFROM information_schema.COLUMNSWHERE `COLUMN_NAME` = 'entity_id' AND `TABLE_SCHEMA` = 'au_drupal' AND TABLE_NAME NOT IN ( SELECT table_name FROM au_main.civicrm_custom_group WHERE `extends` IN ('Location','Address','Contribution','Activity', 'Relationship','Group','Membership','Participant','Event','Grant','Pledge','Case' /*ie take custom tables for: 'Contact','Individual','Household','Organization' */ ) )
I'm looking to write some code to do this as my next task - probably in the form of a php function in ultimately wrapped in a drupal 6 module...What i need to know is which tables contain records where I can just flick over to a new contact Id, and which tables are unsafe to do this on and should force a manual merge?
/** * Based on the provided two contact_ids and a set of tables, move the * belongings of the other contact to the main one. */ function moveContactBelongings($mainId, $otherId, $tables = false)
/** * Find differences between contacts. */ function findDifferences($mainId, $otherId)
my sense is that 80% of our dupes are email only with very few "belongings"
It would be really handy to have an API for deduping contacts wouldn't it? But we have to have a talk fest (and a warm beer) before we introduce any new API functions!A-Team - contact_merge as an API? with find differences as an option (ie. you can call the API as a dry run or a do it?) leveraging the functions Erik identified?