}
$contactReferences = $coreReferences = CRM_Core_DAO::getReferencesToContactTable();
+ foreach (['civicrm_group_contact_cache', 'civicrm_acl_cache', 'civicrm_acl_contact_cache'] as $tableName) {
+ // Don't merge cache tables. These should be otherwise cleared at some point in the dedupe
+ // but they are prone to locking to let's not touch during the dedupe.
+ unset($contactReferences[$tableName], $coreReferences[$tableName]);
+ }
CRM_Utils_Hook::merge('cidRefs', $contactReferences);
if ($contactReferences !== $coreReferences) {
*/
public function testGetCidRefs() {
$this->entityCustomGroupWithSingleFieldCreate(__FUNCTION__, 'Contacts');
- $this->assertEquals($this->getStaticCIDRefs(), CRM_Dedupe_Merger::cidRefs());
- $this->assertEquals($this->getCalculatedCIDRefs(), CRM_Dedupe_Merger::cidRefs());
+ // These are deliberately unset.
+ $unsetRefs = array_fill_keys(['civicrm_group_contact_cache', 'civicrm_acl_cache', 'civicrm_acl_contact_cache'], 1);
+ $this->assertEquals(array_diff_key($this->getStaticCIDRefs(), $unsetRefs), CRM_Dedupe_Merger::cidRefs());
+ $this->assertEquals(array_diff_key($this->getCalculatedCIDRefs(), $unsetRefs), CRM_Dedupe_Merger::cidRefs());
}
/**
foreach ($groupResult['values'] as $groupValues) {
$this->assertEquals($contactID, $groupValues['contact_id']);
$this->assertEquals('Added', $groupValues['status']);
- $this->assertTrue(in_array($groupValues['group_id'], $expectedGroups));
+ $this->assertContains($groupValues['group_id'], $expectedGroups);
}
}
+ /**
+ * Test that we handle cache entries without clashes.
+ */
+ public function testMergeCaches() {
+ $contactID = $this->individualCreate();
+ $contact2ID = $this->individualCreate();
+ $groupID = $this->groupCreate();
+ $this->callAPISuccess('GroupContact', 'create', ['group_id' => $groupID, 'contact_id' => $contactID]);
+ $this->callAPISuccess('GroupContact', 'create', ['group_id' => $groupID, 'contact_id' => $contact2ID]);
+ CRM_Core_DAO::executeQuery("INSERT INTO civicrm_group_contact_cache(group_id, contact_id) VALUES
+ ($groupID, $contactID),
+ ($groupID, $contact2ID)
+ ");
+ $this->callAPISuccess('Job', 'process_batch_merge', ['mode' => 'safe']);
+ }
+
/**
* Test the decisions made for addresses when merging.
*