/**
* Retrieve from prev-next cache.
*
+ * This function is used from a variety of merge related functions, although
+ * it would probably be good to converge on calling CRM_Dedupe_Merger::getDuplicatePairs.
+ *
+ * We seem to currently be storing stats in this table too & they might make more sense in
+ * the main cache table.
+ *
* @param string $cacheKey
* @param string $join
- * @param string $where
+ * @param string $whereClause
* @param int $offset
* @param int $rowCount
+ * @param array $select
+ * @param string $orderByClause
+ * @param bool $includeConflicts
+ * Should we return rows that have already been idenfified as having a conflict.
+ * When this is TRUE you should be careful you do not set up a loop.
*
* @param array $select
*
* @return array
*/
- public static function retrieve($cacheKey, $join = NULL, $where = NULL, $offset = 0, $rowCount = 0, $select = array()) {
+ public static function retrieve($cacheKey, $join = NULL, $whereClause = NULL, $offset = 0, $rowCount = 0, $select = array(), $orderByClause = '', $includeConflicts = TRUE) {
$selectString = 'pn.*';
+
if (!empty($select)) {
$aliasArray = array();
foreach ($select as $column => $alias) {
}
$selectString .= " , " . implode(' , ', $aliasArray);
}
- $query = "
-SELECT SQL_CALC_FOUND_ROWS {$selectString}
-FROM civicrm_prevnext_cache pn
- {$join}
-WHERE (pn.cacheKey = %1 OR pn.cacheKey = %2)
-";
+
$params = array(
1 => array($cacheKey, 'String'),
- 2 => array("{$cacheKey}_conflicts", 'String'),
);
- if ($where) {
- $query .= " AND {$where}";
+ if (!empty($whereClause)) {
+ $whereClause = " AND " . $whereClause;
+ }
+ if ($includeConflicts) {
+ $where = ' WHERE (pn.cacheKey = %1 OR pn.cacheKey = %2)' . $whereClause;
+ $params[2] = array("{$cacheKey}_conflicts", 'String');
}
+ else {
+ $where = ' WHERE (pn.cacheKey = %1)' . $whereClause;
+ }
+
+ $query = "
+SELECT SQL_CALC_FOUND_ROWS {$selectString}
+FROM civicrm_prevnext_cache pn
+ {$join}
+ $where
+ $orderByClause
+";
if ($rowCount) {
$offset = CRM_Utils_Type::escape($offset, 'Int');
public static function batchMerge($rgid, $gid = NULL, $mode = 'safe', $autoFlip = TRUE, $batchLimit = 1, $isSelected = 2) {
$redirectForPerformance = ($batchLimit > 1) ? TRUE : FALSE;
$reloadCacheIfEmpty = (!$redirectForPerformance && $isSelected == 2);
- $dupePairs = self::getDuplicatePairs($rgid, $gid, $reloadCacheIfEmpty, $batchLimit, $isSelected);
+ $dupePairs = self::getDuplicatePairs($rgid, $gid, $reloadCacheIfEmpty, $batchLimit, $isSelected, '', FALSE);
$cacheParams = array(
'cache_key_string' => self::getMergeCacheKeyString($rgid, $gid),
// @todo call getDuplicatePairs.
$dupePairs = CRM_Core_BAO_PrevNextCache::retrieve($cacheKeyString,
$cacheParams['join'],
- $cacheParams['where']
+ $cacheParams['where'],
+ 0,
+ 0,
+ array(),
+ '',
+ FALSE
);
}
else {
* @param bool $reloadCacheIfEmpty
* @param int $batchLimit
* @param bool $isSelected
+ * @param array $orderByClause
+ * @param bool $includeConflicts
*
* @return array
* Array of matches meeting the criteria.
*/
- public static function getDuplicatePairs($rule_group_id, $group_id, $reloadCacheIfEmpty, $batchLimit, $isSelected) {
+ public static function getDuplicatePairs($rule_group_id, $group_id, $reloadCacheIfEmpty, $batchLimit, $isSelected, $orderByClause = '', $includeConflicts = TRUE) {
$where = self::getWhereString($batchLimit, $isSelected);
- $cacheKeyString = self::getMergeCacheKeyString($rule_group_id, $group_id);
+ $cacheKeyString = self::getMergeCacheKeyString($rule_group_id, $group_id, $includeConflicts);
$join = self::getJoinOnDedupeTable();
- $dupePairs = CRM_Core_BAO_PrevNextCache::retrieve($cacheKeyString, $join, $where);
+ $dupePairs = CRM_Core_BAO_PrevNextCache::retrieve($cacheKeyString, $join, $where, 0, 0, array(), $orderByClause, $includeConflicts);
if (empty($dupePairs) && $reloadCacheIfEmpty) {
// If we haven't found any dupes, probably cache is empty.
- // Try filling cache and give another try.
+ // Try filling cache and give another try. We don't need to specify include conflicts here are there will not be any
+ // until we have done some processing.
CRM_Core_BAO_PrevNextCache::refillCache($rule_group_id, $group_id, $cacheKeyString);
- $dupePairs = CRM_Core_BAO_PrevNextCache::retrieve($cacheKeyString, $join, $where);
+ $dupePairs = CRM_Core_BAO_PrevNextCache::retrieve($cacheKeyString, $join, $where, 0, 0, array(), $orderByClause, $includeConflicts);
return $dupePairs;
}
return $dupePairs;