From e4f8c98c19a74f5590c954bbd5cfdb0696de9019 Mon Sep 17 00:00:00 2001 From: yashodha Date: Mon, 28 Apr 2014 01:45:59 +0530 Subject: [PATCH] CRM-14500: refer to contact id foreign keys dynamically --- CRM/Dedupe/Merger.php | 51 ++++++++++--------------------------------- 1 file changed, 11 insertions(+), 40 deletions(-) diff --git a/CRM/Dedupe/Merger.php b/CRM/Dedupe/Merger.php index 4958a3a5b1..06d2444746 100644 --- a/CRM/Dedupe/Merger.php +++ b/CRM/Dedupe/Merger.php @@ -186,50 +186,21 @@ class CRM_Dedupe_Merger { } /** - * Return tables and their fields referencing civicrm_contact.contact_id explicitely + * Return tables and their fields referencing civicrm_contact.contact_id explicitly */ static function cidRefs() { static $cidRefs; if (!$cidRefs) { - // FIXME: this should be generated dynamically from the schema's - // foreign keys referencing civicrm_contact(id) - $cidRefs = array( - 'civicrm_acl_cache' => array('contact_id'), - 'civicrm_activity_contact' => array('contact_id'), - 'civicrm_case_contact' => array('contact_id'), - 'civicrm_contact' => array('primary_contact_id'), - 'civicrm_contribution' => array('contact_id'), - 'civicrm_contribution_page' => array('created_id'), - 'civicrm_contribution_recur' => array('contact_id'), - 'civicrm_contribution_soft' => array('contact_id'), - 'civicrm_custom_group' => array('created_id'), - 'civicrm_entity_tag' => array('entity_id'), - 'civicrm_event' => array('created_id'), - 'civicrm_grant' => array('contact_id'), - 'civicrm_group_contact' => array('contact_id'), - 'civicrm_group_organization' => array('organization_id'), - 'civicrm_log' => array('modified_id'), - 'civicrm_mailing' => array('created_id', 'scheduled_id'), - 'civicrm_mailing_event_queue' => array('contact_id'), - 'civicrm_mailing_event_subscribe' => array('contact_id'), - 'civicrm_membership' => array('contact_id'), - 'civicrm_membership_log' => array('modified_id'), - 'civicrm_membership_type' => array('member_of_contact_id'), - 'civicrm_note' => array('contact_id'), - 'civicrm_participant' => array('contact_id'), - 'civicrm_pcp' => array('contact_id'), - 'civicrm_relationship' => array('contact_id_a', 'contact_id_b'), - 'civicrm_uf_match' => array('contact_id'), - 'civicrm_uf_group' => array('created_id'), - 'civicrm_pledge' => array('contact_id'), - ); - - $cidRefs += self::getMultiValueCustomSets('cidRefs'); - - // Add ContactReference custom fields CRM-9561 - $sql = "SELECT cg.table_name, cf.column_name - FROM civicrm_custom_group cg, civicrm_custom_field cf - WHERE cg.id = cf.custom_group_id AND cf.data_type = 'ContactReference'"; + $sql = " +SELECT + table_name, + column_name +FROM information_schema.key_column_usage +WHERE + referenced_table_schema = database() AND + referenced_table_name = 'civicrm_contact' AND + referenced_column_name = 'id'; + "; $dao = CRM_Core_DAO::executeQuery($sql); while ($dao->fetch()) { $cidRefs[$dao->table_name][] = $dao->column_name; -- 2.25.1