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.
/** * Automaticlly merge two contacts. * * @see autoMergeSQL() * * @param $param array * - 'id' integer contact_id of record to keep (injection attack safe) * - 'id_duplicate' integer contact_id of record to be assimilated (injection attack safe) * @return array result * - is_error * - sql * - error_message * - report */ static public function merge($param) { $keep = (int)$param['id']; $lose = (int)$param['id_duplicate']; // attempt to generate SQL: $result = AgcAutoMerge::autoMergeSQL($keep, $lose); if (!$result['is_error']) { // perform merge: require_once 'CRM/Core/Transaction.php'; $transaction = new CRM_Core_Transaction( ); foreach ($result['sql'] as $sql) { CRM_Core_DAO::executeQuery( $sql, CRM_Core_DAO::$_nullArray, true, null, true ); } $transaction->commit( ); // add notes to both contacts: //todo fix note created by $note = array( 'entity_table' => 'civicrm_contact', 'entity_id' => $keep, 'note' => "This contact has been merged from the duplicate $lose", 'subject' => 'Target of automerge', 'version' => 3, ); $result['report'] .= "Added note to $keep: ". json_encode(civicrm_api( 'note', 'create', $note)); $note = array( 'entity_table' => 'civicrm_contact', 'entity_id' => $lose, 'note' => "This contact was merged to $keep", 'subject' => 'Duplicate. Deleted during automerge', 'version' => 3, ); $result['report'] .= "Added note to $lose: " . json_encode(civicrm_api( 'note','create', $note)); } return $result; }
/** * Automatically merge two contacts. * * Creates a note in both main and outer contact * * @returns string html */function _agc_dedupe_merge($mainId, $otherId) { require_once 'class.automerge.php'; $params = array( 'id' => $mainId, 'id_duplicate' => $otherId); $result = AgcAutoMerge::merge($params); $html = "<h3>Planned merger of $otherId into $mainId</h3>"; if ($result['is_error']) { $html .= "<h4>Error</h4><p class='error'>$result[error_message]</p><p>$result[report]</p>"; } else { $html .= "<h4>SQL:</h4>" . AgcAutoMergeDevWindow::arrayFormat($result['sql']); } return $html . '<p>Report:' . $result['report'] . '</p>';}
$items['agc/dedupe/merge'] = array( 'title' => 'Perform merge', 'description' => 'Merge a pair of duplicate contacts', 'file' => 'agc.automerge.inc', 'page callback' => '_agc_dedupe_merge', 'page arguments' => array(3,4), // $mainId, $otherId 'access arguments' => $adminRole, 'type' => MENU_CALLBACK);