CRM_Core_DAO::executeQuery($sql, $params);
}
- /**
- * Delete pair from the previous next cache table to remove it from further merge consideration.
- *
- * The pair may have been flipped, so make sure we delete using both orders
- *
- * @param int $id1
- * @param int $id2
- * @param string $cacheKey
- */
- public static function deletePair($id1, $id2, $cacheKey = NULL) {
- $sql = "DELETE FROM civicrm_prevnext_cache WHERE entity_table = 'civicrm_contact'";
-
- $pair = "(entity_id1 = %2 AND entity_id2 = %3) OR (entity_id1 = %3 AND entity_id2 = %2)";
- $sql .= " AND ( {$pair} )";
- $params[2] = [$id1, 'Integer'];
- $params[3] = [$id2, 'Integer'];
-
- if (isset($cacheKey)) {
- $sql .= " AND cachekey LIKE %4";
- // used % to address any row with conflict-cacheKey e.g "merge Individual_8_0_conflicts"
- $params[4] = ["{$cacheKey}%", 'String'];
- }
-
- CRM_Core_DAO::executeQuery($sql, $params);
- }
-
/**
* Mark contacts as being in conflict.
*
CRM_Core_BAO_PrevNextCache::markConflict($mainId, $otherId, $cacheKeyString, $conflicts, $mode);
}
else {
- CRM_Core_BAO_PrevNextCache::deletePair($mainId, $otherId, $cacheKeyString);
+ self::deletePairFromPrevNextCache((int) $mainId, (int) $otherId);
}
self::releaseLocks($locks);
return $resultStats;
}
+ /**
+ * Delete merged pair from the previous next cache table as the are no longer a merge candidate.
+ *
+ * It's possible there may be more than one set of merge results cached, with different cache keys.
+ * Once we have merged a pair these should all go (even from a different merge search) as they
+ * can only be merged once.
+ *
+ * @param int $contactID1
+ * @param int $contactID2
+ */
+ protected static function deletePairFromPrevNextCache(int $contactID1, int $contactID2) {
+ CRM_Core_DAO::executeQuery("
+ DELETE FROM civicrm_prevnext_cache
+ WHERE entity_table = 'civicrm_contact'
+ AND (entity_id1 = %1 AND entity_id2 = %2) OR (entity_id1 = %2 AND entity_id2 = %1)",
+ [1 => [$contactID1, 'Integer'], 2 => [$contactID2, 'Integer']]
+ );
+ }
+
/**
* Replace the pseudo QFKey with zero if it is present.
*