Skip to content
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

Fix for Merge Duplicates Failing when no Determinations need Downgrading #1484

Merged
19 changes: 10 additions & 9 deletions classes/OccurrenceEditorManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -1589,15 +1589,16 @@ public function mergeRecords($targetOccid,$sourceOccid){
]);

//Downgrade old determinations if new determinations have a current determination
$parameters = str_repeat('?,', count($currentDeterminations) - 1) . '?';
$sql = <<<"SQL"
UPDATE omoccurdeterminations
JOIN (SELECT count(*) as cnt FROM omoccurdeterminations WHERE isCurrent = 1 AND occid = ? AND detid NOT IN ($parameters)) as update_flag on cnt > 0
SET isCurrent = 0
WHERE occid = ? AND isCurrent = 1 AND detid IN ($parameters);
SQL;
$this->conn->execute_query($sql, array_merge([$targetOccid], $currentDeterminations, [$targetOccid], $currentDeterminations));

if(count($currentDeterminations) > 0) {
$parameters = str_repeat('?,', count($currentDeterminations) - 1) . '?';
$sql = <<<"SQL"
UPDATE omoccurdeterminations
JOIN (SELECT count(*) as cnt FROM omoccurdeterminations WHERE isCurrent = 1 AND occid = ? AND detid NOT IN ($parameters)) as update_flag on cnt > 0
SET isCurrent = 0
WHERE occid = ? AND isCurrent = 1 AND detid IN ($parameters);
SQL;
$this->conn->execute_query($sql, array_merge([$targetOccid], $currentDeterminations, [$targetOccid], $currentDeterminations));
}
//Remap images
$sql = <<<'SQL'
UPDATE images SET occid = ? WHERE occid = ?;
Expand Down