From ecdae719de57c1b225af5985033f7d67c9700630 Mon Sep 17 00:00:00 2001 From: "deb.monish" Date: Sat, 4 Feb 2017 11:41:24 +0530 Subject: [PATCH] CRM-19702: Fatal error when merging contact records with custom file fields --- CRM/Core/BAO/File.php | 2 +- CRM/Dedupe/Merger.php | 8 +++----- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/CRM/Core/BAO/File.php b/CRM/Core/BAO/File.php index ed6ce21e80..c5df5ec846 100644 --- a/CRM/Core/BAO/File.php +++ b/CRM/Core/BAO/File.php @@ -203,7 +203,7 @@ class CRM_Core_BAO_File extends CRM_Core_DAO_File { $entityFileDAO->entity_table = $tableName; if (!$entityFileDAO->find(TRUE)) { - CRM_Core_Error::fatal(); + CRM_Core_Error::fatal(sprintf('No record found for given file ID - %d and entity ID - %d', $fileID, $entityID)); } $entityFileDAO->delete(); diff --git a/CRM/Dedupe/Merger.php b/CRM/Dedupe/Merger.php index bf95d2e977..400d3364c6 100644 --- a/CRM/Dedupe/Merger.php +++ b/CRM/Dedupe/Merger.php @@ -1644,14 +1644,12 @@ INNER JOIN civicrm_membership membership2 ON membership1.membership_type_id = m $dao = CRM_Core_DAO::executeQuery($sql); while ($dao->fetch()) { $fileIds[$dao->entity_id] = $dao->file_id; + if ($dao->entity_id == $mainId) { + CRM_Core_BAO_File::deleteFileReferences($fileIds[$mainId], $mainId, $customId); + } } $dao->free(); - // delete the main contact's file - if (!empty($fileIds[$mainId])) { - CRM_Core_BAO_File::deleteFileReferences($fileIds[$mainId], $mainId, $customId); - } - // move the other contact's file to main contact //NYSS need to INSERT or UPDATE depending on whether main contact has an existing record if (CRM_Core_DAO::singleValueQuery("SELECT id FROM {$tableName} WHERE entity_id = {$mainId}")) { -- 2.25.1