-
-
Notifications
You must be signed in to change notification settings - Fork 825
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
dev/core#1230 [Ref] Rationalise dedupe code loop. #15184
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -866,6 +866,10 @@ public static function getMergeStatsMsg($stats) { | |
* Respect logged in user permissions. | ||
* | ||
* @return array|bool | ||
* | ||
* @throws \API_Exception | ||
* @throws \CRM_Core_Exception | ||
* @throws \CiviCRM_API3_Exception | ||
*/ | ||
public static function merge($dupePairs = [], $cacheParams = [], $mode = 'safe', | ||
$redirectForPerformance = FALSE, $checkPermissions = TRUE | ||
|
@@ -883,16 +887,17 @@ public static function merge($dupePairs = [], $cacheParams = [], $mode = 'safe', | |
unset($dupePairs[$index]); | ||
continue; | ||
} | ||
CRM_Utils_Hook::merge('flip', $dupes, $dupes['dstID'], $dupes['srcID']); | ||
$mainId = $dupes['dstID']; | ||
$otherId = $dupes['srcID']; | ||
|
||
if (!$mainId || !$otherId) { | ||
// return error | ||
return FALSE; | ||
if (($result = self::dedupePair($dupes, $mode, $checkPermissions, $cacheKeyString)) === FALSE) { | ||
unset($dupePairs[$index]); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These relate to managing the loop - so I moved them OUT of the single pair function |
||
continue; | ||
} | ||
if (!empty($result['merged'])) { | ||
$deletedContacts[] = $result['merged'][0]['other_id']; | ||
$resultStats['merged'][] = ($result['merged'][0]); | ||
} | ||
else { | ||
$resultStats['skipped'][] = ($result['skipped'][0]); | ||
} | ||
|
||
self::dedupePair($resultStats, $deletedContacts, $mode, $checkPermissions, $mainId, $otherId, $cacheKeyString); | ||
} | ||
|
||
if ($cacheKeyString && !$redirectForPerformance) { | ||
|
@@ -2111,20 +2116,26 @@ public static function mergeLocations($mainId, $otherId, $migrationInfo) { | |
/** | ||
* Dedupe a pair of contacts. | ||
* | ||
* @param array $resultStats | ||
* @param array $deletedContacts | ||
* @param array $dupes | ||
* @param string $mode | ||
* @param bool $checkPermissions | ||
* @param int $mainId | ||
* @param int $otherId | ||
* @param string $cacheKeyString | ||
* | ||
* @return bool|array | ||
* @throws \CRM_Core_Exception | ||
* @throws \CiviCRM_API3_Exception | ||
* @throws \API_Exception | ||
*/ | ||
protected static function dedupePair(&$resultStats, &$deletedContacts, $mode, $checkPermissions, $mainId, $otherId, $cacheKeyString) { | ||
|
||
protected static function dedupePair($dupes, $mode = 'safe', $checkPermissions = TRUE, $cacheKeyString = NULL) { | ||
CRM_Utils_Hook::merge('flip', $dupes, $dupes['dstID'], $dupes['srcID']); | ||
$mainId = $dupes['dstID']; | ||
$otherId = $dupes['srcID']; | ||
$resultStats = []; | ||
|
||
if (!$mainId || !$otherId) { | ||
// return error | ||
return FALSE; | ||
} | ||
$migrationInfo = []; | ||
$conflicts = []; | ||
if (!CRM_Dedupe_Merger::skipMerge($mainId, $otherId, $migrationInfo, $mode, $conflicts)) { | ||
|
@@ -2133,7 +2144,6 @@ protected static function dedupePair(&$resultStats, &$deletedContacts, $mode, $c | |
'main_id' => $mainId, | ||
'other_id' => $otherId, | ||
]; | ||
$deletedContacts[] = $otherId; | ||
} | ||
else { | ||
$resultStats['skipped'][] = [ | ||
|
@@ -2149,6 +2159,7 @@ protected static function dedupePair(&$resultStats, &$deletedContacts, $mode, $c | |
else { | ||
CRM_Core_BAO_PrevNextCache::deletePair($mainId, $otherId, $cacheKeyString); | ||
} | ||
return $resultStats; | ||
} | ||
|
||
/** | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These lines relate to a single pair - so I moved them into the single pair function